Skip to content

Flutter Web don't work to NamedRoutes on 1.18.0 #55426

@jonataslaw

Description

@jonataslaw

I have a web application that was working fine about 2 months ago. I had to go to the Dev branch because of some hotfix, and now my Flutter Web projects don't work anymore.
onGenerateRoute is returning null;

Reproduction code:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
        child: MaterialApp(
      initialRoute: "/",
      onGenerateRoute: (settings) {
        print("SETTINGS: ${settings.name}");
        // print: SETTINGS:
        // settings is null
        switch (settings.name) {
          case '/':
            return MaterialPageRoute(
              builder: (_) => First(),
              settings: settings,
            );
          case '/second':
            return MaterialPageRoute(
              builder: (_) => Second(),
              settings: settings,
            );
          case '/third':
            return MaterialPageRoute(
              builder: (_) => Third(),
              settings: settings,
            );
          default:
            return MaterialPageRoute(
                settings: settings,
                builder: (_) => Scaffold(
                      body: Center(
                          child: Text('No route defined for ${settings.name}')),
                    ));
        }
      },
    ));
  }
}

class First extends StatefulWidget {
  @override
  _FirstState createState() => _FirstState();
}

class _FirstState extends State<First> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(onPressed: () {}),
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.add),
          onPressed: () {
            //  Get.snackbar("hi", "i am a modern snackbar");
          },
        ),
        title: Text('First Route}'),
      ),
      body: Center(
        child: RaisedButton(
          color: Colors.blue,
          child: Text('Open route'),
          onPressed: () {
            // Get.toNamed("/second");
          },
        ),
      ),
    );
  }
}

class Second extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.add),
          onPressed: () {
            //  Get.snackbar("hi", "i am a modern snackbar");
          },
        ),
        title: Text('second Route'),
      ),
      body: Center(
        child: RaisedButton(
          color: Colors.blue,
          child: Text('Open route'),
          onPressed: () {
            //  Get.toNamed("/third");
          },
        ),
      ),
    );
  }
}

class Third extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Third Route "),
      ),
      body: Center(
        child: RaisedButton(
          color: Colors.blue,
          onPressed: () {
            //  Get.back();
          },
          child: Text('Go back!'),
        ),
      ),
    );
  }
}

Flutter Doctor:

$ flutter doctor v
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.18.0-dev.5.0, on Linux, locale pt_BR.UTF-8)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.6)
[✓] IntelliJ IDEA Community Edition (version 2019.3)
[✓] Connected device (2 available)

• No issues found!

The same project works normally on Android and iOS, but on Flutter web, the undefined route screen that I programmed on onGenerateRoute is displayed because settings is returning null.

EDIT: Beta branch (1.17.0) works. Dev branch 1.18.0 Don't work.
Some update in the Dev version completely broke the named routes in Flutter Web

Metadata

Metadata

Assignees

Labels

assigned for triageissue is assigned to a domain expert for further triagec: regressionIt was better in the past than it is nowf: routesNavigator, Router, and related APIs.found in release: 1.18Occurs in 1.18has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specifically

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions