Hey Could anyone help me please, i'm having this type of error while trying to parse a json file from the internet
The following NoSuchMethodError was thrown building: The method '[]' was called on null. Receiver: null Tried calling:
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1 ProductsListPage._buildProductsListPage.<anonymous closure>.<anonymous closure> (package:wildkard/components/Boutique.dart:65:46)
#2 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:455:22)
#3 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1201:28)
#4 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1214:55)
...
====================================================================================================
My code:
child: FutureBuilder<List<Product>>(
future: _parseProductsFromResponse(95),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.active:
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.none:
return Center(child: Text("Unable to connect right now"));
case ConnectionState.done:
return ListView.builder(
itemCount: 8,
itemBuilder: (context, index) {
if (index == 0) {
return _buildFilterWidgets(screenSize);
} else if (index == 7) {
return SizedBox(height: 12.0);
} else if (index % 2 == 0) {
return Container();
} else {
return ProductsListItem(
product1: snapshot.data[index - 1],
product2: snapshot.data[index],
);
}
},
);
}
},
Hey Could anyone help me please, i'm having this type of error while trying to parse a json file from the internet
The following NoSuchMethodError was thrown building: The method '[]' was called on null. Receiver: null Tried calling:
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1 ProductsListPage._buildProductsListPage.<anonymous closure>.<anonymous closure> (package:wildkard/components/Boutique.dart:65:46)
#2 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:455:22)
#3 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1201:28)
#4 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1214:55)
...
====================================================================================================
My code:
child: FutureBuilder<List<Product>>(
future: _parseProductsFromResponse(95),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.active:
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.none:
return Center(child: Text("Unable to connect right now"));
case ConnectionState.done:
return ListView.builder(
itemCount: 8,
itemBuilder: (context, index) {
if (index == 0) {
return _buildFilterWidgets(screenSize);
} else if (index == 7) {
return SizedBox(height: 12.0);
} else if (index % 2 == 0) {
return Container();
} else {
return ProductsListItem(
product1: snapshot.data[index - 1],
product2: snapshot.data[index],
);
}
},
);
}
},
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.