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

Bad state: No element on Browser reload #655

Open
Terranic opened this issue Jan 22, 2024 · 1 comment
Open

Bad state: No element on Browser reload #655

Terranic opened this issue Jan 22, 2024 · 1 comment

Comments

@Terranic
Copy link

Describe the bug
Bad State: no element
exception after web app reload (starting it works smoothly)

Beamer version: 1.6.0 (and 2.0.0-dev.1)

To Reproduce
Steps to reproduce the behavior:

  class MyApp extends StatelessWidget {
    const MyApp({super.key});
  
    @override
    Widget build(BuildContext context) {
      final routerDelegate = BeamerDelegate(
        locationBuilder: RoutesLocationBuilder(
          routes: {
            '/': (context, state, data) => const MainWidget(""),
            '/bot/:botId': (context, state, data) {
              final botId = state.pathParameters['botId']!;
              return MainWidget(botId);
            }
          },
        ).call,
      );
      return MaterialApp.router(
        routeInformationParser: BeamerParser(),
        routerDelegate: routerDelegate,
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
      );
    }
  }

For this code, I get the following exception - but only when reloading the web app

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 356:5            last]
packages/beamer/src/beamer_delegate.dart 975:35                              [_setBrowserTitle]
packages/beamer/src/beamer_delegate.dart 760:9                               <fn>
packages/flutter/src/widgets/basic.dart 7682:48                              build
packages/flutter/src/widgets/framework.dart 5541:22                          build
...

which is this code

  void _setBrowserTitle(BuildContext context) {
    if (active && kIsWeb && setBrowserTabTitle) {
      SystemChrome.setApplicationSwitcherDescription(
          ApplicationSwitcherDescription(
EXC-->        label: _currentPages.last.title ??
            currentBeamLocation.state.routeInformation.uri.path,
        primaryColor: Theme.of(context).primaryColor.value,
      ));
    }
  }

Expected behavior
No Exception :-)

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Browser: Chrome
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@lenzpaul
Copy link
Contributor

@Terranic Try declaring your BeamerDelegate outside of the build method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants