PMU/lib/main.dart
2024-10-16 10:48:22 +04:00

149 lines
4.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
// Класс приложения
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
// Настраиваем цветовую схему приложения
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigoAccent),
useMaterial3: true,
),
home: const MyHomePage(title: 'Валова Анна Дмитриевна'),
);
}
}
// Класс домашней страницы
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// Список слов и их переводов
final List<Word> words = [
Word(word: 'Hello', translation: 'Привет', image: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS69a8OWnRueQNykBpuyfbGxl3gt5ct46NOHg&s'),
Word(word: 'Book', translation: 'Книга', image: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSfbH7Ckkbzrr3KZlb144GTaAmJnz87U9opGw&s'),
Word(word: 'Cat', translation: 'Кот', image: 'https://upload.wikimedia.org/wikipedia/commons/0/0e/Felis_silvestris_silvestris.jpg'),
];
int currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (var word in words)
_Card(
word: word.word,
translation: word.translation,
image: word.image,
),
// Кнопки "Знаю" и "Не знаю"
/* Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Кнопка "Знаю"
ElevatedButton(
onPressed: () {
setState(() {
currentIndex++;
if (currentIndex >= words.length) {
currentIndex = 0;
}
});
},
child: const Text('Знаю'),
),
const SizedBox(width: 20),
// Кнопка "Не знаю"
ElevatedButton(
onPressed: () {
// Переходим к предыдущей карточке
setState(() {
currentIndex--;
if (currentIndex < 0) {
currentIndex = words.length - 1;
}
});
},
child: const Text('Не знаю'),
),
],
),*/
],
),
),
),
);
}
}
// Класс карточки
class _Card extends StatelessWidget {
final String word;
final String translation;
final String image;
const _Card({
required this.word,
required this.translation,
required this.image,
});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(20),
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: word == "Cat" ? Colors.greenAccent : Colors.indigoAccent ,
borderRadius: BorderRadius.circular(10),
),
child: Column(
children: [
Image.network(image, width: 300),
Text(
word,
style: Theme.of(context).textTheme.headlineLarge,
),
// Перевод слова
Text(
translation,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
);
}
}
// Класс для слов
class Word {
final String word;
final String translation;
final String image;
Word({required this.word, required this.translation, required this.image});
}