PowerImageBinding()这句代码在runApp之前有问题,请问如何解决?
yougeyouge90 opened this issue · 2 comments
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/foundation/binding.dart': Failed assertion: line 55 pos 12: '!_debugInitialized': is not true.
E/flutter (17451): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
E/flutter (17451): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
E/flutter (17451): #2 new BindingBase (package:flutter/src/foundation/binding.dart:55:12)
E/flutter (17451): #3 new _WidgetsFlutterBinding&BindingBase&GestureBinding (package:flutter/src/widgets/binding.dart)
E/flutter (17451): #4 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding (package:flutter/src/widgets/binding.dart)
E/flutter (17451): #5 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding (package:flutter/src/widgets/binding.dart)
E/flutter (17451): #6 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding (package:flutter/src/widgets/binding.dart)
E/flutter (17451): #7 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding (package:flutter/src/widgets/binding.dart)
E/flutter (17451): #8 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding (package:flutter/src/widgets/binding.dart)
E/flutter (17451): #9 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding (package:flutter/src/widgets/binding.dart)
E/flutter (17451): #10 new WidgetsFlutterBinding (package:flutter/src/widgets/binding.dart)
E/flutter (17451): #11 new PowerImageBinding (package:power_image/src/common/power_image_binding.dart)
E/flutter (17451): #12 main (package:flutter_mogu/main.dart:58:3)
E/flutter (17451): #13 main (file:///D:/git_data/flutter_jinhua_news/.dart_tool/flutter_build/generated_main.dart:157:42)
E/flutter (17451): #14 _runMainZoned.. (dart:ui/hooks.dart:143:38)
E/flutter (17451): #15 _rootRun (dart:async/zone.dart:1428:13)
E/flutter (17451): #16 _CustomZone.run (dart:async/zone.dart:1328:19)
E/flutter (17451): #17 _runZoned (dart:async/zone.dart:1863:10)
E/flutter (17451): #18 runZonedGuarded (dart:async/zone.dart:1851:12)
E/flutter (17451): #19 _runMainZoned. (dart:ui/hooks.dart:141:5)
E/flutter (17451): #20 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:283:19)
我用的flutter版本是2.5.3
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/foundation/binding.dart': Failed assertion: line 55 pos 12: '!_debugInitialized': is not true. E/flutter (17451): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39) E/flutter (17451): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5) E/flutter (17451): #2 new BindingBase (package:flutter/src/foundation/binding.dart:55:12) E/flutter (17451): #3 new _WidgetsFlutterBinding&BindingBase&GestureBinding (package:flutter/src/widgets/binding.dart) E/flutter (17451): #4 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding (package:flutter/src/widgets/binding.dart) E/flutter (17451): #5 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding (package:flutter/src/widgets/binding.dart) E/flutter (17451): #6 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding (package:flutter/src/widgets/binding.dart) E/flutter (17451): #7 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding (package:flutter/src/widgets/binding.dart) E/flutter (17451): #8 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding (package:flutter/src/widgets/binding.dart) E/flutter (17451): #9 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding (package:flutter/src/widgets/binding.dart) E/flutter (17451): #10 new WidgetsFlutterBinding (package:flutter/src/widgets/binding.dart) E/flutter (17451): #11 new PowerImageBinding (package:power_image/src/common/power_image_binding.dart) E/flutter (17451): #12 main (package:flutter_mogu/main.dart:58:3) E/flutter (17451): #13 main (file:///D:/git_data/flutter_jinhua_news/.dart_tool/flutter_build/generated_main.dart:157:42) E/flutter (17451): #14 _runMainZoned.. (dart:ui/hooks.dart:143:38) E/flutter (17451): #15 _rootRun (dart:async/zone.dart:1428:13) E/flutter (17451): #16 _CustomZone.run (dart:async/zone.dart:1328:19) E/flutter (17451): #17 _runZoned (dart:async/zone.dart:1863:10) E/flutter (17451): #18 runZonedGuarded (dart:async/zone.dart:1851:12) E/flutter (17451): #19 _runMainZoned. (dart:ui/hooks.dart:141:5) E/flutter (17451): #20 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:283:19)
你项目里是不是集成了flutterboost? 或者看程序入口处是否重复创建了WidgetsFlutterBinding
因为flutterboost在程序入口处CustomFlutterBinding 再去创建PowerImageBinding()又会重复创建WidgetsFlutterBinding导致的报错
解决方法:
不需要调这一句PowerImageBinding(),只需要将imageCache替换的代码放进自定义的FlutterBinding里就好了
class CustomFlutterBinding extends WidgetsFlutterBinding with BoostFlutterBinding {
@OverRide
ImageCache createImageCache() { //powerImage 用 ImageCacheExt替换 ImageCache
return ImageCacheExt();
}
}