Skip to content

Commit

Permalink
Stack Optimization and Null Check Error Fix (#203)
Browse files Browse the repository at this point in the history
Co-authored-by: Fred Falcon <7475382+fredfalcon@users.noreply.github.com>
  • Loading branch information
solo-daemon and fredfalcon committed Mar 5, 2023
1 parent 05fcba0 commit 5f5bf75
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
15 changes: 6 additions & 9 deletions lib/src/pages/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';

import '../../components/appbar.dart';
import '../../pages/welcome.dart';


/// Navigator and drawer provider for the main pages:
/// Issues, Report Bug, Leaderboards and Feed.
Expand Down Expand Up @@ -61,11 +63,8 @@ class _HomeState extends ConsumerState<Home> {

if (loginState == LoginType.guest) {
await forgetUser();
Navigator.pushReplacementNamed(
context,
RouteManager.welcomePage,
arguments: "You need to login in order to start bug hunt."
);
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(
builder: (context) => WelcomePage(snackBarMessage:"Only Logged in users can start a Bug Hunt")), (Route route) => false);
await logout();
} else {
_reportBugState="Start Bug Hunt";
Expand Down Expand Up @@ -169,10 +168,8 @@ class _HomeState extends ConsumerState<Home> {
// ...
// Then close the drawer
await forgetUser();
Navigator.pushReplacementNamed(
context,
RouteManager.welcomePage,
);
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(
builder: (context) => WelcomePage()), (Route route) => false);
await logout();
},
),
Expand Down
8 changes: 4 additions & 4 deletions lib/src/pages/home/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import '../../components/issuechip.dart';
import '../../providers/authstate_provider.dart';
import '../../models/issuedata_model.dart';
import '../../util/endpoints/issue_endpoints.dart';
import '../../pages/welcome.dart';


/// Page that displays the stats of a user registered on BugHeist,
/// shows dummy data for Guest login.
Expand Down Expand Up @@ -248,11 +250,9 @@ class _UserProfileState extends ConsumerState<UserProfile> {
),
IconButton(
onPressed: () {
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(
builder: (context) => WelcomePage()), (Route route) => false);
forgetUser();
Navigator.pushReplacementNamed(
context,
RouteManager.welcomePage,
);
logout();
},
icon: Icon(Icons.power_settings_new_rounded),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/pages/welcome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class _WelcomePageState extends State<WelcomePage> {
builder: (BuildContext context, ref, Widget? child) {
return TextButton(
onPressed: () {
Navigator.of(context).pushNamed(
ref.read(authStateNotifier.notifier).guestLogin();
Navigator.of(context).pushNamed(
RouteManager.homePage,
);
ref.read(authStateNotifier.notifier).guestLogin();
},
child: Text(
"Explore Anonymously",
Expand Down
2 changes: 1 addition & 1 deletion lib/src/providers/authstate_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AuthNotifier extends StateNotifier<AsyncValue<AuthState>> {
);

/// Do a guest type authentication.
void guestLogin() async {
Future<void> guestLogin() async {
await storage.write(
key: "remember",
value: "guest",
Expand Down

0 comments on commit 5f5bf75

Please sign in to comment.