构建FutureBuilder <List <Data >>(脏,状态:_FutureBuilderState <List <Data >>#d53db)时,引发了以下NoSuchMethodError。

时间:2020-08-12 09:50:45

标签: flutter dart

我似乎无法解决这个问题,所以如果有人可以帮助我,我有点被困住了!

import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as HTTP;
import 'package:flutter/material.dart';
import 'package:coding/Data.dart';


void main()=>
runApp(new MaterialApp(
  home: MyApp(),
  debugShowCheckedModeBanner: false,
));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
try {
  return Scaffold(
    appBar: AppBar(
      backgroundColor: Colors.transparent,
      actions: [new IconButton(icon: Icon(Icons.arrow_back_ios), onPressed: (){}),],
    ),
    body: ListView(
        children: <Widget>[
          new Container(
            height: 500.0,
            margin: EdgeInsets.all(7.0),
            child: new FutureBuilder(
              future: getAllData(),
              builder: (BuildContext c,AsyncSnapshot snapshot) {
                  return ListView.builder(
                    itemCount: snapshot.data.length,
                    itemBuilder: (BuildContext c,int index) {
                      return Card(
                        elevation: 10.0,
                        child: new Column(
                          children: <Widget>[
                            new Image.network(snapshot.data[index].link,
                              height: 150.0,
                              width: 150.0,
                              fit: BoxFit.cover,),
                          ],
                        ),
                      );
                    },);
              },
            ),
          ),
        ]
    ),
  );
}
catch (e){
}
}
}
Future<List<Data>> getAllData() async{
var api="https://www.awanmart.com/wp-json/wp/v2/categories";
var data=await http.get(api);

var jsonData=json.decode(data.body);
List<Data>listOf=[];

for(var i in jsonData){
Data data=new Data(i["id"],i ["count"], i["description"], i["link"], i["name"], i["slug"],I 
["taxonomy"], i["parent"],i ["meta"], i["_links"], i["self"], i["href"], i["collection"], 
i["about"], i["post_type"], i["curies"], i["templated"]);
}
return jsonData;
}

(这是我的Debugconsole)

═╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following NoSuchMethodError was thrown building FutureBuilder<List<Data>>(dirty, state:
_FutureBuilderState<List<Data>>#d53db): The getter 'length' was called on null. Receiver: null Tried calling: length

The relevant error-causing widget was:
  

 FutureBuilder<List<Data>> file:///D:/myappp/coding/lib/main.dart:32:28

When the exception was thrown, this was the stack:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      _MyAppState.build.<anonymous closure> (package:coding/main.dart:36:50)
#2      _FutureBuilderState.build (package:flutter/src/widgets/async.dart:740:55)
#3      StatefulElement.build (package:flutter/src/widgets/framework.dart:4663:28)
#4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4546:15)
#5      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
#6      Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
#7      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
#8      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4710:11)
#9      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5) ...     Normal element mounting (45 frames)
#54     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
#55     Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
#56     SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1164:36)
#57     SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1149:20)
#58     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2620:19)
#59     SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1142:11)
#60     RenderSliverMultiBoxAdaptor._createOrObtainChild d.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:356:23)
#61     RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1868:58)
#62     PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:920:15)
#63     RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1868:13)
#64     RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:345:5)
#65     RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:429:5)
#66     RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:81:12)
#67     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#68     RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:137:11)
#69     RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:377:11)
#70     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#71     RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:471:13)
#72     RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1465:12)
#73     RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1374:20)
#74     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#75     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#76     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#77     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#78     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#79     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#80     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#81     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#82     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#83     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#84     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#85     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#86     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#87     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#88     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#89     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#90     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#91     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#92     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#93     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:173:11)
#94     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:495:7)
#95     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:242:7)
#96     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:401:14)
#97     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#98     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#99     RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#100    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#101    _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1269:11)
#102    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#103    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#104    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#105    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#106    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#107    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#108    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#109    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#110    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#111    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#112    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#113    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#114    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#115    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#116    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#117    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#118    RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3228:13)
#119    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#120    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#121    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#122    _RenderTheatre.performLayout (package:flutter/src/widgets/overlay.dart:702:15)
#123    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#124    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#125    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#126    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#127    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#128    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#129    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#130    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#131    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#132    RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:115:13)
#133    RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#134    RenderView.performLayout (package:flutter/src/rendering/view.dart:170:13)
#135    RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1632:7)
#136    PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:889:18)
#137    RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:404:19)
#138    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:867:13)
#139    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
#140    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
#141    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1056:9)
#142    SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:865:7) (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)

═════════════════════════════════════════════════════════

1 个答案:

答案 0 :(得分:0)

据我所知,您不会检查# Note: This must be an executable or DLL compiled for .NET $Path = "D:\calc.exe" # Get Base64-encoded representation of the bytes that make up the assembly. $bytes = [System.IO.File]::ReadAllBytes($Path) $string = [System.Convert]::ToBase64String($bytes) # ... # Convert the Base64-encoded string back to a byte array, load # the byte array as an assembly, and save the object representing the # loaded assembly for later use. $bytes = [System.Convert]::FromBase64String($string) $assembly = [System.Reflection.Assembly]::Load($bytes) # Get the static method that is the executable's entry point. # Note: Assumes 'ConsoleApp' as the class name, and a static method named 'Main' as the entry point. $entryPointMethod = $assembly. GetType('ConsoleApp', [Reflection.BindingFlags] 'Public, NonPublic'). GetMethod('Main', [Reflection.BindingFlags] 'Static, Public, NonPublic') # Now you can call the entry point. # This example passes two arguments, 'foo' and 'bar' $entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar'))) 是否不是snapshot

null

应该看起来像这样:

builder: (BuildContext c,AsyncSnapshot snapshot) {
              return ListView.builder(
                itemCount: snapshot.data.length,
                itemBuilder: (BuildContext c,int index) {
                  return Card(
                    elevation: 10.0,