I'm building a barcode reader, which displays the name of the product after scanning its barcode. The names and the barcodes are stored in mongodb, I wrote this code for connecting to the data base:
Future<Map> prod() async {
Db db = Db('mongodb://192.168.2.5:27017/database');
await db.open();
DbCollection coll = db.collection('products');
var information = await coll.findOne(where.eq('code', _Barcode));
await db.close();
return information;
}
and I used future builder to display the name:
FutureBuilder(
future: prod(),
builder: (buildContext, AsyncSnapshot snapshot) {
if ( snapshot.data== null){
return Container(
child: Center(
child: Text("Loading..."),
),
);} else{
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (buildContext, int index) {
return Container(
child:snapshot.data.name,
);
});}
},)
It keeps showing loading text.