beamer icon indicating copy to clipboard operation
beamer copied to clipboard

Navigator.onGenerateRoute was null error on hot reload

Open MrSquaare opened this issue 1 year ago • 1 comments

Describe the bug If the class passed as a parameter to runApp does not return MaterialApp directly, when a hot reload is triggered, the following error occurs:

Navigator.onGenerateRoute was null, but the route named "/" was referenced.

Beamer version: 1.5.0

To Reproduce Steps to reproduce the behavior:

  1. Generate a new Flutter project
  2. Copy-paste the following code in main.dart:
import 'package:beamer/beamer.dart';
import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MyAppView();
  }
}

class MyAppView extends StatelessWidget {
  MyAppView({Key? key}) : super(key: key);

  final _routerDelegate = BeamerDelegate(
    locationBuilder: RoutesLocationBuilder(
      routes: {
        "/": (context, state, data) => const Center(
              child: Text("Hello, World!"),
            ),
      },
    ),
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerDelegate: _routerDelegate,
      routeInformationParser: BeamerParser(),
    );
  }
}
  1. Run the app
  2. Trigger hot reload
  3. See error

Smartphone (please complete the following information):

  • Device: Pixel 5 (Emulator)
  • OS: Android 12

MrSquaare avatar Jul 08 '22 17:07 MrSquaare

Hey @MrSquaare :wave: Thanks for creating an issue!

This looks like a general behavior in Flutter, not specific to Beamer. Can we reproduce that with vanilla Router API?

slovnicki avatar Jul 21 '22 21:07 slovnicki