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

Navigator 2.0 can't provide initial page #71106

Closed
wreppun opened this issue Nov 23, 2020 · 18 comments · Fixed by #73153
Closed

Navigator 2.0 can't provide initial page #71106

wreppun opened this issue Nov 23, 2020 · 18 comments · Fixed by #73153
Assignees
Labels
f: routes Navigator, Router, and related APIs. found in release: 1.24 Found to occur in 1.24 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on

Comments

@wreppun
Copy link

wreppun commented Nov 23, 2020

Steps to Reproduce

  1. Run flutter create bug.
  2. Replace main.dart
main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:rxdart/rxdart.dart';
import 'package:unrulr_mobile/blocs/api_call_bloc.dart';
import 'package:unrulr_mobile/blocs/bloc_utils.dart';
import 'package:unrulr_mobile/blocs/connections_bloc.dart';
import 'package:unrulr_mobile/blocs/membership_bloc.dart';
import 'package:unrulr_mobile/blocs/objective_descriptions_bloc.dart';
import 'package:unrulr_mobile/blocs/refresh_feed_bloc.dart';
import 'package:unrulr_mobile/components/common/unrulr_progress_indicator.dart';
import 'package:unrulr_mobile/components/create/status_display.dart';
import 'package:unrulr_mobile/components/exhibition_display.dart';
import 'package:unrulr_mobile/components/utils/stream_builder_combinators.dart';
import 'package:unrulr_mobile/data/external/api.dart';
import 'package:unrulr_mobile/data/public_exhibition_info.dart';
import 'package:unrulr_mobile/navigation/top_level_nav_key_provider.dart';
import 'package:unrulr_mobile/screens/journey_screen.dart';
import 'package:unrulr_mobile/theme.dart';
import 'package:unrulr_mobile/utils/async_status.dart';

class ElephantCowApp extends StatefulWidget {
  @override
  _ElephantCowAppState createState() => _ElephantCowAppState();
}

class _ElephantCowAppState extends State<ElephantCowApp> {
  final _publicRouter = ElephantCowRouterDelegate();
  final _routeParser = PublicRouteInformationParser();

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerDelegate: _publicRouter,
      routeInformationParser: _routeParser,
    );
  }
}

/// Expand to ADT or Class/Subclasses as needed
@immutable
class ElephantCowPath {
  final bool isElephant;
  final bool isCow;

  ElephantCowPath.elephant()
      : isElephant = true,
        isCow = false;
  ElephantCowPath.cow()
      : isElephant = false,
        isCow = true;

  T caseMap<T>({
    @required T Function() onElephant,
    @required T Function() onCow,
  }) {
    if (isElephant) {
      return onElephant();
    }

    if (isCow) {
      return onCow();
    }

    throw UnimplementedError('Case not handled in path $this');
  }

  @override
  bool operator ==(Object other) {
    if (other is ElephantCowPath) {
      if (isElephant && other.isElephant) {
        return true;
      }

      if (isCow && other.isCow) {
        return true;
      }
    }

    return false;
  }

  @override
  String toString() {
    return caseMap(
      onCow: () => 'Path: cow',
      onElephant: () => 'Path: elephant',
    );
  }
}

class ElephantPage extends Page<ElephantCowPath> {
  ElephantPage() : super(key: ValueKey('elephant'));

  @override
  Route<ElephantCowPath> createRoute(BuildContext context) {
    return MaterialPageRoute(
      settings: this,
      builder: (_) => Scaffold(
        body: Center(
          child: Text('I am an elephant'),
        ),
      ),
    );
  }
}

class CowPage extends Page<ElephantCowPath> {
  CowPage() : super(key: ValueKey('cow'));

  @override
  Route<ElephantCowPath> createRoute(BuildContext context) {
    return MaterialPageRoute(
      settings: this,
      builder: (_) => Scaffold(
        body: Center(
          child: Text('I am a cow.  Moo.'),
        ),
      ),
    );
  }
}

class ElephantCowRouterDelegate extends RouterDelegate<ElephantCowPath>
    with ChangeNotifier, PopNavigatorRouterDelegateMixin<ElephantCowPath> {
  final _navigatorKey = GlobalKey<NavigatorState>();

  final routeStack = <ElephantCowPath>[];

  @override
  ElephantCowPath get currentConfiguration =>
      routeStack.isNotEmpty ? routeStack.last : null;

  @override
  Widget build(BuildContext context) {
    print('building router');

    return Navigator(
      key: _navigatorKey,
      pages: [
        ...routeStack.map(_buildPage),
      ],
      onPopPage: (route, dynamic result) {
        if (!route.didPop(result)) {
          return false;
        }

        return true;
      },
    );
  }

  @override
  Future<void> setInitialRoutePath(ElephantCowPath path) {
    print('set initial route path');
    return setNewRoutePath(path);
  }

  @override
  Future<void> setNewRoutePath(ElephantCowPath path) async {
    print('setting new path: $path');

    if (routeStack.isEmpty || routeStack.last != path) {
      print('added path');
      routeStack.add(path);
    } else {
      print('skipped add path');
    }

    return SynchronousFuture(null);
  }

  @override
  GlobalKey<NavigatorState> get navigatorKey => _navigatorKey;

  static Page<ElephantCowPath> _buildPage(ElephantCowPath p) {
    return p.caseMap(
      onElephant: () => ElephantPage(),
      onCow: () => CowPage(),
    );
  }
}

class PublicRouteInformationParser
    extends RouteInformationParser<ElephantCowPath> {
  @override
  Future<ElephantCowPath> parseRouteInformation(
    RouteInformation routeInformation,
  ) async {
    return SynchronousFuture(_parsePublicPath(routeInformation.location));
  }

  static ElephantCowPath _parsePublicPath(String location) {
    final uri = Uri.parse(location);

    // Handle '/'
    if (uri.pathSegments.length == 0) {
      print('parsed: root');
      return ElephantCowPath.elephant();
    }

    // Handle '/post/:id'
    if (uri.pathSegments.length == 1) {
      if (uri.pathSegments.first == 'elephant') {
        print('parsed: elephant');
        return ElephantCowPath.elephant();
      }

      if (uri.pathSegments.first == 'cow') {
        print('parsed: cow');
        return ElephantCowPath.cow();
      }
    }

    // Handle unknown routes
    print('parsed: unknown ${uri.pathSegments.join('/')}');
    return ElephantCowPath.elephant();
  }

  @override
  RouteInformation restoreRouteInformation(ElephantCowPath path) {
    print('restoring route info - $path');

    return path.caseMap(
      onCow: () => RouteInformation(location: '/cow'),
      onElephant: () => RouteInformation(location: '/elephant'),
    );
  }
}

  1. flutter run -d chrome

Expected results:
Navigator 2.0 loads the initial page based on the browser url.

Actual results:
Navigator 2.0 throws an error before it attempts to parse the url.

The following assertion was thrown building Builder:                                     
Navigator.onGenerateRoute was null, but the route named "/" was referenced.              
To use the Navigator API with named routes (pushNamed, pushReplacementNamed, or          
pushNamedAndRemoveUntil), the Navigator must be provided with an onGenerateRoute handler.
The Navigator was:                                                                       
  NavigatorState#aaa00(lifecycle state: initialized)                                     
                                                                                         
The relevant error-causing widget was:                                                   
  MaterialApp                                                                                                                                                                     
  .../elephant_cow_navigator_2_0/lib/main.dart:19:24       
                                                                                         
When the exception was thrown, this was the stack:                                       
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 216:49  throw_     
packages/flutter/src/widgets/navigator.dart 3967:9                            <fn>       
packages/flutter/src/widgets/navigator.dart 3976:14                                      
[_routeNamed]                                                                            
packages/flutter/src/widgets/navigator.dart 2763:27                                      
defaultGenerateInitialRoutes                                                             
packages/flutter/src/widgets/navigator.dart 3332:41

More info

  /// This is called whenever the [setInitialRoutePath] method's future
  /// completes, the [setNewRoutePath] method's future completes with the value
  /// true, the [popRoute] method's future completes with the value true, or
  /// this object notifies its clients (see the [Listenable] interface, which
  /// this interface includes). In addition, it may be called at other times. It
  /// is important, therefore, that the methods above do not update the state
  /// that the [build] method uses before they complete their respective
  /// futures.

Based on its name and the documentation around the build method on RouterDelegate, I would expect setInitialRoutePath to set the initial Path.

Instead, if Navigator.pages is initially empty, the Navigator attempts to use onGenerateRoute to create the initial route. If I'm using Navigator 2.0, I wouldn't expect to implement onGenerateRoute.

Workarounds

I can add a temporary initial route, and remove it as soon as I parse the url, but that seems fairly convoluted for a pretty basic case.

Doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, 1.24.0-10.2.pre, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [!] Xcode - develop for iOS and macOS (Xcode 12.1) ! CocoaPods 1.8.3 out of date (1.9.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. [✓] Chrome - develop for the web [✓] Android Studio (version 4.1) [✓] VS Code (version 1.51.1) [✓] Connected device (2 available)
@darshankawar
Copy link
Member

Issue replicable on latest beta and on latest master.

Error log
For a more detailed help message, press "h". To quit, press "q".
parsed: root
building router
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building Builder:
Navigator.onGenerateRoute was null, but the route named "/" was referenced.
To use the Navigator API with named routes (pushNamed, pushReplacementNamed, or
pushNamedAndRemoveUntil), the Navigator must be provided with an onGenerateRoute handler.
The Navigator was:
  NavigatorState#0fe83(lifecycle state: initialized)

The relevant error-causing widget was:
  MaterialApp file:///Users/dhs/Documents/NCFlutter/webtest/lib/main.dart:19:24

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 216:49  throw_
packages/flutter/src/widgets/navigator.dart 4007:9                            <fn>
packages/flutter/src/widgets/navigator.dart 4016:14                           [_routeNamed]
packages/flutter/src/widgets/navigator.dart 2803:27                           defaultGenerateInitialRoutes
packages/flutter/src/widgets/navigator.dart 3372:41                           restoreState
packages/flutter/src/widgets/restoration.dart 982:5                           [_doRestore]
packages/flutter/src/widgets/restoration.dart 968:7                           didChangeDependencies
packages/flutter/src/widgets/navigator.dart 3411:11                           didChangeDependencies
packages/flutter/src/widgets/framework.dart 4842:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 6173:14                           mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
set initial route path
setting new path: Path: elephant
added path
building router
restoring route info - Path: elephant
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 6173:14                           mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 6173:14                           mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/framework.dart 4709:16                           performRebuild
packages/flutter/src/widgets/framework.dart 4856:11                           performRebuild
packages/flutter/src/widgets/framework.dart 4378:5                            rebuild
packages/flutter/src/widgets/framework.dart 4663:5                            [_firstBuild]
packages/flutter/src/widgets/framework.dart 4847:11                           [_firstBuild]
packages/flutter/src/widgets/framework.dart 4658:5                            mount
packages/flutter/src/widgets/framework.dart 3624:13                           inflateWidget
packages/flutter/src/widgets/framework.dart 3389:18                           updateChild
packages/flutter/src/widgets/binding.dart 1208:16                             [_rebuild]
packages/flutter/src/widgets/binding.dart 1179:5                              mount
packages/flutter/src/widgets/binding.dart 1121:16                             <fn>
packages/flutter/src/widgets/framework.dart 2730:19                           buildScope
packages/flutter/src/widgets/binding.dart 1120:12                             attachToRenderTree
packages/flutter/src/widgets/binding.dart 959:24                              attachRootWidget
packages/flutter/src/widgets/binding.dart 941:7                               <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19       internalCallback


beta and master flutter doctor -v
[✓] Flutter (Channel beta, 1.24.0-10.2.pre, on Mac OS X 10.15.4 19E2269
    darwin-x64, locale en-IN)
    • Flutter version 1.24.0-10.2.pre at /Users/dhs/documents/Fluttersdk/flutter
    • Framework revision 022b333a08 (6 days ago), 2020-11-18 11:35:09 -0800
    • Engine revision 07c1eed46b
    • Dart version 2.12.0 (build 2.12.0-29.10.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0.1, Build version 12A7300
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 46.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.50.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.15.1

[✓] Connected device (4 available)
    • SM A260G (mobile)                   • 5200763ebcfa861f
      • android-arm    • Android 8.1.0 (API 27)
    • iPhone SE (2nd generation) (mobile) • 6C85835D-FBFD-4AB3-8DE8-B4FAD35E5367
      • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator)
    • Web Server (web)                    • web-server
      • web-javascript • Flutter Tools
    • Chrome (web)                        • chrome
      • web-javascript • Google Chrome 87.0.4280.67

• No issues found!


[✓] Flutter (Channel master, 1.24.0-8.0.pre.344, on Mac OS X 10.15.4 19E2269
    darwin-x64, locale en-IN)
    • Flutter version 1.24.0-8.0.pre.344 at
      /Users/dhs/documents/Fluttersdk/flutter
    • Framework revision de56c6ad72 (35 hours ago), 2020-11-23 05:28:06 +0900
    • Engine revision 23a8e027db
    • Dart version 2.12.0 (build 2.12.0-62.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.0.1, Build version 12A7300
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 46.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.50.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.15.1

[✓] Connected device (5 available)
    • SM A260G (mobile)                   • 5200763ebcfa861f
      • android-arm    • Android 8.1.0 (API 27)
    • iPhone SE (2nd generation) (mobile) • 6C85835D-FBFD-4AB3-8DE8-B4FAD35E5367
      • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator)
    • macOS (desktop)                     • macos
      • darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Web Server (web)                    • web-server
      • web-javascript • Flutter Tools
    • Chrome (web)                        • chrome
      • web-javascript • Google Chrome 87.0.4280.67

• No issues found!


@wreppun FYI I see below exception also:

Another exception was thrown: A GlobalKey was used multiple times inside one widget's child list. after running your code sample.

@darshankawar darshankawar added f: routes Navigator, Router, and related APIs. found in release: 1.24 Found to occur in 1.24 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically passed first triage labels Nov 24, 2020
@darshankawar
Copy link
Member

Related to 65777

@wreppun
Copy link
Author

wreppun commented Nov 24, 2020

@darshankawar I saw that exception too, but I think that's an artifact of the earlier exception?

Both exceptions disappear when an initial page is used.

@chunhtai
Copy link
Contributor

I think there are two issues here:

  1. We should update the error message says the page list cannot be empty
  2. The code uses synchronous future, the route stack should have the route when build is called. I am not sure why this isn't the case

For now, you can workaround this by building some default route when route stack is empty.

@yjbanov yjbanov removed the platform-web Web applications specifically label Dec 3, 2020
@yjbanov
Copy link
Contributor

yjbanov commented Dec 3, 2020

Removed the web label as this doesn't look web-specific.

@chunhtai chunhtai changed the title [web] Navigator 2.0 can't provide initial page Navigator 2.0 can't provide initial page Dec 3, 2020
@danilofuchs
Copy link

danilofuchs commented Dec 11, 2020

I have a Navigator 2.0 widget (with pages and onPopPage) nested inside a regular navigator with named routes. This internal navigator is accessed through a named route.

Whenever I navigate to it, this error is thrown. I wasn't able to determine if this is the same issue or if I should create a new one.

The error is non-breaking, but shows up on console.

I solved the error by adding this: onGenerateRoute: (_) => MaterialPageRoute(builder: (_) => Container())

@chunhtai
Copy link
Contributor

chunhtai commented Dec 30, 2020

if you return synchronous future, you will want to remove the async keyword in the function, otherwise it still turns it into a async future.

Something like this will work. If the logic does have to be async, you will need to handle the case where the build is called before the parsing finishes. I will update the error message

Code
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(ElephantCowApp());
}

class ElephantCowApp extends StatefulWidget {
  @override
  _ElephantCowAppState createState() => _ElephantCowAppState();
}

class _ElephantCowAppState extends State<ElephantCowApp> {
  final _publicRouter = ElephantCowRouterDelegate();
  final _routeParser = PublicRouteInformationParser();

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerDelegate: _publicRouter,
      routeInformationParser: _routeParser,
    );
  }
}

/// Expand to ADT or Class/Subclasses as needed
@immutable
class ElephantCowPath {
  final bool isElephant;
  final bool isCow;

  ElephantCowPath.elephant()
      : isElephant = true,
        isCow = false;
  ElephantCowPath.cow()
      : isElephant = false,
        isCow = true;

  T caseMap<T>({
    @required T Function() onElephant,
    @required T Function() onCow,
  }) {
    if (isElephant) {
      return onElephant();
    }

    if (isCow) {
      return onCow();
    }

    throw UnimplementedError('Case not handled in path $this');
  }

  @override
  bool operator ==(Object other) {
    if (other is ElephantCowPath) {
      if (isElephant && other.isElephant) {
        return true;
      }

      if (isCow && other.isCow) {
        return true;
      }
    }

    return false;
  }

  @override
  String toString() {
    return caseMap(
      onCow: () => 'Path: cow',
      onElephant: () => 'Path: elephant',
    );
  }
}

class ElephantPage extends Page<ElephantCowPath> {
  ElephantPage() : super(key: ValueKey('elephant'));

  @override
  Route<ElephantCowPath> createRoute(BuildContext context) {
    return MaterialPageRoute(
      settings: this,
      builder: (_) => Scaffold(
        body: Center(
          child: Text('I am an elephant'),
        ),
      ),
    );
  }
}

class CowPage extends Page<ElephantCowPath> {
  CowPage() : super(key: ValueKey('cow'));

  @override
  Route<ElephantCowPath> createRoute(BuildContext context) {
    return MaterialPageRoute(
      settings: this,
      builder: (_) => Scaffold(
        body: Center(
          child: Text('I am a cow.  Moo.'),
        ),
      ),
    );
  }
}

class ElephantCowRouterDelegate extends RouterDelegate<ElephantCowPath>
    with ChangeNotifier, PopNavigatorRouterDelegateMixin<ElephantCowPath> {
  final _navigatorKey = GlobalKey<NavigatorState>();

  final routeStack = <ElephantCowPath>[];

  @override
  ElephantCowPath get currentConfiguration =>
      routeStack.isNotEmpty ? routeStack.last : null;

  @override
  Widget build(BuildContext context) {
    print('building router');

    return Navigator(
      key: _navigatorKey,
      pages: [
        ...routeStack.map(_buildPage),
      ],
      onPopPage: (route, dynamic result) {
        if (!route.didPop(result)) {
          return false;
        }

        return true;
      },
    );
  }

  @override
  Future<void> setInitialRoutePath(ElephantCowPath path) {
    print('set initial route path');
    return setNewRoutePath(path);
  }

  @override
  Future<void> setNewRoutePath(ElephantCowPath path) {
    print('setting new path: $path');

    if (routeStack.isEmpty || routeStack.last != path) {
      print('added path');
      routeStack.add(path);
    } else {
      print('skipped add path');
    }

    return SynchronousFuture(null);
  }

  @override
  GlobalKey<NavigatorState> get navigatorKey => _navigatorKey;

  static Page<ElephantCowPath> _buildPage(ElephantCowPath p) {
    return p.caseMap(
      onElephant: () => ElephantPage(),
      onCow: () => CowPage(),
    );
  }
}

class PublicRouteInformationParser
    extends RouteInformationParser<ElephantCowPath> {
  @override
  Future<ElephantCowPath> parseRouteInformation(
      RouteInformation routeInformation,
      ) {
    return SynchronousFuture(_parsePublicPath(routeInformation.location));
  }

  static ElephantCowPath _parsePublicPath(String location) {
    final uri = Uri.parse(location);

    // Handle '/'
    if (uri.pathSegments.length == 0) {
      print('parsed: root');
      return ElephantCowPath.elephant();
    }

    // Handle '/post/:id'
    if (uri.pathSegments.length == 1) {
      if (uri.pathSegments.first == 'elephant') {
        print('parsed: elephant');
        return ElephantCowPath.elephant();
      }

      if (uri.pathSegments.first == 'cow') {
        print('parsed: cow');
        return ElephantCowPath.cow();
      }
    }

    // Handle unknown routes
    print('parsed: unknown ${uri.pathSegments.join('/')}');
    return ElephantCowPath.elephant();
  }

  @override
  RouteInformation restoreRouteInformation(ElephantCowPath path) {
    print('restoring route info - $path');

    return path.caseMap(
      onCow: () => RouteInformation(location: '/cow'),
      onElephant: () => RouteInformation(location: '/elephant'),
    );
  }
}

@esDotDev
Copy link

esDotDev commented Apr 15, 2021

I ran into this same error, no idea why it's happening as I'm just trying to set initialPath on a Navigator that has a single persistent MaterialPage. The onGenerateRoute hack worked but it did not correctly set my initialPath.

Something like:

return Material(
      child: Navigator(
        key: navigatorKey,
        transitionDelegate: NoAnimationTransitionDelegate(),
        // initialPath: myInitialPath  // uncomment this to go boom
        pages: [ MaterialPage( child: ..., )],
        onPopPage: (_, __) => false,
      ),

In the end I just went straight to the source and manually injected my own initial route if "/" is reported:

  Future<void> setInitialRoutePath(String path) {
    if (path == "/") path = myInitialPath ?? path;
    return super.setInitialRoutePath(path);
  }

@chunhtai
Copy link
Contributor

@esDotDev
navigator initialpath only works for the first build, and that is one of the limitation we decide to go with nav2. Since you can pass your own pages, you should be able to change the page freely.

@rayliverified
Copy link

rayliverified commented Jul 2, 2021

Thank you for the example here @chunhtai

Removing the async keyword from parseRouteInformation and returning a Synchronous location is what helped setInitialRoutePath work correctly.

Posting the errors here to help future users who are searching for a solution.

Error:

The Navigator.pages must not be empty to use the Navigator.pages API

The following assertion was thrown building Builder:
A GlobalKey was used multiple times inside one widget's child list.
The offending GlobalKey was: [LabeledGlobalKey#6d0cb]
The parent of the widgets with that key was:
Builder
The first child to get instantiated with that key became:
Navigator-[LabeledGlobalKey#6d0cb]
The second child that was to be instantiated with that key was:
Builder
A GlobalKey can only be specified on one widget at a time in the widget tree.

Fixed parseRouteInformation.

  @override
  Future<DefaultRoute> parseRouteInformation(
      RouteInformation routeInformation) {
    final Uri uri = Uri.parse(routeInformation.location ?? '');
    return SynchronousFuture(DefaultRoute.parse(uri));
  }

@mtgnoah
Copy link

mtgnoah commented Jul 12, 2021

@chunhtai
What can I do if I need the async because it is getting a future value from my backend?

Future<void> isUserLoggedIn() async {
    ParseUser? currentUser = await ParseUser.currentUser() as ParseUser?;
    if (currentUser == null) {
      setNewRoutePath(loginPageConfig);
    }
    //Checks whether the user's session token is valid
    final ParseResponse parseResponse =
        (await ParseUser.getCurrentUserFromServer(
            currentUser!.get<String>('sessionToken')!))!;

    if (!parseResponse.success) {
      //Invalid session. Logout
      await currentUser.logout();
      setNewRoutePath(loginPageConfig);
    } else {
      setNewRoutePath(navBarPageConfig);
    }
  }

@chunhtai
Copy link
Contributor

@mtgnoah If the logic does have to be async, you will need to handle the case where the build is called before the parsing finishes.

@mtgnoah
Copy link

mtgnoah commented Jul 14, 2021

@mtgnoah If the logic does have to be async, you will need to handle the case where the build is called before the parsing finishes.

How would I handle that case? Should I implement a route that is just a loading screen with circularprogressindicator?

@mtgnoah
Copy link

mtgnoah commented Jul 14, 2021

@chunhtai Also just letting you know that Parse is the backend and that is what I am awaiting on. It's not parsing anything.

@mtgnoah
Copy link

mtgnoah commented Jul 14, 2021

Unhandled Exception: Null check operator used on a null value This is the error I am receiving by the way.

@mtgnoah
Copy link

mtgnoah commented Jul 14, 2021

final ParseResponse parseResponse =
(await ParseUser.getCurrentUserFromServer(
currentUser!.get('sessionToken')!))!;
This is the line that causes the error. I also tried wrapping it in an if statement of if(currentUser != null)

@mtgnoah
Copy link

mtgnoah commented Jul 14, 2021

This worked! For anyone with the same issue on accessing backend

    ParseUser? currentUser = await ParseUser.currentUser() as ParseUser?;
    ParseResponse? parseResponse;
    if (currentUser == null) {
      setNewRoutePath(loginPageConfig);
    }
    if (currentUser != null) {
      //Checks whether the user's session token is valid
      parseResponse = (await ParseUser.getCurrentUserFromServer(
          currentUser.get<String>('sessionToken')!))!;
    }
    if (parseResponse?.success ?? false) {
      //Invalid session. Logout
      await currentUser!.logout();
      setNewRoutePath(loginPageConfig);
    } else {
      setNewRoutePath(navBarPageConfig);
    }
  }

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: routes Navigator, Router, and related APIs. found in release: 1.24 Found to occur in 1.24 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants