如何在长按中按住TextField来解决“找不到MediaQuery窗口小部件”

时间:2020-10-22 18:54:04

标签: flutter dart flutter-layout flutter-dependencies flutter-animation

我是新来的。我尝试实现#EasyLocalization,#MultiProvider和#FlutterEasyLoading来收集我的项目。我已经在MaterialApp之外放置了MultiProvider和flutterEasyLoading小部件,因此出现如下错误,

 _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#27e04](dirty, state:
I/flutter ( 2610): _OverlayEntryWidgetState#9d2ed):
I/flutter ( 2610): No MediaQuery widget found.
I/flutter ( 2610): _OverlayEntryWidget widgets require a MediaQuery widget ancestor.
I/flutter ( 2610): The specific widget that could not find a MediaQuery ancestor was:
I/flutter ( 2610):   _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#27e04]
I/flutter ( 2610): The ownership chain for the affected widget is:
I/flutter ( 2610):   "_OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#27e04] ← _Theatre ← Overlay ←
I/flutter ( 2610):   Directionality ← FlutterEasyLoading ← _InheritedProviderScope<FirebaseAnalyticsObserver> ←
I/flutter ( 2610):   Provider<FirebaseAnalyticsObserver> ← _NestedHook ← _InheritedProviderScope<FirebaseAnalytics> ←
I/flutter ( 2610):   Provider<FirebaseAnalytics> ← ⋯"
I/flutter ( 2610): Typically, the MediaQuery widget is introduced by the MaterialApp or WidgetsApp widget at the top of
I/flutter ( 2610): your application widget tree.
I/flutter ( 2610):

我的代码在下面,

void main() {
  runApp(
    EasyLocalization(
        supportedLocales: [
          Locale('en', ''),
          Locale('ar', ''),
        ],
        path: 'assets/translations',
        fallbackLocale: Locale('en', ''),
        child: MyApp()),
  );
  configLoading();     // This line you can comment (It's configure loader)

}
// in MyApp (Statefull widget)

MultiProvider(
      providers: [
        Provider<FirebaseAnalytics>.value(value: analytics),
        Provider<FirebaseAnalyticsObserver>.value(value: observer),
      ],
      child: FlutterEasyLoading(
        child: MaterialApp(
          debugShowCheckedModeBanner: false,
          title: App.app_name,
          theme: ThemeData(
            primarySwatch: Colors.blue,
            fontFamily: App.font_name,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          localizationsDelegates: context.localizationDelegates,
          supportedLocales: context.supportedLocales,
          locale: context.locale,
          navigatorObservers: <NavigatorObserver>[observer],
          home: SplashScreen(),
        ),
      )
    )

我已经尝试过的方法(#refered

     MaterialApp(
      debugShowCheckedModeBanner: false,
      title: App.app_name,
      theme: ThemeData(
        primarySwatch: Colors.blue,
        fontFamily: App.font_name,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      localizationsDelegates: context.localizationDelegates,
      supportedLocales: context.supportedLocales,
      locale: context.locale,
      navigatorObservers: <NavigatorObserver>[observer],
      home: SplashScreen(),
      builder: (BuildContext context, Widget child) {
        return MultiProvider(
            providers: [
              Provider<FirebaseAnalytics>.value(value: analytics),
              Provider<FirebaseAnalyticsObserver>.value(value: observer),
            ],
            child: FlutterEasyLoading(child: child)
        )

使用上述解决方案可以解决问题,但不适用于阿拉伯语从右到左的方向(用于本地化EasyLocalization)。所以,

如何解决使用聚会?

是否有其他解决方案,建议或严格的指导,以找到合适的解决方案?

提前谢谢!

0 个答案:

没有答案