Skip to content

App crashes with "BuildOwner.scheduleBuildFor() called inappropriately." in callback for "ext.flutter.reassemble" when hot-reloading multiple times  #154060

@benPesso

Description

@benPesso

Steps to reproduce

  1. Create an app with the provided code sample.
  2. Launch the app on iOS simulator.
  3. Trigger a Hot Reload. (No error should trigger at this stage.)
  4. Trigger another Hot Reload.
  5. Observe the below error.

It seems the issue is with using a global (or provider) GoRouter while having extendBodyBehindAppBar set to true on the HomeView's Scaffold widget.

Expected results

No error should be thrown when using GoRouter and extendBodyBehindAppBar.

Actual results

After the first Hot Reload, every consecutive Hot Reload triggers the following error:

The following assertion was thrown during a service extension callback for "ext.flutter.reassemble":
BuildOwner.scheduleBuildFor() called inappropriately.
The BuildOwner.scheduleBuildFor() method should only be called while the buildScope() method is actively rebuilding the widget tree.

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(const AppScreen());
}

// AppScreen
class AppScreen extends StatelessWidget {
  const AppScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: router,
    );
  }
}

// HomeView
class HomeView extends StatelessWidget {
  const HomeView({super.key});

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Scaffold(
          body: SizedBox(
            width: double.maxFinite,
            child: Container(color: Colors.pink),
          ),
          extendBodyBehindAppBar: true,
        ),
      ],
    );
  }
}

// SignInView
class SignInView extends StatelessWidget {
  const SignInView({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(color: Colors.green);
  }
}

// Router
final router = GoRouter(
  initialLocation: '/',
  errorBuilder: (_, state) => Container(color: Colors.red),
  redirect: (_, state) {
    print(state.matchedLocation);
    return (state.matchedLocation != '/sign-in') ? '/sign-in' : null;
  },
  routes: [
    GoRoute(
      name: 'home',
      path: '/',
      builder: (_, state) => HomeView(
        key: state.pageKey,
      ),
      routes: [
        GoRoute(
          name: 'signIn',
          path: 'sign-in',
          builder: (_, state) => SignInView(
            key: state.pageKey,
          ),
        ),
      ],
    ),
  ],
);

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Console log: Console log.txt

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.24.0, on macOS 14.6.1 23G93 darwin-x64, locale en-US)
    • Flutter version 3.24.0 on channel stable at /.../flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (3 weeks ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /.../Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.92.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.94.0

[✓] Network resources
    • All expected network resources are available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listc: crashStack traces logged to the consolec: regressionIt was better in the past than it is nowfound in release: 3.24Found to occur in 3.24found in release: 3.25Found to occur in 3.25frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versiont: hot reloadReloading code during "flutter run"team-frameworkOwned by Framework teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions