104 lines
4.0 KiB
Python
104 lines
4.0 KiB
Python
import re
|
|
|
|
with open('kifi-app/lib/features/dashboard/presentation/dashboard_screen.dart', 'r') as f:
|
|
content = f.read()
|
|
|
|
home_start_idx = content.find("RefreshIndicator(\n onRefresh: _onRefresh,")
|
|
home_end_idx = content.find("// ---------------- PROJECTS 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]
|
|
|
|
# We need to replace everything from `return IndexedStack(` to the end of bottom navbar
|
|
old_start_idx = content.find("return IndexedStack(")
|
|
old_end_idx = content.find(" );\n }\n\n Widget _buildSummaryCard")
|
|
|
|
if old_start_idx == -1 or old_end_idx == -1:
|
|
print("Could not find bounds")
|
|
exit(1)
|
|
|
|
new_code = """final List<Widget> screens = [];
|
|
|
|
screens.add(""" + home_widget + """);
|
|
|
|
if (isProjectMode) {
|
|
screens.add(const ProjectsScreen());
|
|
}
|
|
|
|
if (isBusinessMode) {
|
|
screens.add(const BusinessHubScreen());
|
|
}
|
|
|
|
screens.add(""" + stats_widget + """);
|
|
|
|
final addIndex = screens.length;
|
|
screens.add(const SizedBox.shrink()); // Placeholder for Add
|
|
|
|
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<BottomNavigationBarItem> 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;
|
|
if (safeIndex >= navItems.length) safeIndex = navItems.length - 1;
|
|
|
|
return BottomNavigationBar(
|
|
currentIndex: safeIndex,
|
|
type: BottomNavigationBarType.fixed,
|
|
onTap: (index) {
|
|
int addIdx = 1;
|
|
if (isProjectMode) addIdx++;
|
|
if (isBusinessMode) addIdx++;
|
|
addIdx++; // For Stats
|
|
|
|
if (index == addIdx) {
|
|
Navigator.push(context, MaterialPageRoute(builder: (_) => const AddTransactionScreen()));
|
|
} else {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
}
|
|
},
|
|
selectedItemColor: Theme.of(context).colorScheme.primary,
|
|
unselectedItemColor: Colors.grey,
|
|
showSelectedLabels: true,
|
|
showUnselectedLabels: true,
|
|
items: navItems,
|
|
);
|
|
}
|
|
),
|
|
);"""
|
|
|
|
new_content = content[:old_start_idx] + "return Builder(builder: (context) {\n" + new_code + content[old_end_idx+6:]
|
|
|
|
with open('kifi-app/lib/features/dashboard/presentation/dashboard_screen.dart', 'w') as f:
|
|
f.write(new_content)
|
|
print("Dashboard screen patched")
|