我陷入了闪屏飞溅的屏幕错误,如下所示:
E/flutter ( 5472): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The method 'findAncestorStateOfType' was called on null.
E/flutter ( 5472): Receiver: null
E/flutter ( 5472): Tried calling: findAncestorStateOfType<NavigatorState>()
E/flutter ( 5472): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 5472): #1 Navigator.of (package:flutter/src/widgets/navigator.dart:2185:40)
E/flutter ( 5472): #2 Navigator.push (package:flutter/src/widgets/navigator.dart:1801:22)
E/flutter ( 5472): #3 _SplashState.initState.<anonymous closure> (package:demo1/splash/splash.dart:19:25)
E/flutter ( 5472): #4 new Future.delayed.<anonymous closure> (dart:async/future.dart:325:39)
E/flutter ( 5472): #5 _rootRun (dart:async/zone.dart:1182:47)
E/flutter ( 5472): #6 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 5472): #7 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 5472): #8 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter ( 5472): #9 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 5472): #10 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 5472): #11 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter ( 5472): #12 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter ( 5472): #13 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter ( 5472): #14 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter ( 5472): #15 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
答案 0 :(得分:0)
您必须上传一些相关代码。 而且我认为您在构建之前已调用setState。 请在调用setState之前添加以下条件
if(this.mounted) {
setState((){});
}