Quote:
here's what the error says: The 'data' method cannot be invoked unconditionally because the receiver may be 'null'.
Try making the call conditional (using '?.') or adding a null check to the target
and here is the full code:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:djasse_application/ecran/page_produit.dart';
import 'package:djasse_application/services/firbase_services.dart';
import 'package:djasse_application/widget/custon_action_bar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/foundation/key.dart';
import 'package:flutter/src/widgets/framework.dart';
import '../constant.dart';
class pagePanier extends StatefulWidget {
const pagePanier({Key? key}) : super(key: key);
@override
State<pagePanier> createState() => _pagePanierState();
}
class _pagePanierState extends State<pagePanier> {
FirebaseServices _firebaseServices = FirebaseServices();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
FutureBuilder<QuerySnapshot>(
future: _firebaseServices.userRef
.doc(_firebaseServices.getUserId())
.collection("Panier")
.get(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Scaffold(
body: Center(
child: Text("Erreur: ${snapshot.error}"),
),
);
}
if (snapshot.connectionState == ConnectionState.done) {
return ListView(
padding: EdgeInsets.only(
top: 108.0,
bottom: 12.0,
),
children: snapshot.data!.docs.map((document) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PageProduit(
produitId: document.id,
),
),
);
},
child: FutureBuilder(
future:
_firebaseServices.productRef.doc(document.id).get(),
builder: (context, productSnap) {
if (productSnap.hasError) {
return Container(
child: Center(
child: Text("${productSnap.error}"),
),
);
}
if (productSnap.connectionState ==
ConnectionState.done) {
Map _productMap = productSnap.data.data();
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
),
margin: EdgeInsets.symmetric(
vertical: 12.0,
horizontal: 24.0,
),
child: Container(
child: Text("${_productMap['nom']}"),
),
);
}
},
),
);
}).toList(),
);
}
return const Scaffold(
body: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Color.fromARGB(255, 243, 159, 80)),
),
),
);
},
),
CustomActionBar(
title: "Panier",
hasBackArrow: true,
hasTitle: true,
hasBackground: false)
],
));
}
}