Skip to content

Changing a MaterialApp's initialRoute does not rebuild the widget. #12454

@gavindoughtie

Description

@gavindoughtie

Steps to Reproduce

Run this demo app:

https://github.com/gavindoughtie/flutter_nav_bug

The key code is:

class _MyAppState extends State<MyApp> {
  String nextRoute = homeRoute;

  void _nextRoute() {
    String route = secondRoute;
    if (nextRoute == secondRoute) route = homeRoute;
    setState(() {
      print('setting route to $route');
      nextRoute = route;
    });
  }

  @override
  Widget build(BuildContext context) {
    final routes = {
      homeRoute: (BuildContext context) => new MyHomePage(nextRoute: _nextRoute),
      secondRoute: (BuildContext context) => new _MySecondRoute(_nextRoute),
    };
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      routes: routes,
      initialRoute: nextRoute,
    );
  }
}

Triggering the _nextRoute() function prints the new initialRoute, but the application is not rebuilt with the new route.

Logs

Launching lib/main.dart on iPhone 7 Plus in debug mode...
Running Xcode build...
	    CFBundleIdentifier = "com.yourcompany.flutterNavBug";
	    PackageType = Developer;
	    SimulatorRootPath = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk";
	    SimulatorUserPath = "/Users/doughtie/Library/Developer/CoreSimulator/Devices/CD05F0E8-3440-4AB4-941B-E0D3544A87C0/data";
	}
	state->old_bundle: /Users/doughtie/Library/Developer/CoreSimulator/Devices/CD05F0E8-3440-4AB4-941B-E0D3544A87C0/data/Containers/Bundle/Application/6CB1077B-A23F-497C-9AE1-B150D05BC5B7/Runner.app
	state->new_bundle: /Users/doughtie/flutter_nav_bug/build/ios/iphonesimulator/Runner.app
	state->dst_bundle: /Users/doughtie/Library/Developer/CoreSimulator/Devices/CD05F0E8-3440-4AB4-941B-E0D3544A87C0/data/Library/Caches/com.apple.mobile.installd.staging/temp.0Xk96l/extracted/Payload//Runner.app, binaryDiff flag: FALSE
		dst_ipa: /Users/doughtie/Library/Developer/CoreSimulator/Devices/CD05F0E8-3440-4AB4-941B-E0D3544A87C0/data/Library/Caches/com.apple.mobile.installd.staging/temp.0Xk96l/extracted
Oct  8 00:05:50 doughtie-macbookpro2 com.apple.CoreSimulator.SimDevice.CD05F0E8-3440-4AB4-941B-E0D3544A87C0.launchd_sim[16956] (com.apple.videosubscriptionsd[25547]): Service exited with abnormal code: 1
	    arguments =     (
	        "--enable-dart-profiling",
	        "--flx=/Users/doughtie/flutter_nav_bug/build/app.flx",
	        "--dart-main=/Users/doughtie/flutter_nav_bug/lib/main.dart",
	        "--packages=/Users/doughtie/flutter_nav_bug/.packages",
	        "--enable-checked-mode",
	        "--start-paused",
	        "--observatory-port=8100",
	        "--diagnostic-port=8101"
	    );
	    environment =     {
	    };
	}
		retryTimeout: 120.000000 (default write com.apple.CoreSimulatorBridge LaunchRetryTimeout <value>)
		bootTimeout: 300.000000 (default write com.apple.CoreSimulatorBridge BootRetryTimeout <value>)
		bootLeeway: 120.000000 (default write com.apple.CoreSimulatorBridge BootLeeway <value>)
		Note: Use 'xcrun simctl spawn booted defaults write <domain> <key> <value>' to modify defaults in the booted Simulator device.
	Simulator booted at: 2017-10-07 03:13:02 +0000
	Current time: 2017-10-08 07:05:55 +0000
	Within boot leeway: NO
You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
Syncing files to device iPhone 7 Plus...
setting route to route_two

Run flutter analyze and attach any output of that command also.

% flutter analyze
Analyzing /Users/doughtie/flutter_nav_bug...
No issues found!
Ran in 4.8s

Flutter Doctor

% flutter doctor
[✓] Flutter (on Mac OS X 10.12.6 16G29, locale en-US, channel master)
    • Flutter at /Users/doughtie/flutter
    • Framework revision 6420c75f26 (12 days ago), 2017-09-25 13:59:05 -0700
    • Engine revision 005212683c
    • Tools Dart version 1.25.0-dev.11.0

[✓] Android toolchain - develop for Android devices (Android SDK 26.0.1)
    • Android SDK at /Users/doughtie/Library/Android/sdk
    • Platform android-26, build-tools 26.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] iOS toolchain - develop for iOS devices (Xcode 8.3.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 8.3.3, Build version 8E3004b
    • ios-deploy 1.9.2
    • CocoaPods version 1.3.1

[✓] Android Studio (version 2.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[-] IntelliJ IDEA Community Edition (version 2017.2.5)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    • Dart plugin version 172.4155.35
    • For information about installing plugins, see
      https://flutter.io/intellij-setup/#installing-the-plugins

[✓] Connected devices
    • iPhone 7 Plus • CD05F0E8-3440-4AB4-941B-E0D3544A87C0 • ios • iOS 10.3 (simulator)

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.f: routesNavigator, Router, and related APIs.found in release: 3.3Found to occur in 3.3found in release: 3.4Found to occur in 3.4frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamwaiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions