You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The method '[]' was called on null.
Receiver: null
Tried calling: []("images")
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _MyOrderPageState.build.<anonymous closure>.<anonymous closure>
package:apps/order.dart:80
#2 SliverChildBuilderDelegate.build
package:flutter/…/widgets/sliver.dart:442
#3 SliverMultiBoxAdaptorElement._build.<anonymous closure>
package:flutter/…/widgets/sliver.dart:1153
#4 _HashMap.putIfAbsent (dart:collection-patch/collection_patch.dart:137:29)
Here is the code:-
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:woocommerce_api/woocommerce_api.dart';
class OrderPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyOrderPage(title: 'WooCommerce API Demo'),
);
}
}
class MyOrderPage extends StatefulWidget {
MyOrderPage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyOrderPageState createState() => _MyOrderPageState();
}
class _MyOrderPageState extends State<MyOrderPage> {
List<Widget> products = [];
Future getProducts() async {
/// Initialize the API
WooCommerceAPI wcApi = WooCommerceAPI(
"https://panahgah.com",
"*****************************************************",
"*****************************************************"
);
/// Get data using the endpoint
var p = await wcApi.getAsync("products");
return p;
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: FutureBuilder(
future: getProducts(),
builder: (_, s){
if(s.data == null){
return Container(
child: Center(
child: Text("Loading..."),
),
);
}
return ListView.builder(
itemCount: s.data.length,
itemBuilder: (_, index){
/// create a list of products
return ListTile(
leading: CircleAvatar(
child: Image.network(s.data[index]["images"][0]["src"]),
),
title: Text(s.data[index]["name"]),
subtitle: Text("Buy now for \$ " + s.data[index]["price"]),
);
}
);
},
),
);
}
}
My JSON is working fine. Here is the output from my website:-
Getting following error:-
Here is the code:-
My JSON is working fine. Here is the output from my website:-
P.S: I have hidden Consumer Key and Consumer Secret for this post
The text was updated successfully, but these errors were encountered: