my_bill
my_bill copied to clipboard
跑不起了
最近在学习flutter,项目下载下来,跑不起了,启动页过后卡住了。
======== Exception caught by widgets library ======================================================= The following assertion was thrown building Builder(dirty, dependencies: [MediaQuery]): No MediaQuery widget ancestor found.
ScreenUtilInit widgets require a MediaQuery widget ancestor. The specific widget that could not find a MediaQuery ancestor was: ScreenUtilInit state: _ScreenUtilInitState#91dc1 The ownership chain for the affected widget is: "ScreenUtilInit ← Application ← [root]"
No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of(). This can happen because you have not added a WidgetsApp, CupertinoApp, or MaterialApp widget (those widgets introduce a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.
The relevant error-causing widget was:
Builder Builder:file:///E:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_screenutil-5.5.3+2/lib/src/screenutil_init.dart:128:16
When the exception was thrown, this was the stack:
#0 debugCheckHasMediaQuery. (package:flutter/src/widgets/debug.dart:246:7)
#1 debugCheckHasMediaQuery (package:flutter/src/widgets/debug.dart:261:4)
#2 MediaQuery.of (package:flutter/src/widgets/media_query.dart:908:12)
#3 Application.build. (package:my_bili/application.dart:49:30)
#4 _ScreenUtilInitState.child (package:flutter_screenutil/src/screenutil_init.dart:83:27)
#5 _ScreenUtilInitState.build. (package:flutter_screenutil/src/screenutil_init.dart:136:20)
#6 Builder.build (package:flutter/src/widgets/basic.dart:7371:48)
#7 StatelessElement.build (package:flutter/src/widgets/framework.dart:4876:49)
#8 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4806:15)
#9 Element.rebuild (package:flutter/src/widgets/framework.dart:4529:5)
#10 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4787:5)
#11 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4781:5)
... Normal element mounting (21 frames)
#32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3817:16)
#33 Element.updateChild (package:flutter/src/widgets/framework.dart:3551:18)
#34 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1202:16)
#35 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1171:5)
#36 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:1119:18)
#37 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2597:19)
#38 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1118:13)
#39 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:953:7)
#40 WidgetsBinding.scheduleAttachRootWidget. (package:flutter/src/widgets/binding.dart:933:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
在Application中移除MediaQuery这个试试
感觉不是MediaQuery 问题,应该是屏幕适配ScreenUtilInit的设置问题
我也是看ScreenUtilInit的issues有提到相关问题, MediaQuery 的位置不太正确,不过我这几个都没复现这个问题
ScreenUtilInit 里面的builder,参数好像是2个,项目中的是一个参数context
你可以参考ScreenUtilInit官网配置下,影响不大