Skip to content

Commit

Permalink
feat: implement Custom app router
Browse files Browse the repository at this point in the history
  • Loading branch information
cevheri committed Dec 11, 2024
1 parent 0430d8b commit a71f6a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/presentation/common_widgets/drawer/drawer_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_advance/configuration/app_key_constants.dart';
import 'package:flutter_bloc_advance/configuration/local_storage.dart';
import 'package:flutter_bloc_advance/routes/app_router.dart';
import 'package:flutter_bloc_advance/routes/app_routes_constants.dart';
import 'package:go_router/go_router.dart';
import 'package:string_2_icon/string_2_icon.dart';

import '../../../generated/l10n.dart';
Expand Down Expand Up @@ -72,7 +72,7 @@ class ApplicationDrawer extends StatelessWidget {
),
onTap: () {
Navigator.pop(context);
context.go(childMenu.url);
AppRouter().push(context, childMenu.url);
},
);
}).toList(),
Expand Down Expand Up @@ -104,15 +104,15 @@ class ApplicationDrawer extends StatelessWidget {
listener: (context, state) {
if (state.isLogout) {
context.read<DrawerBloc>().add(Logout());
context.go(ApplicationRoutesConstants.login);
AppRouter().push(context, ApplicationRoutesConstants.login);
}
},
),
BlocListener<AccountBloc, AccountState>(
listener: (context, state) {
if (state.status == AccountStatus.failure) {
context.read<DrawerBloc>().add(Logout());
context.go(ApplicationRoutesConstants.login);
AppRouter().push(context, ApplicationRoutesConstants.login);
}
},
),
Expand Down Expand Up @@ -146,7 +146,7 @@ class ApplicationDrawer extends StatelessWidget {
void onLogout(context) {
BlocProvider.of<DrawerBloc>(context).add(Logout());
Navigator.pop(context);
context.go(ApplicationRoutesConstants.login);
AppRouter().push(context, ApplicationRoutesConstants.login);
}

void onCancel(context) {
Expand Down Expand Up @@ -221,7 +221,7 @@ class LanguageSwitchButtonState extends State<LanguageSwitchButton> {
await S.load(Locale(isTurkish ? 'tr' : 'en'));
if (mounted) {
setState(
() => context.go(ApplicationRoutesConstants.home),
() => AppRouter().push(context, ApplicationRoutesConstants.home),
);
}
},
Expand Down
23 changes: 17 additions & 6 deletions lib/presentation/screen/login/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter_bloc_advance/routes/app_routes_constants.dart';
import 'package:flutter_bloc_advance/utils/app_constants.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:go_router/go_router.dart';

import '../../../generated/l10n.dart';
import 'bloc/login.dart';
Expand Down Expand Up @@ -128,17 +127,29 @@ class LoginScreen extends StatelessWidget {
debugPrint("BEGIN: login submit button listener ${state.username}");

if (state is LoginLoadingState) {
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(SnackBar(behavior: SnackBarBehavior.floating, content: Text(S.of(context).loading), backgroundColor: Theme.of(context).colorScheme.primary, width: MediaQuery.of(context).size.width* 0.8));
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(SnackBar(
behavior: SnackBarBehavior.floating,
content: Text(S.of(context).loading),
backgroundColor: Theme.of(context).colorScheme.primary,
width: MediaQuery.of(context).size.width * 0.8));
} else if (state is LoginLoadedState) {
debugPrint("BEGIN: login submit button listener LoginLoadedState");
AppRouter().push(context, ApplicationRoutesConstants.home);
ScaffoldMessenger.of(_scaffoldKey.currentContext!).hideCurrentSnackBar();
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(SnackBar(behavior: SnackBarBehavior.floating,content: Text(S.of(context).success), backgroundColor: Theme.of(context).colorScheme.primary, width: MediaQuery.of(context).size.width* 0.8));
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(SnackBar(
behavior: SnackBarBehavior.floating,
content: Text(S.of(context).success),
backgroundColor: Theme.of(context).colorScheme.primary,
width: MediaQuery.of(context).size.width * 0.8));
debugPrint("END: login submit button listener LoginLoadedState");
} else if (state is LoginErrorState) {
debugPrint("BEGIN: login submit button listener LoginErrorState");
ScaffoldMessenger.of(_scaffoldKey.currentContext!).hideCurrentSnackBar();
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(SnackBar(behavior: SnackBarBehavior.floating,content: Text(S.of(context).failed), backgroundColor: Theme.of(context).colorScheme.primary, width: MediaQuery.of(context).size.width* 0.8));
ScaffoldMessenger.of(_scaffoldKey.currentContext!).showSnackBar(SnackBar(
behavior: SnackBarBehavior.floating,
content: Text(S.of(context).failed),
backgroundColor: Theme.of(context).colorScheme.primary,
width: MediaQuery.of(context).size.width * 0.8));
debugPrint("END: login submit button listener LoginErrorState");
}
},
Expand Down Expand Up @@ -166,7 +177,7 @@ class LoginScreen extends StatelessWidget {
return SizedBox(
child: TextButton(
key: loginButtonForgotPasswordKey,
onPressed: () => context.go(ApplicationRoutesConstants.forgotPassword),
onPressed: () => AppRouter().push(context, ApplicationRoutesConstants.forgotPassword),
child: Text(S.of(context).password_forgot),
),
);
Expand All @@ -176,7 +187,7 @@ class LoginScreen extends StatelessWidget {
return SizedBox(
child: TextButton(
key: loginButtonRegisterKey,
onPressed: () => context.go(ApplicationRoutesConstants.register),
onPressed: () => AppRouter().push(context, ApplicationRoutesConstants.register),
child: Text(S.of(context).register),
),
);
Expand Down

0 comments on commit a71f6a9

Please sign in to comment.