alibaba / alibaba/flutter_boost
跑 test/initial_route.dart 报错
- Dominant language
- Dart
- Stars
- 7.2k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
## Steps to Reproduce
**A small application to reproduce the bug(最小化可复现的demo)**
1. git checkout v3.0-null-safety-release.1 并且 flutter pub get
2. 解决 test/initial_route.dart 下的 nullsafe 报错
```
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State {
static Map routerMap = {
'initialRoute': (settings, uniqueId) {
return PageRouteBuilder(
settings: settings,
pageBuilder: (_, __, ___) {
return Scaffold(
body: Text('initialRoute text'),
);
},
);
},
'mainPage': (settings, uniqueId) {
return PageRouteBuilder(
settings: settings,
pageBuilder: (_, __, ___) {
final Map map = settings.arguments as Map;
final String? dataString = map['data'] as String?;
return Scaffold(
body: Center(
child: Column(
children: [
Text('mainPage text'),
Text(dataString ?? ''),
],
)),
);
});
},
};
Route? routeFactory(RouteSettings settings, String? uniqueId) {
FlutterBoostRouteFactory func = routerMap[settings.name] as FlutterBoostRouteFactory;
if (func == null) {
return null;
}
return func(settings, uniqueId);
}
Widget appBuilder(Widget home) {
return MaterialApp(home: home, debugShowCheckedModeBanner: false);
}
@override
Widget build(BuildContext context) {
return FlutterBoostApp(
routeFactory,
appBuilder: appBuilder,
initialRoute: "initialRoute",
);
}
}
void main() {
/// initialRoute test
testWidgets('initialRoute test', (tester) async {
await tester.pumpWidget(
MyApp(),
);
await tester.pump(const Duration(milliseconds: 10));
expect(find.text('initialRoute text'), findsOneWidget);
});
}
```
3. 执行命令
flutter test --no-sound-null-safety test/initial_route.dart
**Flutter Boost Version** v3.0-null-safety-release.1
**Target Platform:** macos
**Target OS version/browser:** macos
**Devices:** macos
## Logs
```
00:09 +0: initialRoute test
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building MyApp(state: _MyAppState#69dd5):
BoostFlutterBinding is not initialized,please refer to "class CustomFlutterBinding" in example
project
'package:flutter_boost/src/flutter_boost_app.dart':
Failed assertion: line 85 pos 9: 'BoostFlutterBinding.instance != null'
The relevant error-causing widget was:
MyApp file:///Users/frank/workspace/opensourcecode/flutter_boost/test/initial_route.dart:68:7
When the exception was thrown, this was the stack:
#2 FlutterBoostAppState.initState (package:flutter_boost/src/flutter_boost_app.dart:85:9)
#3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4632:57)
#4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4469:5)
... Normal element mounting (9 frames)
#13 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
#14 Element.updateChild (package:flutter/src/widgets/framework.dart:3303:20)
#15 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1182:16)
#16 RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1160:5)
#17 RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1174:7)
#18 Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
#19 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2694:33)
#20 AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1102:19)
#21 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#22 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
#23 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#24 AutomatedTestWidgetsFlutterBinding.pump. (package:flutter_test/src/binding.dart:969:9)
#27 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#28 AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:956:27)
#29 WidgetTester.pumpWidget. (package:flutter_test/src/widget_tester.dart:522:22)
#32 TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#33 WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:519:27)
#34 main. (file:///Users/frank/workspace/opensourcecode/flutter_boost/test/initial_route.dart:67:18)
#35 main. (file:///Users/frank/workspace/opensourcecode/flutter_boost/test/initial_route.dart:66:36)
#36 testWidgets.. (package:flutter_test/src/widget_tester.dart:144:29)
(elided 7 frames from class _AssertionError, dart:async, and package:stack_trace)
════════════════════════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _TextFinder:
Which: means none were found but one was expected
When the exception was thrown, this was the stack:
#4 main. (file:///Users/frank/workspace/opensourcecode/flutter_boost/test/initial_route.dart:71:5)
(elided one frame from package:stack_trace)
...
This was caught by the test expectation on the following line:
file:///Users/frank/workspace/opensourcecode/flutter_boost/test/initial_route.dart line 71
The test description was:
initialRoute test
════════════════════════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following message was thrown:
Multiple exceptions (2) were detected during the running of the current test, and at least one was
unexpected.
════════════════════════════════════════════════════════════════════════════════════════════════════
00:09 +0 -1: initialRoute test [E]
Test failed. See exception logs above.
The test description was: initialRoute test
00:09 +0 -1: Some tests failed.
```
```
[✓] Flutter (Channel stable, 2.0.6, on macOS 12.0.1 21A559 darwin-arm, locale zh-Hans-CN)
• Flutter version 2.0.6 at /Users/frank/fvm/versions/2.0.6
• Framework revision 1d9032c7e1 (11 个月前), 2021-04-29 17:37:58 -0700
• Engine revision 05e680e202
• Dart version 2.12.3
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc3)
• Android SDK at /Users/frank/Library/Android/sdk
• Platform android-31, build-tools 31.0.0-rc3
• ANDROID_HOME = /Users/frank/Library/Android/sdk
• Java binary at: bin/java
✗ Cannot execute bin/java to determine the version
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.3, Build version 13E113
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio (version 2021.1)
• Android Studio at /Applications/AndroidStudo.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
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[✓] IntelliJ IDEA Community Edition (version 2021.1.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.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.66.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.38.1
[✓] Connected device (3 available)
• ONEPLUS A3000 (mobile) • 375013eb • android-arm64 • Android 9 (API 28)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.0.1 21A559 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.75
! Error: ifphone is not connected. Xcode will continue when ifphone is connected. (code -13)
! Doctor found issues in 2 categories.
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with test/initial_route.dart and reproduce the failure using `flutter test --no-sound-null-safety test/initial_route.dart`. Read the BoostFlutterBinding assertion at src/flutter_boost_app.dart:85 and the referenced CustomFlutterBinding example. Done means the test initializes successfully and finds one widget containing “initialRoute text”.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile-dev, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100