Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix routing #15

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bindings/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import 'package:how_much/controllers/helpers/nav_bar.dart';
class DashboardBindings extends Bindings {
@override
void dependencies() {
Get.put(NavigationController());
Get.put(NavigationController(), permanent: true);
}
}
4 changes: 2 additions & 2 deletions lib/bindings/edit_assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:how_much/controllers/add/new_category.dart';
class EditAssetsBindings extends Bindings {
@override
void dependencies() {
Get.put(AddNewAssetController());
Get.put(AddNewCategoryController());
Get.put(AddNewAssetController(), permanent: true);
Get.put(AddNewCategoryController(), permanent: true);
}
}
2 changes: 0 additions & 2 deletions lib/controllers/helpers/nav_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class NavigationController extends GetxController {
case 1:
Get.toNamed('/settings');
break;
case 2:
break;
}
}
}
21 changes: 12 additions & 9 deletions lib/controllers/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class LoginController extends GetxController {
// initialize these controllers after successful login immediately

// we need this for being able to map asset symbols to names
Get.put(AssetTableController());
Get.put(AssetTableController(), permanent: true);

// this is for snapshot controller to be able to fetch prices
PriceTablesController priceTablesController =
Get.put(PriceTablesController());
Get.put(PriceTablesController(), permanent: true);
if (priceTablesController.loading.value) {
// Wait until priceTableController.loading becomes false
await priceTablesController.loading.stream
Expand All @@ -85,39 +85,42 @@ class LoginController extends GetxController {

// snapshots are needed for creating the report, and for the userAssets
// this is also setting the `newUser` observable
SnapshotsController snapshotsController = Get.put(SnapshotsController());
SnapshotsController snapshotsController =
Get.put(SnapshotsController(), permanent: true);
if (snapshotsController.loading.value) {
// Wait until snapshotsController.loading becomes false
await snapshotsController.loading.stream
.firstWhere((isLoading) => !isLoading);
}

// this controls what will be displayed in the dashboard, along with the report
UserAssetsController userAssetsController = Get.put(UserAssetsController());
UserAssetsController userAssetsController =
Get.put(UserAssetsController(), permanent: true);
if (userAssetsController.loading.value) {
// Wait until userAssetsController.loading becomes false
await userAssetsController.loading.stream
.firstWhere((isLoading) => !isLoading);
}

// date controller will set the dates for Report Controller
Get.put(DateController());
Get.put(DateController(), permanent: true);

// we need report controller for both edit assets screen and for dashboard
ReportController reportController = Get.put(ReportController());
ReportController reportController =
Get.put(ReportController(), permanent: true);
if (reportController.loading.value) {
// Wait until reportController.loading becomes false
await reportController.loading.stream
.firstWhere((isLoading) => !isLoading);
}

// this lets us display the total amount in other currencies
Get.put(CurrencyController());
Get.put(CurrencyController(), permanent: true);

if (snapshotsController.newUser) {
Get.toNamed('/intro');
Get.offAllNamed('/intro');
} else {
Get.toNamed('/dashboard');
Get.offAllNamed('/dashboard');
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/snapshots_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SnapshotsController extends GetxController {
if (!foundSnapshots) {
// couldn't find any local snapshot, fetch transactions from the server
TransactionsController transactionsController =
Get.put(TransactionsController());
Get.put(TransactionsController(), permanent: true);

// if there are no transactions, it means we are dealing with a new user
bool wereThereAnyTransactions =
Expand Down
3 changes: 1 addition & 2 deletions lib/presentation/pages/main/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class NotificationsPage extends GetView<LoginController> {
appBar: AppBar(
leading: BackButton(
onPressed: () {
navigationController.selectedIndex.value = 0;
Get.toNamed('/dashboard');
navigationController.onItemTapped(0);
},
),
title: const Text("Notifications"),
Expand Down
7 changes: 3 additions & 4 deletions lib/presentation/pages/main/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class SettingsPage extends GetView<LoginController> {
appBar: AppBar(
leading: BackButton(
onPressed: () {
navigationController.selectedIndex.value = 0;
Get.toNamed('/dashboard');
navigationController.onItemTapped(0);
},
),
title: const Text("Settings"),
Expand All @@ -37,13 +36,13 @@ class SettingsPage extends GetView<LoginController> {
return ListTile(
leading: const Icon(Ionicons.information_circle_outline),
title: const Text("About"),
onTap: () => Get.toNamed('about'),
onTap: () => Get.toNamed('/about'),
);
} else if (index == 1) {
return ListTile(
leading: const Icon(Ionicons.help_circle_outline),
title: const Text("FAQ"),
onTap: () => Get.toNamed('faq'),
onTap: () => Get.toNamed('/faq'),
);
} else {
return ListTile(
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/widgets/nav_bar/custom_fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CustomFAB extends StatelessWidget {
color: howBlack,
),
onPressed: () {
Get.toNamed('edit_assets');
Get.toNamed('/edit_assets');
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/widgets/nav_bar/discard_save.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DiscardAndSave extends StatelessWidget {
bool discardConfirmed = await showDiscardDialog(context);
if (discardConfirmed) {
userAssetsController.discardChanges();
Get.toNamed('/dashboard');
Get.offAllNamed('/dashboard');
}
})),
Obx(() => PrimaryButton(
Expand All @@ -54,7 +54,7 @@ class DiscardAndSave extends StatelessWidget {
loadingAnimation();
await userAssetsController.saveAssets();
Get.find<ReportController>().calculateAll();
Get.toNamed('/dashboard');
Get.offAllNamed('/dashboard');
}
}))
]),
Expand Down
Loading