From 4dbdafe048cbd209ebfdf2e880751c12be93440c Mon Sep 17 00:00:00 2001 From: "Sanders (aider)" Date: Mon, 9 Jun 2025 14:38:23 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=87=D0=B5=D1=80=D0=BD=D0=BE-=D0=B1=D0=B5?= =?UTF-8?q?=D0=BB=D1=8B=D0=B5=20=D1=82=D0=B5=D0=BC=D1=8B=20=D0=B8=20=D1=83?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=B8=D1=82=D1=8C=20main.dart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 86 ++++++---------------------------------- lib/theme/app_theme.dart | 80 +++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 73 deletions(-) create mode 100644 lib/theme/app_theme.dart diff --git a/lib/main.dart b/lib/main.dart index 916624b..a0c9352 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,81 +1,43 @@ import 'package:flutter/material.dart'; +import 'theme/app_theme.dart'; -// Главная функция - точка входа в приложение -// runApp() запускает Flutter приложение и принимает корневой виджет void main() { - // Создаем экземпляр MyApp и передаем null как database (заглушка) - runApp(MyApp(database: null)); + runApp(const MyApp()); } -// MyApp - корневой виджет приложения -// StatefulWidget означает, что виджет может изменять свое состояние class MyApp extends StatefulWidget { - // Конструктор принимает database как параметр - // final означает, что значение нельзя изменить после создания - final dynamic database; - - const MyApp({super.key, required this.database}); + const MyApp({super.key}); @override State createState() => _MyAppState(); } -// Состояние для MyApp виджета -// Здесь хранятся изменяемые данные и логика class _MyAppState extends State { - // Переменная для отслеживания текущей темы - // _ в начале означает, что переменная приватная (доступна только в этом классе) bool _isDarkMode = false; - // Метод для переключения темы void toggleTheme() { - // setState() сообщает Flutter, что состояние изменилось - // и нужно перерисовать виджет setState(() { - _isDarkMode = !_isDarkMode; // Инвертируем значение + _isDarkMode = !_isDarkMode; }); } @override Widget build(BuildContext context) { return MaterialApp( - title: 'Budget App', // Название приложения - - // Светлая тема - используется когда _isDarkMode = false - theme: ThemeData( - colorScheme: ColorScheme.fromSeed( - seedColor: Colors.blue, - brightness: Brightness.light, // Явно указываем светлую тему - ), - useMaterial3: true, // Используем Material Design 3 - ), - - // Темная тема - используется когда _isDarkMode = true - darkTheme: ThemeData( - colorScheme: ColorScheme.fromSeed( - seedColor: Colors.blue, - brightness: Brightness.dark, // Явно указываем темную тему - ), - useMaterial3: true, - ), - - // Определяем какую тему использовать на основе _isDarkMode + title: 'Budget App', + theme: AppTheme.lightTheme(), + darkTheme: AppTheme.darkTheme(), themeMode: _isDarkMode ? ThemeMode.dark : ThemeMode.light, - - // Главная страница приложения home: HomePage( - onThemeToggle: toggleTheme, // Передаем функцию переключения темы - isDarkMode: _isDarkMode, // Передаем текущее состояние темы + onThemeToggle: toggleTheme, + isDarkMode: _isDarkMode, ), ); } } -// Главная страница приложения class HomePage extends StatelessWidget { - // Функция обратного вызова для переключения темы final VoidCallback onThemeToggle; - // Текущее состояние темы final bool isDarkMode; const HomePage({ @@ -86,48 +48,26 @@ class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { - // Scaffold - это базовая структура страницы в Material Design - // Он предоставляет готовый каркас с местами для основных элементов: - // - appBar (верхняя панель) - // - body (основное содержимое) - // - bottomNavigationBar (нижняя навигация) - // - floatingActionButton (плавающая кнопка действия) - // - drawer (боковое меню) и другие return Scaffold( - // AppBar - верхняя панель приложения appBar: AppBar( title: const Text('Budget App'), - // Кнопка для переключения темы в AppBar actions: [ IconButton( - // Меняем иконку в зависимости от текущей темы icon: Icon(isDarkMode ? Icons.light_mode : Icons.dark_mode), - onPressed: onThemeToggle, // Вызываем функцию переключения темы - tooltip: 'Переключить тему', // Подсказка при долгом нажатии + onPressed: onThemeToggle, + tooltip: 'Переключить тему', ), ], ), - - // Основное содержимое страницы body: const Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Icon( - Icons.account_balance_wallet, - size: 64, - ), - SizedBox(height: 16), // Отступ между элементами + Icon(Icons.account_balance_wallet, size: 64), + SizedBox(height: 16), Text( 'Добро пожаловать в Budget App!', style: TextStyle(fontSize: 24), - textAlign: TextAlign.center, - ), - SizedBox(height: 8), - Text( - 'Здесь будет основной контент приложения', - style: TextStyle(fontSize: 16), - textAlign: TextAlign.center, ), ], ), diff --git a/lib/theme/app_theme.dart b/lib/theme/app_theme.dart new file mode 100644 index 0000000..ceb2afc --- /dev/null +++ b/lib/theme/app_theme.dart @@ -0,0 +1,80 @@ +import 'package:flutter/material.dart'; + +class AppTheme { + // Светлая тема в черно-белой гамме + static ThemeData lightTheme() { + return ThemeData( + useMaterial3: true, + colorScheme: ColorScheme.fromSeed( + seedColor: Colors.grey, // Серый как базовый цвет + brightness: Brightness.light, + primary: Colors.black, // Основной цвет - черный + secondary: Colors.grey[800]!, // Вторичный цвет - темно-серый + surface: Colors.white, // Фон поверхностей + background: Colors.grey[50]!, // Общий фон - очень светлый серый + ), + appBarTheme: const AppBarTheme( + backgroundColor: Colors.white, // Белый фон AppBar + foregroundColor: Colors.black, // Черный цвет иконок и текста + elevation: 0, // Убираем тень + centerTitle: true, // Центрируем заголовок + ), + cardTheme: CardTheme( + elevation: 1, // Легкая тень + margin: const EdgeInsets.all(8), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + elevatedButtonTheme: ElevatedButtonThemeData( + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, + backgroundColor: Colors.black, // Черные кнопки + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + ), + ); + } + + // Темная тема в черно-белой гамме + static ThemeData darkTheme() { + return ThemeData( + useMaterial3: true, + colorScheme: ColorScheme.fromSeed( + seedColor: Colors.grey, + brightness: Brightness.dark, + primary: Colors.white, // Основной цвет - белый + secondary: Colors.grey[300]!, // Вторичный цвет - светлый серый + surface: Colors.grey[900]!, // Фон поверхностей + background: Colors.black, // Общий фон - черный + ), + appBarTheme: AppBarTheme( + backgroundColor: Colors.grey[900]!, // Темно-серый фон AppBar + foregroundColor: Colors.white, // Белый цвет иконок и текста + elevation: 0, + centerTitle: true, + ), + cardTheme: CardTheme( + elevation: 1, + margin: const EdgeInsets.all(8), + color: Colors.grey[800], // Темные карточки + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + elevatedButtonTheme: ElevatedButtonThemeData( + style: ElevatedButton.styleFrom( + foregroundColor: Colors.black, + backgroundColor: Colors.white, // Белые кнопки + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + ), + ); + } +}