Skip to content

MaterialApp onGenerateRoute show unexpected behaviour. #64775

@thangnguyen69vt

Description

@thangnguyen69vt

Steps to Reproduce

3
This is the file /lib/main.dart, nothing else needed `import 'package:flutter/material.dart';

import 'login.dart';
import 'home.dart';
import 'splash.dart';
import 'register.dart';

void main(List<String> args) {
  runApp(MaterialApp(
    initialRoute: '/splash',
    onGenerateRoute: (settings) {
      if (settings.name == '/splash') {
        return MaterialPageRoute(builder: (_) => SplashPage());
      } else if (settings.name == '/home') {
        print("ok");
        return MaterialPageRoute(builder: (_) => MainScreen());
      } else if (settings.name == '/login') {
        return MaterialPageRoute(builder: (_) => LoginPage());
      } else if (settings.name == '/register') {
        return MaterialPageRoute(builder: (_) => RegisterPage());
      }
    },
  ));
}

Expected results:
settings.name argument should be '/splash' on the first onGenerateRoute call.
Actual results:
settings.name argument was '/' on the first onGenerateRoute call, despite setting the initialRoute to '/splash'. And it turned to '/splash' on the second call, which is not explicitly executed from my part( no call to navigator.Push or Pop).

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: first hourThe first hour of using Flutterd: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.f: routesNavigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions