应用可以正确运行flutter run
对于flutter drive --target=test_driver/main.dart
,对dependentOnInheritedWidgetOfExactType的调用将返回null
一些相关代码:
class TimerServiceProvider extends InheritedWidget {
const TimerServiceProvider({Key key, this.service, Widget child})
: super(key: key, child: child);
final TimerService service;
@override
bool updateShouldNotify(TimerServiceProvider old) => service != old.service;
}
在MyApp中,小部件树以TimerServiceProvider开头
final timerService = TimerService();
@override
Widget build(BuildContext context) {
return TimerServiceProvider(
// provide timer service to all widgets of your app
service: timerService,
...
在其中一页上
timerService = TimerService.of(context);
在函数TimerService.of
中,dependOnInheritedWidgetOfExactType
返回null
。在正常的应用执行过程中,此方法工作正常,如果从flutter driver
运行,则返回null。
static TimerService of(BuildContext context) {
var provider =
context.dependOnInheritedWidgetOfExactType<TimerServiceProvider>();
return provider.service;
}
颤抖的医生
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.5, on Mac OS X 10.15.5 19F101, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.47.2)
[✓] Connected device (1 available)
• No issues found!