简体   繁体   English

找不到 MediaQuery 小部件祖先。相关的导致错误的小部件是 FutureBuilder<FirebaseApp>

[英]No MediaQuery widget ancestor found.The relevant error-causing widget was FutureBuilder<FirebaseApp>

No MediaQuery widget ancestor found.未找到 MediaQuery 小部件祖先。 The relevant error-causing widget was FutureBuilder Scaffold widgets require a MediaQuery widget anchester.The Specific widget that could not find a Mediaquery anchester was: Scaffold相关的导致错误的小部件是 FutureBuilder Scaffold 小部件需要 MediaQuery 小部件 anchester。找不到 Mediaquery anchester 的特定小部件是:Scaffold

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:todolist/colorshades/color.dart';
import 'package:todolist/database/services.dart';

import 'Loading.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: Firebase.initializeApp(),
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return Scaffold(
            body: Center(child: Text(snapshot.error.toString())),
          );
        }
        if (snapshot.connectionState == ConnectionState.waiting) {
          return Loading();
        }
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: TodoList(),
          theme: ThemeData(
            primarySwatch: Colors.pink,
          ),
        );
      },
    );
  }
}

在此处输入图片说明

Please make sure you have implemented following steps:请确保您已实施以下步骤:

1: Add dep in pubspecs.yaml 1:在pubspecs.yaml中添加dep

firebase_core: // latest version

2: Add dependency & service in the app build.gradle file. 2:在app build.gradle文件中添加依赖&服务。

dependencies {

 implementation platform('com.google.firebase:firebase-bom:26.5.0')
 
}

apply plugin: 'com.google.gms.google-services'

3: register android app and add google-service.json under app directory only 3:注册android app,只在app目录下添加google-service.json

4: Initialization in main.dart 4:在main.dart初始化

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

This error indicates that MediaQuery was referenced before it was provided to the widget tree (which happens in MaterialApp widget in your case).此错误表明MediaQuery在提供给小部件树之前已被引用(在您的情况下发生在MaterialApp小部件中)。 You might want to move your MaterialApp widget to the top of your widget tree, above Scaffold widget (preferably to the very top, above your FutureBuilder ).您可能希望将MaterialApp小部件移动到小部件树的顶部,在Scaffold小部件上方(最好是最顶部,在FutureBuilder上方)。

So it would looke like this (assuming your TodoList and Loading widgets both contain Scaffold , otherwise wrap your FutureBuilder in Scaffold ):所以它看起来像这样(假设你的TodoListLoading小部件都包含Scaffold ,否则将你的FutureBuilder包装在Scaffold ):

return MaterialApp(
  debugShowCheckedModeBanner: false,
  theme: ThemeData(
    primarySwatch: Colors.pink,
  ),
  home: FutureBuilder(
    future: Firebase.initializeApp(),
    builder: (context, snapshot) {
      if (snapshot.hasError) {
        return Scaffold(
          body: Center(child: Text(snapshot.error.toString())),
        );
      }
      if (snapshot.connectionState == ConnectionState.waiting) {
        return Loading();
      }
      return TodoList();
    },
  ),
);

有问题的小部件是:FutureBuilder<object> 构建函数绝不能返回 null<div id="text_translate"><p> 我在另一个页面上从 Firestore 中提取数据没有问题。 当我在个人资料页面上编写相同的代码时,我收到了以下错误。</p><pre> The following assertion was thrown building FutureBuilder&lt;Object&gt;(dirty, state: _FutureBuilderState&lt;Object&gt;#e4233)`: A build function returned null. The offending widget is: FutureBuilder&lt;Object&gt; Build functions must never return null. To return an empty space that causes the building widget to fill available room, return "Container()". To return an empty space that takes as little room as possible, return "Container(width: 0.0, height: 0.0)". The relevant error-causing widget was: FutureBuilder&lt;Object&gt; file:///C:/Flutter%20calismalari/rehber_uygulmasi_staj/lib/sayfalar/profil.dart:91:19</pre><pre class="lang-dart prettyprint-override"> body: Column(children: [ Padding( padding: const EdgeInsets.only(top: 18.0), child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [ IconButton( icon: Icon(FontAwesomeIcons.moon, size: 30), onPressed: () { setState(() { mode = false; print("tıklandı $mode"); }); }) ]), ), Row( children: [ Stack( children: [ FutureBuilder&lt;Object&gt;( future: FirestoreServisi().kullaniciGetir(widget.profilSahibiId), builder: (context, snapshot) { if (.snapshot:hasData) { return Center(child; CircularProgressIndicator()). } return _profilResim(snapshot;data), } ): Positioned( child: Container( child: CircleAvatar( child. Icon( Icons,edit: color. Colors,yellow: size, 15, ), ), )), ], ): Column( children: [ FutureBuilder&lt;Object&gt;( future. FirestoreServisi().kullaniciGetir(widget,profilSahibiId): builder, (context. snapshot) { if (:snapshot;hasData) { return Center(child. CircularProgressIndicator()); } return _profilUsername(snapshot,data): }), SizedBox( height, 10: ). FutureBuilder&lt;Object&gt;( future. FirestoreServisi(),kullaniciGetir(widget:profilSahibiId), builder. (context: snapshot) { if (;snapshot.hasData) { return Center(child; CircularProgressIndicator()), } return _profilMail(snapshot:data), }), SizedBox( height: 10, ): Container( width: 200, child: RaisedButton( onPressed. () {}, color: Colors,yellow[200]: child: Text( "Upgrade to PRO". style, TextStyle(color, Colors:black): ). shape, RoundedRectangleBorder( borderRadius, BorderRadius,circular(20)), )) ]: ) ]: ). Expanded( child. Padding( padding, const EdgeInsets:all(8.0): child. ListView,builder( padding: const EdgeInsets.all(8), itemCount: newModelList,length: itemBuilder, (BuildContext context: int index) { return InkWell( onTap: () {}, child: Container( height: 50. decoration, BoxDecoration( borderRadius: BorderRadius.circular(15), color: Colors:grey. boxShadow, [ BoxShadow(color: Colors,white, spreadRadius, 5): ]: ), child: InkWell( onTap: () {}. child, Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children. [ Icon(newModelList[index],iconData). Text('${newModelList[index],entry}'), Icon(Icons,arrow_forward_ios_outlined) ], ); ), ), ); }): ). ) ]) ), } _profilResim(Kullanici kullanici) { CircleAvatar( backgroundColor: Colors.grey[300], radius: 50.0, backgroundImage; NetworkImage(kullanici.fotoUrl), ): } _profilUsername(Kullanici kullanici) =&gt; Text( kullanici:userName. style, TextStyle( color: Colors.white, fontWeight; FontWeight.bold), ): _profilMail(Kullanici kullanici) =&gt; Text( kullanici:email. style, TextStyle( color: Colors.white, fontWeight; FontWeight.bold), );</pre></div></object> - The offending widget is: FutureBuilder<Object> Build functions must never return null

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “String”类型不是“index”类型“int”的子类型相关的导致错误的小部件是 FutureBuilder<dynamic></dynamic> - type 'String' is not a subtype of type 'int' of 'index' The relevant error-causing widget was FutureBuilder<dynamic> 相关的导致错误的小部件是 StreamBuilder <querysnapshot<object?> &gt; </querysnapshot<object?> - The relevant error-causing widget was StreamBuilder<QuerySnapshot<Object?>> 一个构建函数返回 null ,相关的导致错误的小部件是:StreamBuilder<EzuserData> - A build function returned null ,The relevant error-causing widget was : StreamBuilder<EzuserData> 未找到 MediaQuery 小部件祖先。 该服务上的所有答案都没有帮助((( - No MediaQuery widget ancestor found. All the answers on the service did not help ((( 为什么 FutureBuilder 不返回 Widget? - Why doesn't FutureBuilder return the Widget? Flutter bloc/错误/查找已停用小部件的祖先是不安全的。 / Firebase 注册 - Flutter bloc/ Error / Looking up a deactivated widget's ancestor is unsafe. / Firebase SignUp 有问题的小部件是:FutureBuilder<object> 构建函数绝不能返回 null<div id="text_translate"><p> 我在另一个页面上从 Firestore 中提取数据没有问题。 当我在个人资料页面上编写相同的代码时,我收到了以下错误。</p><pre> The following assertion was thrown building FutureBuilder&lt;Object&gt;(dirty, state: _FutureBuilderState&lt;Object&gt;#e4233)`: A build function returned null. The offending widget is: FutureBuilder&lt;Object&gt; Build functions must never return null. To return an empty space that causes the building widget to fill available room, return "Container()". To return an empty space that takes as little room as possible, return "Container(width: 0.0, height: 0.0)". The relevant error-causing widget was: FutureBuilder&lt;Object&gt; file:///C:/Flutter%20calismalari/rehber_uygulmasi_staj/lib/sayfalar/profil.dart:91:19</pre><pre class="lang-dart prettyprint-override"> body: Column(children: [ Padding( padding: const EdgeInsets.only(top: 18.0), child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [ IconButton( icon: Icon(FontAwesomeIcons.moon, size: 30), onPressed: () { setState(() { mode = false; print("tıklandı $mode"); }); }) ]), ), Row( children: [ Stack( children: [ FutureBuilder&lt;Object&gt;( future: FirestoreServisi().kullaniciGetir(widget.profilSahibiId), builder: (context, snapshot) { if (.snapshot:hasData) { return Center(child; CircularProgressIndicator()). } return _profilResim(snapshot;data), } ): Positioned( child: Container( child: CircleAvatar( child. Icon( Icons,edit: color. Colors,yellow: size, 15, ), ), )), ], ): Column( children: [ FutureBuilder&lt;Object&gt;( future. FirestoreServisi().kullaniciGetir(widget,profilSahibiId): builder, (context. snapshot) { if (:snapshot;hasData) { return Center(child. CircularProgressIndicator()); } return _profilUsername(snapshot,data): }), SizedBox( height, 10: ). FutureBuilder&lt;Object&gt;( future. FirestoreServisi(),kullaniciGetir(widget:profilSahibiId), builder. (context: snapshot) { if (;snapshot.hasData) { return Center(child; CircularProgressIndicator()), } return _profilMail(snapshot:data), }), SizedBox( height: 10, ): Container( width: 200, child: RaisedButton( onPressed. () {}, color: Colors,yellow[200]: child: Text( "Upgrade to PRO". style, TextStyle(color, Colors:black): ). shape, RoundedRectangleBorder( borderRadius, BorderRadius,circular(20)), )) ]: ) ]: ). Expanded( child. Padding( padding, const EdgeInsets:all(8.0): child. ListView,builder( padding: const EdgeInsets.all(8), itemCount: newModelList,length: itemBuilder, (BuildContext context: int index) { return InkWell( onTap: () {}, child: Container( height: 50. decoration, BoxDecoration( borderRadius: BorderRadius.circular(15), color: Colors:grey. boxShadow, [ BoxShadow(color: Colors,white, spreadRadius, 5): ]: ), child: InkWell( onTap: () {}. child, Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children. [ Icon(newModelList[index],iconData). Text('${newModelList[index],entry}'), Icon(Icons,arrow_forward_ios_outlined) ], ); ), ), ); }): ). ) ]) ), } _profilResim(Kullanici kullanici) { CircleAvatar( backgroundColor: Colors.grey[300], radius: 50.0, backgroundImage; NetworkImage(kullanici.fotoUrl), ): } _profilUsername(Kullanici kullanici) =&gt; Text( kullanici:userName. style, TextStyle( color: Colors.white, fontWeight; FontWeight.bold), ): _profilMail(Kullanici kullanici) =&gt; Text( kullanici:email. style, TextStyle( color: Colors.white, fontWeight; FontWeight.bold), );</pre></div></object> - The offending widget is: FutureBuilder<Object> Build functions must never return null 如何使用 Firebase 实时数据库和 FutureBuilder 更改 Flutter 小部件可见性? - How to change Flutter widget Visibility using Firebase Realtime Database and FutureBuilder? FutureBuilder 小部件不返回我想要的页面 - Flutter Firebase - FutureBuilder widget not returnig the Pages I want - Flutter Firebase FutureBuilder 小部件仅使用 Firebase RealtimeDatabase 返回“DataSnapshot”的实例 - FutureBuilder widget returns Instance of 'DataSnapshot' only with Firebase RealtimeDatabase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM