Earlybyte / aad_oauth

Flutter Azure Active Directory OAuth Package
https://pub.dev/packages/aad_oauth
MIT License
92 stars 179 forks source link

Go router issues #278

Open thomtomdup opened 8 months ago

thomtomdup commented 8 months ago

Hello. Have you test it with go router without issue ? Because in my case i have many issues. Thank you. Regards.

mikedigit commented 8 months ago

Hi, If i can give you some pointer, I use this package in my app using go router without issue yet. However, your message does not provide a lot of context around the encountered error, so I'm not sure where to go from there.

thomtomdup commented 8 months ago

Hello.

I use it for ADB2C and the response give issue for gorouter : For example in redirection from ADB2C to flutter app : GoException: no routes for location: state=7ipvjc4ZDjuJAgXTxXpfGbeyzm....

ShmuelCammebys commented 6 months ago

I am also having issues. The Config object requires a GlobalKey<NavigatorState>, and the only way to get that is with router.configuration.navigatorKey because MaterialApp.router doesn't have a navigatorKey param. Except when I use router.configuration.navigatorKey, the following error is thrown:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.
The key [LabeledGlobalKey<NavigatorState>#d2b44] was used by multiple widgets. The parents of those
widgets were:
- InheritedGoRouter(goRouter: Instance of 'GoRouter')
- SignInContent(state: SignInContentState#4b314)
A GlobalKey can only be specified on one widget at a time in the widget tree.

When the exception was thrown, this was the stack:
#0      BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/widgets/framework.dart:3103:13)
#1      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#2      BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure>.<anonymous closure> (package:flutter/src/widgets/framework.dart:3047:20)
#3      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#4      BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure> (package:flutter/src/widgets/framework.dart:3042:36)
#5      BuildOwner._debugVerifyGlobalKeyReservation (package:flutter/src/widgets/framework.dart:3111:6)
#6      BuildOwner.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:3168:11)
#7      BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3250:8)
#8      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:987:19)
#9      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5)
#10     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15)
#11     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9)
#12     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:5)
#13     _invoke (dart:ui/hooks.dart:312:13)
#14     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:383:5)
#15     _drawFrame (dart:ui/hooks.dart:283:31)
════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: Multiple widgets used the same GlobalKey.
Another exception was thrown: Multiple widgets used the same GlobalKey.

I also sometimes get this error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Could not push new route using provided navigatorKey, Because NavigatorState returned from provided navigatorKey is null. Please Make sure provided navigatorKey is passed to WidgetApp. This can also happen if at the time of this method call WidgetApp is not part of the flutter widget tree
#0      RequestCode.requestCode (package:aad_oauth/request_code.dart:41:7)
<asynchronous suspension>
#1      MobileOAuth._performFullAuthFlow (package:aad_oauth/helper/mobile_oauth.dart:160:16)
<asynchronous suspension>
#2      MobileOAuth._authorization (package:aad_oauth/helper/mobile_oauth.dart:143:22)
<asynchronous suspension>
#3      MobileOAuth.login (package:aad_oauth/helper/mobile_oauth.dart:42:12)
<asynchronous suspension>
#4      SignInContentState.build.<anonymous closure> (package:my_app/sign_in_screen.dart:123:30)
<asynchronous suspension>
ShmuelCammebys commented 5 months ago

I was able to solve the issue by passing the NavigatorKey from my ShellRoute to the library:

  final _rootShellNavigatorKey = GlobalKey<NavigatorState>();
  final _rootNavigatorKey = GlobalKey<NavigatorState>();

  late final _router = GoRouter(
    navigatorKey: _rootNavigatorKey,
    routes: [
      ShellRoute(
        navigatorKey: _rootShellNavigatorKey,
        routes: [ GoRoute(pageBuilder: (...) => SignInScreen(rootNavigator: _rootShellNavigator)... ]
        ...
      )
      ...
    ]
    ...
  );
  ...
  // SignInScreen.dart
  Config(
    navigatorKey: rootNavigator,
    clientId: ...,
  );
mvukojicic commented 5 months ago

I have the same problem but I am using Getx, "A GlobalKey was used multiple times inside one widget's child list", @ShmuelCammebys do you maybe have an idea how to solve it in Getx? I have a GetMaterial wrapper, and I am using getPages for routing.