Skip to content

Commit

Permalink
fix: go_router redirect problem in production(API call waiting)
Browse files Browse the repository at this point in the history
  • Loading branch information
cevheri committed Dec 14, 2024
1 parent 4ab7da5 commit b578f72
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions lib/routes/go_router_routes/app_go_router_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_advance/configuration/app_logger.dart';
import 'package:flutter_bloc_advance/configuration/local_storage.dart';
import 'package:flutter_bloc_advance/generated/l10n.dart';
import 'package:flutter_bloc_advance/presentation/common_blocs/account/account.dart';
import 'package:flutter_bloc_advance/routes/app_routes_constants.dart';
Expand Down Expand Up @@ -55,31 +56,38 @@ class AppGoRouterConfig {
redirect: (context, state) async {
_log.debug("BEGIN: redirect");
_log.debug("redirect - uri: ${state.uri}");
final accountBloc = context.read<AccountBloc>();
var accountBloc = context.read<AccountBloc>();
await Future.delayed(const Duration(microseconds: 100));
accountBloc.add(const AccountLoad());
await Future.delayed(const Duration(microseconds: 500));
_log.debug("redirect - accountBloc.state: ${accountBloc.state.status}");
// check if the account is loaded
// if (accountBloc.state.status == AccountStatus.initial) {
// //
// _log.debug("redirect with account load from initial");
// accountBloc.add(const AccountLoad());
// _log.debug("redirect with account load from initial - after add");
// //
// _log.debug("redirect with account load from initial - before delay");
// await Future.delayed(const Duration(seconds: 1));
// _log.debug("redirect with account load from initial - after delay");
// //
// if (accountBloc.state.status == AccountStatus.failure) {
// _log.debug("END: redirect - ${accountBloc.state.status} with login - initial>failure");
// return ApplicationRoutesConstants.login;
// }
// } else
if (accountBloc.state.status == AccountStatus.failure) {
_log.debug("END: redirect - ${accountBloc.state.status} with login - initial>failure");
// await Future.delayed(const Duration(microseconds: 3000));
// _log.debug("redirect - accountBloc.state: ${accountBloc.state.status}");
// // check if the account is loaded
// // if (accountBloc.state.status == AccountStatus.initial) {
// // //
// // _log.debug("redirect with account load from initial");
// // accountBloc.add(const AccountLoad());
// // _log.debug("redirect with account load from initial - after add");
// // //
// // _log.debug("redirect with account load from initial - before delay");
// // await Future.delayed(const Duration(seconds: 1));
// // _log.debug("redirect with account load from initial - after delay");
// // //
// // if (accountBloc.state.status == AccountStatus.failure) {
// // _log.debug("END: redirect - ${accountBloc.state.status} with login - initial>failure");
// // return ApplicationRoutesConstants.login;
// // }
// // } else
// if (accountBloc.state.status == AccountStatus.failure) {
// _log.debug("END: redirect - ${accountBloc.state.status} with login - initial>failure");
// return ApplicationRoutesConstants.login;
// }

// check if the jwtToken is null
if(AppLocalStorageCached.jwtToken == null) {
_log.debug("END: redirect - jwtToken is null");
return ApplicationRoutesConstants.login;
}
//TODO check if jwtToken is expired

_log.debug("END: redirect return null");
return null;
Expand Down

0 comments on commit b578f72

Please sign in to comment.