url_launcher:^5.1.2在安卓模拟器上报错
来源:6-10 如何打开第三方应用?【你期待的技能】
蒋_a1990
2019-08-09
Performing hot restart…
Syncing files to device Android SDK built for x86…
Restarted application in 1,193ms.
I/flutter ( 3973): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 3973): The following assertion was thrown building LaunchPage(state: _LaunchPageState#6d945):
I/flutter ( 3973): MediaQuery.of() called with a context that does not contain a MediaQuery.
I/flutter ( 3973): No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of().
I/flutter ( 3973): This can happen because you do not have a WidgetsApp or MaterialApp widget (those widgets introduce
I/flutter ( 3973): a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.
I/flutter ( 3973): The context used was:
I/flutter ( 3973): Scaffold(dirty, state: ScaffoldState#1df0d(lifecycle state: initialized, tickers: tracking 2
I/flutter ( 3973): tickers))
I/flutter ( 3973):
I/flutter ( 3973): When the exception was thrown, this was the stack:
I/flutter ( 3973): #0 MediaQuery.of (package:flutter/src/widgets/media_query.dart:696:5)
I/flutter ( 3973): #1 ScaffoldState.didChangeDependencies (package:flutter/src/material/scaffold.dart:1842:50)
I/flutter ( 3973): #2 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4051:12)
I/flutter ( 3973): #3 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3902:5)
I/flutter ( 3973): #4 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3084:14)
I/flutter ( 3973): #5 Element.updateChild (package:flutter/src/widgets/framework.dart:2887:12)
I/flutter ( 3973): #6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3935:16)
I/flutter ( 3973): #7 Element.rebuild (package:flutter/src/widgets/framework.dart:3721:5)
I/flutter ( 3973): #8 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3907:5)
I/flutter ( 3973): #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4053:11)
I/flutter ( 3973): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3902:5)
I/flutter ( 3973): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3084:14)
I/flutter ( 3973): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2887:12)
I/flutter ( 3973): #13 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:939:16)
I/flutter ( 3973): #14 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:910:5)
I/flutter ( 3973): #15 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:856:17)
I/flutter ( 3973): #16 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2320:19)
I/flutter ( 3973): #17 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:855:13)
I/flutter ( 3973): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:736:7)
I/flutter ( 3973): #19 runApp (package:flutter/src/widgets/binding.dart:786:7)
I/flutter ( 3973): #20 main (package:flutter_app/main.dart:4:16)
I/flutter ( 3973): #21 _runMainZoned.. (dart:ui/hooks.dart:216:25)
I/flutter ( 3973): #26 _runMainZoned. (dart:ui/hooks.dart:208:5)
I/flutter ( 3973): #27 _startIsolate. (dart:isolate-patch/isolate_patch.dart:301:19)
I/flutter ( 3973): #28 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
I/flutter ( 3973): (elided 4 frames from package dart:async)
I/flutter ( 3973): ════════════════════════════════════════════════════════════════════════════════════════════════════
1回答
-
你的代码中是不是用到了MediaQuery,调用MediaQuery的地方要位于MaterialApp之下如:void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Title',
theme: kThemeData,
home: HomePage(),
);
}
}class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;return Container(
child: ...,
);
}
}012019-08-14
相似问题