import re with open('kifi-app/lib/features/dashboard/presentation/dashboard_screen.dart', 'r') as f: content = f.read() # Add imports imports_added = False if "import '../../auth/providers/auth_provider.dart';" not in content: content = content.replace( "import '../../business/providers/indian_states_provider.dart';", "import '../../business/providers/indian_states_provider.dart';\nimport '../../auth/providers/auth_provider.dart';\nimport '../../projects/presentation/projects_screen.dart';" ) imports_added = True # Add isProjectMode if "final isProjectMode = ref.watch(projectModeProvider);" not in content: content = content.replace( "final isBusinessMode = ref.watch(businessModeProvider);", "final isProjectMode = ref.watch(projectModeProvider);\n final isBusinessMode = ref.watch(businessModeProvider);" ) # Fix Title logic old_title_logic = """ String title; if (_currentIndex == 0) { title = 'Dashboard'; } else if (isBusinessMode) { if (_currentIndex == 1) title = 'Business Hub'; else if (_currentIndex == 2) title = 'Statistics'; else if (_currentIndex == 3) title = 'My Accounts'; else title = 'Budgets'; } else { if (_currentIndex == 1) title = 'Statistics'; else if (_currentIndex == 2) title = 'My Accounts'; else title = 'Budgets'; }""" new_title_logic = """ String title = 'Dashboard'; int logicalIndex = _currentIndex; if (logicalIndex == 0) title = 'Dashboard'; else { if (isProjectMode) { if (logicalIndex == 1) title = 'Projects'; logicalIndex--; } if (isBusinessMode) { if (logicalIndex == 1) title = 'Business Hub'; logicalIndex--; } if (logicalIndex == 1) title = 'Statistics'; else if (logicalIndex == 2) title = 'My Accounts'; else if (logicalIndex == 3) title = 'Budgets'; }""" content = content.replace(old_title_logic, new_title_logic) home_start_idx = content.find("RefreshIndicator(\n onRefresh: _onRefresh,") home_end_idx = content.find("// ---------------- BUSINESS TAB ----------------") home_widget = content[home_start_idx:home_end_idx].strip() if home_widget.endswith(","): home_widget = home_widget[:-1] stats_start_idx = content.find("StatisticsTab(") stats_end_idx = content.find("// ---------------- WALLETS TAB ----------------") stats_widget = content[stats_start_idx:stats_end_idx].strip() if stats_widget.endswith(","): stats_widget = stats_widget[:-1] old_stack_start_idx = content.find("return IndexedStack(") old_bottom_end_idx = content.find(" );\n }\n\n Widget _buildSummaryCard") new_body_and_bottom = """ final List screens = []; screens.add(""" + home_widget + """); if (isProjectMode) { screens.add(const ProjectsScreen()); } if (isBusinessMode) { screens.add(const BusinessHubScreen()); } screens.add(""" + stats_widget + """); screens.add(const AccountsScreen()); screens.add(const BudgetScreen()); int safeIndex = _currentIndex; if (safeIndex >= screens.length) safeIndex = screens.length - 1; return IndexedStack( index: safeIndex, children: screens, ); }, ), bottomNavigationBar: Builder( builder: (context) { final isProjectMode = ref.watch(projectModeProvider); final isBusinessMode = ref.watch(businessModeProvider); final List navItems = []; navItems.add(const BottomNavigationBarItem(icon: Icon(LucideIcons.home), label: 'Home')); if (isProjectMode) navItems.add(const BottomNavigationBarItem(icon: Icon(LucideIcons.trello), label: 'Projects')); if (isBusinessMode) navItems.add(const BottomNavigationBarItem(icon: Icon(LucideIcons.briefcase), label: 'Business')); navItems.add(const BottomNavigationBarItem(icon: Icon(LucideIcons.pieChart), label: 'Stats')); navItems.add(const BottomNavigationBarItem(icon: Icon(LucideIcons.plusCircle), label: 'Add')); navItems.add(const BottomNavigationBarItem(icon: Icon(LucideIcons.wallet), label: 'Wallets')); navItems.add(const BottomNavigationBarItem(icon: Icon(LucideIcons.target), label: 'Budgets')); int safeIndex = _currentIndex; // Adjust _currentIndex for the display of bottom nav bar because of 'Add' button int addIdx = 1; if (isProjectMode) addIdx++; if (isBusinessMode) addIdx++; addIdx++; // For Stats int displayIndex = _currentIndex; if (_currentIndex >= addIdx) displayIndex++; if (displayIndex >= navItems.length) displayIndex = navItems.length - 1; return BottomNavigationBar( currentIndex: displayIndex, type: BottomNavigationBarType.fixed, onTap: (index) { if (index == addIdx) { Navigator.push(context, MaterialPageRoute(builder: (_) => const AddTransactionScreen())); } else { setState(() { _currentIndex = index > addIdx ? index - 1 : index; }); } }, selectedItemColor: Theme.of(context).colorScheme.primary, unselectedItemColor: Colors.grey, showSelectedLabels: true, showUnselectedLabels: true, items: navItems, ); } ),""" content = content[:old_stack_start_idx] + new_body_and_bottom + content[old_bottom_end_idx:] with open('kifi-app/lib/features/dashboard/presentation/dashboard_screen.dart', 'w') as f: f.write(content) print("Dashboard screen patched fully")