Click here to Skip to main content
15,884,472 members

Comments by ago2486 (Top 8 by date)

ago2486 4-Oct-22 11:19am View    
//import 'dart:html';
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';

class pagePanier extends StatefulWidget {
const pagePanier({Key? key}) : super(key: key);

@override
State<pagepanier> createState() => _pagePanierState();
}

class _pagePanierState extends State<pagepanier> {
/*final CollectionReference _productRef =
FirebaseFirestore.instance.collection("Users");*/
/*final CollectionReference _productRef =
FirebaseFirestore.instance.collection("Produit");*/

final 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}"),
),
);
}
//collection Données prêtes à être affichées
if (snapshot.connectionState == ConnectionState.done) {
//Afficher les données dans une vue de liste
return ListView(
padding: EdgeInsets.only(
top: 108.0,
bottom: 12.0,
),
children: snapshot.data!.docs.map((document) {
return GestureDetector(
/*Click pour afficher l'image ou les info de l'image dans une autre page */
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PageProduit(
produitId: document.id,
),
),
);
},
child: FutureBuilder(
future:
_firebaseServices.productRef.doc(document.id).get(),
builder: (context,
AsyncSnapshot<documentsnapshot> productSnap) {
if (productSnap.hasError) {
return Container(
child: Center(
child: Text("${productSnap.error}"),
),
);
}

if (productSnap.connectionState ==
ConnectionState.done) {
/*Map _productmap=productSnap.data.data(); */
final _productMap = productSnap.data!;

return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
),
/*height: 350.0,*/
margin: EdgeInsets.symmetric(
vertical: 12.0,
horizontal: 24.0,
),
child: Container(
child: Text("${_productMap["nom"]}"),
),
/*child: Text("Nom: ${document['nom']}"),*/
ago2486 4-Oct-22 11:19am View    
I was able to find a solution with builder: (context,
AsyncSnapshot<documentsnapshot> productSnap)
and final _productMap = productSnap.data!;
it works but i need an explanation please.
ago2486 4-Oct-22 7:27am View    
understood sir I will check it and get back to you
ago2486 4-Oct-22 6:55am View    
https://stackoverflow.com/questions/68432119/error-the-method-data-isnt-defined-for-the-class-object
ago2486 4-Oct-22 6:54am View    
In one of my searches on the internet I came across:
The problem here is that by writing Map you are actually writing Map<dynamic, dynamic=""> which will remove important type information. I will recommend just using var or final and let Dart automatically assign the best possible type for the variable:

final _productMap = productSnap.data.data();

but its not working