flutter / flutter/flutter

RestorableRouteFuture._hookOntoRouteFuture: Null check operator used on a null value

Open
#164,679 4 comments 0 reactions 0 assignees View on GitHub
a: production c: crash f: routes framework needs repro info P2 team-framework triaged-framework
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Steps to reproduce

Unable to reproduce this error however it occurs frequently in production app.
Still working on finding reproducible steps but at the present sharing the stack trace here.

### Expected results

Should not throw error.

### Actual results

```console
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown .
#00 pc 0x6abff7 com.agendaboa.app (RestorableRouteFuture._hookOntoRouteFuture [navigator.dart:6112]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#01 pc 0xd8839f com.agendaboa.app (RestorableRouteFuture.initWithValue [navigator.dart:6075]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#02 pc 0x6371b7 com.agendaboa.app (RestorationMixin.registerForRestoration [restoration.dart:810]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#03 pc 0x636fef com.agendaboa.app (RestorationMixin.registerForRestoration [restoration.dart:779]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#04 pc 0x636f0f com.agendaboa.app (MyTestScreenState.restoreState [my_test_screen_state.dart:128]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#05 pc 0xadbfe7 com.agendaboa.app (RestorationMixin._doRestore [restoration.dart:924]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#06 pc 0xadbf83 com.agendaboa.app (RestorationMixin.didChangeDependencies [restoration.dart:910]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#07 pc 0xadbdb3 com.agendaboa.app (MyTestScreenState.didChangeDependencies [my_test_screen_state.dart:107]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#08 pc 0x71780b com.agendaboa.app (StatefulElement._firstBuild [framework.dart:5766]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#09 pc 0x6813bf com.agendaboa.app (ComponentElement.mount [framework.dart:5593]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#10 pc 0xef7cd3 com.agendaboa.app (Element.inflateWidget [framework.dart:4468]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#11 pc 0xef2c9b com.agendaboa.app (ComponentElement.performRebuild [framework.dart:3963]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#12 pc 0x71777f com.agendaboa.app (ComponentElement._firstBuild [framework.dart:5333]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#13 pc 0x6813bf com.agendaboa.app (ComponentElement.mount [framework.dart:5593]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#14 pc 0xef7cd3 com.agendaboa.app (Element.inflateWidget [framework.dart:4468]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#15 pc 0x67f423 com.agendaboa.app (SingleChildRenderObjectElement.mount [framework.dart:3963]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#16 pc 0xef7cd3 com.agendaboa.app (Element.inflateWidget [framework.dart:4468]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#17 pc 0x67f423 com.agendaboa.app (SingleChildRenderObjectElement.mount [framework.dart:3963]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#18 pc 0xef7cd3 com.agendaboa.app (Element.inflateWidget [framework.dart:4468]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#19 pc 0xef2c9b com.agendaboa.app (ComponentElement.performRebuild [framework.dart:3963]) (BuildId: 63956a455ab3a60210d24405e0f84812)
```

### Code sample

Code sample

```dart
import 'package:flutter/material.dart';

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

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

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(colorSchemeSeed: Colors.blue),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
final String title;

const MyHomePage({super.key, required this.title});

@override
State createState() => _MyHomePageState();
}

class _MyHomePageState extends State with RestorationMixin {
late RestorableRouteFuture _routeFuture;
int _counter = 0;

@override
void initState() {
super.initState();
// setup the route screen
_routeFuture = RestorableRouteFuture(
navigatorFinder: (context) => Navigator.of(context, rootNavigator: true),
onPresent: (navigator, arguments) {
return navigator.restorablePushNamed("myRoute", arguments: arguments);
},
onComplete: _routeResult,
);
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
debugPrint("didChangeDependencies");
}

@override
String? get restorationId => "restoreMyScreen";

@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(_routeFuture, "routeFuture");
}

void _routeResult(result) {
debugPrint(result);
}

@override
void dispose() {
_routeFuture.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _routeFuture.present(),
tooltip: 'Open my route',
child: const Icon(Icons.add),
),
);
}
}
```

### Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

### Logs

Logs

```console
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown .
#00 pc 0x6abff7 com.agendaboa.app (RestorableRouteFuture._hookOntoRouteFuture [navigator.dart:6112]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#01 pc 0xd8839f com.agendaboa.app (RestorableRouteFuture.initWithValue [navigator.dart:6075]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#02 pc 0x6371b7 com.agendaboa.app (RestorationMixin.registerForRestoration [restoration.dart:810]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#03 pc 0x636fef com.agendaboa.app (RestorationMixin.registerForRestoration [restoration.dart:779]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#04 pc 0x636f0f com.agendaboa.app (MyTestScreenState.restoreState [my_test_screen_state.dart:128]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#05 pc 0xadbfe7 com.agendaboa.app (RestorationMixin._doRestore [restoration.dart:924]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#06 pc 0xadbf83 com.agendaboa.app (RestorationMixin.didChangeDependencies [restoration.dart:910]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#07 pc 0xadbdb3 com.agendaboa.app (MyTestScreenState.didChangeDependencies [my_test_screen_state.dart:107]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#08 pc 0x71780b com.agendaboa.app (StatefulElement._firstBuild [framework.dart:5766]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#09 pc 0x6813bf com.agendaboa.app (ComponentElement.mount [framework.dart:5593]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#10 pc 0xef7cd3 com.agendaboa.app (Element.inflateWidget [framework.dart:4468]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#11 pc 0xef2c9b com.agendaboa.app (ComponentElement.performRebuild [framework.dart:3963]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#12 pc 0x71777f com.agendaboa.app (ComponentElement._firstBuild [framework.dart:5333]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#13 pc 0x6813bf com.agendaboa.app (ComponentElement.mount [framework.dart:5593]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#14 pc 0xef7cd3 com.agendaboa.app (Element.inflateWidget [framework.dart:4468]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#15 pc 0x67f423 com.agendaboa.app (SingleChildRenderObjectElement.mount [framework.dart:3963]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#16 pc 0xef7cd3 com.agendaboa.app (Element.inflateWidget [framework.dart:4468]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#17 pc 0x67f423 com.agendaboa.app (SingleChildRenderObjectElement.mount [framework.dart:3963]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#18 pc 0xef7cd3 com.agendaboa.app (Element.inflateWidget [framework.dart:4468]) (BuildId: 63956a455ab3a60210d24405e0f84812)
#19 pc 0xef2c9b com.agendaboa.app (ComponentElement.performRebuild [framework.dart:3963]) (BuildId: 63956a455ab3a60210d24405e0f84812)
```

Device information for reference:
Device
Brand:Motorola
Model:Moto G(9) Plus
Orientation:Portrait
RAM free: 849.7 MB
Disk free: 53.96 GB
Operating System
Version:Android 11
Orientation:Portrait
Rooted: No
Crash
Date:Mar 6, 2025, 12:05:48 AM

### Flutter Doctor output

Doctor output

```console
[✓] Flutter (Channel stable, 3.24.5, on macOS 12.7.6 21H1320 darwin-x64, locale en-US)
• Flutter version 3.24.5 on channel stable at /Users/appleapple/fvm/versions/3.24.5
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision dec2ee5c1f (4 months ago), 2024-11-13 11:13:06 -0800
• Engine revision a18df97ca5
• Dart version 3.5.4
• DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/appleapple/Library/Android/sdk
• Platform android-35, 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.11+0-17.0.11b1207.24-11852314)
• All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
! Flutter recommends a minimum Xcode version of 15.
Download the latest version or update via the Mac App Store.
• CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.1)
• 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.11+0-17.0.11b1207.24-11852314)

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

[✓] Connected device (3 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 15 (API 35) (emulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.7.6 21H1320 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 134.0.6998.45

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

! Doctor found issues in 1 category.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.