flutter firestore无法从数据库获取数据

时间:2018-07-12 05:47:24

标签: firebase google-cloud-firestore flutter

我正试图从我的Firestore数据库中获取一些日期并将其放置在卡片视图中,但是数据没有出现。此时我完全被困住了

我的代码在这里

import "package:cloud_firestore/cloud_firestore.dart";
import 'package:flutter/material.dart';


class Feed extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        home: new Scaffold(
            appBar: new AppBar(
              // leading: new IconButton(icon: null, onPressed: null) , // to add hand  menu button
              title: const Text('extraextra'),
            ),
            body: new StreamBuilder(
                stream: Firestore.instance.collection("storys").snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> snapshot) {
                  if (!snapshot.hasData) return CircularProgressIndicator();
                 return FeedList(documents: snapshot.data.documents);
                })));
  } // build
} // feed StatelessWidget

class FeedList extends StatelessWidget {
  final List<DocumentSnapshot> documents;
  FeedList({this.documents});
  @override
  Widget build(BuildContext context) {
   return ListView.builder(
       itemBuilder:(BuildContext context, int index){
     String title = documents[index].data['Title'].toString();
     return Card(
       child: Column(
         children: <Widget>[
           ListTile(
             title: Text(title),
           )
         ],
       ),
     );
   } );
  }
}

输出:

enter image description here

我尝试了许多看起来可行的类似方法。好像是加载微调器来了,所以我已经在模拟器和我的个人设备上尝试过

更新控制台:

(31648): /data/app/com.google.android.gms-1/lib/arm/libconscrypt_gmscore_jni.so: unused DT entry: type 0xf arg 0x193
V/NativeCrypto(31648): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 280 native methods...
D/NetworkSecurityConfig(31648): No Network Security Config specified, using platform default
I/ProviderInstaller(31648): Installed default security provider GmsCore_OpenSSL
W/art     (31648): Before Android 4.1, method double java.util.concurrent.ThreadLocalRandom.internalNextDouble(double, double) would have incorrectly overridden the package-private method in java.util.Random
W/art     (31648): Before Android 4.1, method int java.util.concurrent.ThreadLocalRandom.internalNextInt(int, int) would have incorrectly overridden the package-private method in java.util.Random
W/art     (31648): Before Android 4.1, method long java.util.concurrent.ThreadLocalRandom.internalNextLong(long, long) would have incorrectly overridden the package-private method in java.util.Random
E/art     (31648): The String#value field is not present on Android versions >= 6.0
I/flutter (31648): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (31648): The following assertion was thrown during performLayout():
I/flutter (31648): 'package:flutter/src/widgets/text.dart': Failed assertion: line 213 pos 15: 'data != null': is not
I/flutter (31648): true.
I/flutter (31648): 
I/flutter (31648): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (31648): more information in this error message to help you determine and fix the underlying cause.
I/flutter (31648): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (31648):   https://github.com/flutter/flutter/issues/new
I/flutter (31648): 
I/flutter (31648): When the exception was thrown, this was the stack:
I/flutter (31648): #2      new Text (package:flutter/src/widgets/text.dart)
I/flutter (31648): #3      FeedList.build.<anonymous closure> (file:///C:/Users/zuriel/AndroidStudioProjects/extraextra/lib/Feed.dart:37:21)
I/flutter (31648): #4      SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:197:20)
I/flutter (31648): #5      SliverMultiBoxAdaptorElement._build.<anonymous closure> (package:flutter/src/widgets/sliver.dart:716:67)
I/flutter (31648): #6      _HashMap.putIfAbsent (dart:collection/runtime/libcollection_patch.dart:143:29)
I/flutter (31648): #7      SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:716:26)
I/flutter (31648): #8      SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:729:55)
I/flutter (31648): #9      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2222:19)
I/flutter (31648): #10     SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:722:11)
I/flutter (31648): #11     RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:254:23)
I/flutter (31648): #12     RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1666:58)
I/flutter (31648): #13     PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:740:15)
I/flutter (31648): #14     RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1666:13)
I/flutter (31648): #15     RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:243:5)
I/flutter (31648): #16     RenderSliverMultiBoxAdaptor.insertAndLayoutChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:381:5)
I/flutter (31648): #17     RenderSliverList.performLayout.advance (package:flutter/src/rendering/sliver_list.dart:190:19)
I/flutter (31648): #18     RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:233:19)
I/flutter (31648): #19     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #20     RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:182:11)
I/flutter (31648): #21     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #22     RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:336:13)
I/flutter (31648): #23     RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1172:12)
I/flutter (31648): #24     RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1090:20)
I/flutter (31648): #25     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #26     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (31648): #27     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #28     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (31648): #29     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #30     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (31648): #31     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #32     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (31648): #33     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #34     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (31648): #35     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #36     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (31648): #37     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #38     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (31648): #39     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #40     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:109:13)
I/flutter (31648): #41     RenderObject.layout (package:flutter/src/rendering/object.dart:1570:7)
I/flutter (31648): #42     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:141:11)
I/flutter (31648): #43     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:399:7)
I/flutter (31648): #44     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:211:7)
I/flutter (31648): #45     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:355:14)
I/flutter (31648): #46     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1445:7)
I/flutter (31648): #47     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:709:18)
I/flutter (31648): #48     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:270:19)
I/flutter (31648): #49     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:627:13)
I/flutter (31648): #50     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter (31648): #51     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (31648): #52     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (31648): #53     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (31648): #54     _invoke (dart:ui/hooks.dart:120:13)
I/flutter (31648): #55     _drawFrame (dart:ui/hooks.dart:109:3)
I/flutter (31648): (elided 2 frames from class _AssertionError)
I/flutter (31648): 
I/flutter (31648): The following RenderObject was being processed when the exception was fired:
I/flutter (31648):   RenderSliverList#50267 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (31648):   creator: SliverList ← MediaQuery ← SliverPadding ← Viewport ← _ScrollableScope ←
I/flutter (31648):   IgnorePointer-[GlobalKey#1626a] ← Semantics ← Listener ← _GestureSemantics ←
I/flutter (31648):   RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#fd3b0] ←
I/flutter (31648):   _ExcludableScrollSemantics-[GlobalKey#3b4e3] ← RepaintBoundary ← ⋯
I/flutter (31648):   parentData: paintOffset=Offset(0.0, 0.0) (can use size)
I/flutter (31648):   constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle,
I/flutter (31648):   scrollOffset: 0.0, remainingPaintExtent: 560.0, crossAxisExtent: 360.0, crossAxisDirection:
I/flutter (31648):   AxisDirection.right, viewportMainAxisExtent: 560.0, remainingCacheExtent: 810.0 cacheOrigin: 0.0 )
I/flutter (31648):   geometry: null
I/flutter (31648):   currently live children: 0 to 0
I/flutter (31648): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (31648):   RenderRepaintBoundary#7af48 relayoutBoundary=up3 NEEDS-PAINT
I/flutter (31648):     RenderSemanticsAnnotations#1b123 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (31648):       RenderPadding#f0d92 relayoutBoundary=up5 NEEDS-PAINT
I/flutter (31648):         RenderPhysicalShape#146f9 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (31648):           RenderCustomPaint#a1290 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (31648): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (31648): Another exception was thrown: NoSuchMethodError: The getter 'scrollOffsetCorrection' was called on null.
I/flutter (31648): Another exception was thrown: NoSuchMethodError: The method 'debugAssertIsValid' was called on null.
I/flutter (31648): Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.

1 个答案:

答案 0 :(得分:0)

如果您已正确设置Firebase凭证services.json文件,则需要检查获取快照是否有错误。最近,当我忘记添加Firestore规则以允许从集合中获取数据时,这发生在我身上。 它返回一个错误,指出访问被拒绝。

只需尝试一下

if (snapshot.hasError) { print(snapshot.error.toString()) }