diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f2365c6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,31 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Flutter", + "type": "dart", + "request": "launch", + "program": "lib/main.dart" + }, + { + "name": "budget_app", + "request": "launch", + "type": "dart" + }, + { + "name": "budget_app (profile mode)", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "budget_app (release mode)", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} \ No newline at end of file diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 29e7d5c..3a64977 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -36,6 +36,8 @@ class _HomePageState extends State { final authState = context.read().state; if (authState is AuthAuthenticated) { _currentUserId = authState.user.id; + // Загружаем транзакции через глобальный TransactionBloc + context.read().add(LoadTransactions(userId: _currentUserId)); } else { // Если пользователь не аутентифицирован, можно перенаправить на страницу входа // или использовать ID по умолчанию, если это применимо. @@ -56,49 +58,43 @@ class _HomePageState extends State { context, )!; // Получаем экземпляр локализации - return BlocProvider( - create: (context) { - return GetIt.instance() - ..add(LoadTransactions(userId: _currentUserId)); - }, - child: Scaffold( - appBar: AppBar( - title: Text(localizations.appTitle), // Локализованный заголовок - // Кнопки действий в AppBar теперь не нужны, так как настройки перенесены в BottomNavigationBar - ), - body: Center( - child: _widgetOptions[_selectedIndex], // Отображаем выбранный виджет - ), - floatingActionButton: FloatingActionButton( - onPressed: () { - showDialog( - context: context, - builder: (BuildContext context) { - return const AddTransactionDialog(); - }, - ); - }, - child: const Icon(Icons.add), - ), - bottomNavigationBar: BottomNavigationBar( - items: [ - BottomNavigationBarItem( - icon: const Icon(Icons.home), - label: localizations.homePageTitle, // Локализованный текст - ), - BottomNavigationBarItem( - icon: const Icon(Icons.bar_chart), - label: localizations.reportsPageTitle, // Локализованный текст - ), - BottomNavigationBarItem( - icon: const Icon(Icons.settings), - label: localizations.settingsPageTitle, // Локализованный текст - ), - ], - currentIndex: _selectedIndex, - selectedItemColor: Theme.of(context).colorScheme.primary, - onTap: _onItemTapped, - ), + return Scaffold( + appBar: AppBar( + title: Text(localizations.appTitle), // Локализованный заголовок + // Кнопки действий в AppBar теперь не нужны, так как настройки перенесены в BottomNavigationBar + ), + body: Center( + child: _widgetOptions[_selectedIndex], // Отображаем выбранный виджет + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context) { + return const AddTransactionDialog(); + }, + ); + }, + child: const Icon(Icons.add), + ), + bottomNavigationBar: BottomNavigationBar( + items: [ + BottomNavigationBarItem( + icon: const Icon(Icons.home), + label: localizations.homePageTitle, // Локализованный текст + ), + BottomNavigationBarItem( + icon: const Icon(Icons.bar_chart), + label: localizations.reportsPageTitle, // Локализованный текст + ), + BottomNavigationBarItem( + icon: const Icon(Icons.settings), + label: localizations.settingsPageTitle, // Локализованный текст + ), + ], + currentIndex: _selectedIndex, + selectedItemColor: Theme.of(context).colorScheme.primary, + onTap: _onItemTapped, ), ); } @@ -203,85 +199,3 @@ class TransactionsPage extends StatelessWidget { ); } } - -class HomeView extends StatelessWidget { - const HomeView({super.key}); - - // // - // Основной метод построения интерфейса виджета. - // - // Возвращает Scaffold - базовую структуру страницы Material Design, - // которая включает: - // 1. AppBar (верхнюю панель) - // 2. Body (основное содержимое) - // // - @override - Widget build(BuildContext context) { - final localizations = AppLocalizations.of( - context, - )!; // Получаем экземпляр локализации - - return Scaffold( - // Верхняя панель приложения - appBar: AppBar( - // Заголовок приложения - title: const Text('Budget App'), - - // Кнопки в правой части AppBar - actions: [ - // Кнопка настроек - IconButton( - icon: const Icon(Icons.settings), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) => const SettingsPage()), - ); - }, - tooltip: 'Настройки', - ), - ], - ), - - body: BlocBuilder( - builder: (context, state) { - if (state is TransactionLoading) { - return const Center(child: CircularProgressIndicator()); - } else if (state is TransactionLoaded) { - if (state.transactions.isEmpty) { - return const Center(child: Text('Нет транзакций')); - } - return ListView.builder( - itemCount: state.transactions.length, - itemBuilder: (context, index) { - final transaction = state.transactions[index]; - return ListTile( - leading: Icon( - transaction.category.icon, - color: transaction.category.color, - ), - title: Text(transaction.vendor), - subtitle: Text(transaction.category.name), - trailing: Text( - '${transaction.amount.toStringAsFixed(2)} ${transaction.currency}', - style: TextStyle( - color: transaction.isIncome ? Colors.green : Colors.red, - ), - ), - ); - }, - ); - } else if (state is TransactionError) { - return Center( - child: Text(localizations.transactionErrorText(state.message)), - ); // Локализованный текст - } else { - return Center( - child: Text(localizations.loadingTransactionsText), - ); // Локализованный текст - } - }, - ), - ); - } -}