diff --git a/lib/main.dart b/lib/main.dart index 10eb0ef..71def3f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; +// Класс приложения void main() { runApp(const MyApp()); } @@ -10,8 +11,10 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( + debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( + // Настраиваем цветовую схему приложения colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigoAccent), useMaterial3: true, ), @@ -20,9 +23,9 @@ class MyApp extends StatelessWidget { } } +// Класс домашней страницы class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); - final String title; @override @@ -30,6 +33,15 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { + // Список слов и их переводов + final List 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( @@ -37,68 +49,101 @@ class _MyHomePageState extends State { backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), - body: const MyWidget(), - ); - } -} - -class MyWidget extends StatelessWidget { - const MyWidget({super.key}); - - @override - Widget build(BuildContext context) { - return const Center( - child: SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _Card("Hello1", translation: "desc"), - _Card("Hello1", translation: "desc"), - _Card("Hello", translation: "desc"), - ], + 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 IconData icon; + final String image; - const _Card( - this.word, { + const _Card({ + required this.word, required this.translation, - this.icon = Icons.abc, + required this.image, }); - @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.all(20), margin: const EdgeInsets.all(10), decoration: BoxDecoration( - color: Colors.amberAccent, + 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.bodySmall, + style: Theme.of(context).textTheme.bodyMedium, ), - Icon( - icon, - size: 50, - ) ], ), ); } } + +// Класс для слов +class Word { + final String word; + final String translation; + final String image; + + Word({required this.word, required this.translation, required this.image}); +} \ No newline at end of file diff --git a/test/widget_test.dart b/test/widget_test.dart index 596662e..e0f8c14 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:card_app/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget(MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget);