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

[GO_ROUTER SUPPORT] The MaterialApp.router has no field named navigatorKey #7

Open
tungakanui opened this issue Aug 8, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@tungakanui
Copy link
Contributor

I have to pass the navigator key in GoRouter config but it ran to an error
@singleton class AppPages { final router = GoRouter( initialLocation: Routes.home, debugLogDiagnostics: true, navigatorKey: getIt<AliceHelper>().getNavigatorKey, routes: [ GoRoute( name: Routes.home, path: Routes.home, builder: (context, state) => const CorePage(), ), GoRoute( name: Routes.anotherPage, path: Routes.anotherPage, builder: (context, state) => const AnotherPage(), ), ], ); }

E/flutter ( 1208): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:overlay_support/src/overlay_state_finder.dart': Failed assertion: line 12 pos 7: '_debugInitialized': Global OverlaySupport Not Initialized ! E/flutter ( 1208): ensure your app wrapped widget OverlaySupport.global E/flutter ( 1208): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61) E/flutter ( 1208): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5) E/flutter ( 1208): #2 findOverlayState (package:overlay_support/src/overlay_state_finder.dart:12:7) E/flutter ( 1208): #3 showOverlay (package:overlay_support/src/overlay.dart:63:26) E/flutter ( 1208): #4 AliceCore.showDebugAnimNotification (package:flutter_alice/core/alice_core.dart:237:5) E/flutter ( 1208): #5 AliceCore._showLocalNotification (package:flutter_alice/core/alice_core.dart:171:5) E/flutter ( 1208): #6 AliceCore._onCallsChanged (package:flutter_alice/core/alice_core.dart:87:15) E/flutter ( 1208): #7 new AliceCore._.<anonymous closure> (package:flutter_alice/core/alice_core.dart:67:55) E/flutter ( 1208): #8 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10) E/flutter ( 1208): #9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter ( 1208): #10 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) E/flutter ( 1208): #11 _MultiStreamController.addSync (dart:async/stream_impl.dart:1044:36) E/flutter ( 1208): #12 _MultiControllerSink.add (package:rxdart/src/utils/forwarding_stream.dart:130:35) E/flutter ( 1208): #13 _StartWithStreamSink.onData (package:rxdart/src/transformers/start_with.dart:12:31) E/flutter ( 1208): #14 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10) E/flutter ( 1208): #15 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11) E/flutter ( 1208): #16 _DelayedData.perform (dart:async/stream_impl.dart:515:14) E/flutter ( 1208): #17 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11) E/flutter ( 1208): #18 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7) E/flutter ( 1208): #19 _microtaskLoop (dart:async/schedule_microtask.dart:40:21) E/flutter ( 1208): #20 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5) E/flutter ( 1208): I/flutter ( 1208): [🌎 Easy Localization] [DEBUG] Build I/flutter ( 1208): [🌎 Easy Localization] [DEBUG] Init Localization Delegate I/flutter ( 1208): [🌎 Easy Localization] [DEBUG] Init provider I/flutter ( 1208): I/flutter ( 1208): ╔╣ DioError ║ DioExceptionType.connectionTimeout I/flutter ( 1208): ║ The request connection took longer than 0:00:30.000000. It was aborted. I/flutter ( 1208): ╚══════════════════════════════════════════════════════════════════════════════════════════╝ I/flutter ( 1208): [🌎 Easy Localization] [WARNING] Localization key [dio_cancel_request] not found

@tungakanui tungakanui added the enhancement New feature or request label Aug 8, 2023
@SardorbekR
Copy link

you have navigatorKey inside GoRouter()

@ogak-github
Copy link

ogak-github commented Feb 7, 2024

Hi, I have related problem with @tungakanui
the alice is not displayed
Here is my setup:

I create an global navigatorkey variable like this

final navigatorKeyProvider =
    Provider<GlobalKey<NavigatorState>>((ref) => GlobalKey<NavigatorState>());

I set lazy navigatoKey for alice in main like this =>

class _MyAppState extends ConsumerState<MyApp> {
  late Alice alice;

  @override
  void initState() {
    alice = Alice(showNotification: true, showInspectorOnShake: true);

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final router = ref.watch(routerProvider);
    final navigatorKey = ref.watch(navigatorKeyProvider);
    alice.setNavigatorKey(navigatorKey);
    return OverlaySupport(
      child: MaterialApp.router(
      ...

and in my base Dio like this

@Riverpod(keepAlive: true)
Future<Dio> dioInstance(DioInstanceRef ref) async {
  final Alice alice = Alice(showNotification: true, showInspectorOnShake: true);
  final Dio dio = Dio();
  const apiUrl = prod;
/*   final options = BaseOptions(
    baseUrl: apiUrl,
    connectTimeout: connectTimeOut,
    receiveTimeout: receiveTimeOut,
  ); */
  final optionsWithLog = dio
    ..options.baseUrl = apiUrl
    ..options.connectTimeout = connectTimeOut
    ..options.receiveTimeout = receiveTimeOut
    ..interceptors.add(AuthInterceptor(ref))
    ..interceptors.add(
      alice.getDioInterceptor(),
    );
  /* ..interceptors.add(
      LogInterceptor(
        request: false,
        error: false,
        responseHeader: false,
        requestHeader: false,
        responseBody: false,
      ),); */

  return optionsWithLog;
}

The Alice not displayed..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants