nslogx / nslogx/flutter_easyloading

Failed assertion: '_dependents.isEmpty': is not true.

Open
#153 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dart
Stars
1.3k
Forks
249
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

If a stateful widget throws exception during didUpdateWidget, popping the Navigator will trigger the failed assertion.

Reproduce code.
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: EasyLoading.init(),
      onGenerateRoute: (_) => MaterialPageRoute(builder: (_) => const Page1()),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () => Navigator.of(context).push(
            MaterialPageRoute(builder: (_) => const Page2()),
          ),
          child: const Text('Start the test'),
        ),
      ),
    );
  }
}

class Page2 extends StatefulWidget {
  const Page2({Key? key}) : super(key: key);

  @override
  State<Page2> createState() => _Page2State();
}

class _Page2State extends State<Page2> {
  var shouldThrow = false;

  @override
  void initState() {
    super.initState();

    Future.delayed(const Duration(seconds: 1))
        .then((_) => setState(() => shouldThrow = true));
    Future.delayed(const Duration(seconds: 3))
        .then((_) => Navigator.pop(context));
  }

  @override
  Widget build(BuildContext context) {
    return _StatefulWidget(shouldThrow: shouldThrow);
  }
}

class _StatefulWidget extends StatefulWidget {
  final bool shouldThrow;

  const _StatefulWidget({Key? key, required this.shouldThrow})
      : super(key: key);

  @override
  State<_StatefulWidget> createState() => _State();
}

class _State extends State<_StatefulWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(child: Text('shouldThrow=${widget.shouldThrow}')),
    );
  }

  @override
  void initState() {
    super.initState();
    _maybeThrow();
  }

  @override
  void didUpdateWidget(covariant _StatefulWidget oldWidget) {
    super.didUpdateWidget(oldWidget);
    _maybeThrow();
  }

  void _maybeThrow() {
    if (widget.shouldThrow) {
      throw 'This exception is expected.';
    }
  }
}

Flutter/Dart info

[✓] Flutter (Channel stable, 2.10.0, on macOS 11.3 20E232 darwin-x64, locale en)
    • Flutter version 2.10.0 at /Users/xxx/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5f105a6ca7 (3 weeks ago), 2022-02-01 14:15:42 -0800
    • Engine revision 776efd2034
    • Dart version 2.16.0
    • DevTools version 2.9.2

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/xxx/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.0

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

[✓] Android Studio (version 2020.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 11.0.10+0-b96-7281165)

[✓] IntelliJ IDEA Ultimate Edition (version 2021.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • 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

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

[✓] Connected device (3 available)
    • iPhone 13 (mobile) • 5FC7388A-59D8-4476-896A-2D101BD04108 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
    • macOS (desktop)    • macos                                • darwin-x64     • macOS 11.3 20E232 darwin-x64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 98.0.4758.109

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Screenshots

The demo throws this on purpose 👇 But Navigator.pop triggers this 👇
Simulator Screen Shot - iPhone 13 - 2022-02-23 at 17 43 13 Simulator Screen Shot - iPhone 13 - 2022-02-23 at 17 43 15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided example with Flutter 2.10.0 and inspect the lifecycle path that produces the '_dependents.isEmpty' assertion after Navigator.pop. Done means the reported exception no longer leads to the failed assertion when the route is popped.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.