FireBase, not able to display the records of a map in an array into a view

Viewed 39

I am passing the result of a snapshot into a map. On the first view, I am displaying in a ListView.builder each document of a collection. Each record is displayed into a Card. If the user is doing an onTap, I want to display the details of the previous view into a new view. But, right now, I can not find how do display each record into a list. In the map, I have two fields. item_Name => String and itemChecked => String itemChecked value is here to identify if the user have checked the box or not. If yes, that means that the user have bought the product in the list.

Below, you will find my code. Many thanks for your help. It is appreciated.

enter image description here

enter image description here

body: Column(
        children: [
          Container(
            height: MediaQuery.of(context).size.height /1.4,
            width: MediaQuery.of(context).size.width,
            child:StreamBuilder(
              stream: FirebaseFirestore.instance
                  .collection('Users')
                  .doc(FirebaseAuth.instance.currentUser.uid)
                  .collection('lists')
                  .snapshots(),
                  builder: (context, snapshot){
                
                QuerySnapshot data = snapshot.requireData;
                
                return ListView.builder(
                    itemCount: data.size,
                    itemBuilder: (context, index){
                    Map item = data.docs[index].data();

                    final allrecords = item['allItems'];
                    
                   /* print('items');
                    print (item);
                    print ('nbRecord');
                    print(item['allItems'].length.toString());*/
                    print('mon test');
                    print(item['allItems']);
                    print(allrecords);

                      return InkWell(
                        child: Card(
                            child: ListTile(
                              leading: Icon(Icons.skip_next_rounded),
                              title:Text((item['listName'])),
                              subtitle: Text(item['allItems'].length.toString())),
                            ),
                      onTap:(){
                              Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => DetailScreen_CheckList_V3(item),));
import 'package:flutter/material.dart';
import 'package:gtd_official_sharped_focused/Constante/Const.dart';
import 'package:gtd_official_sharped_focused/Views/Lists/checklist_V3/ElementOfAListCompletedProgressIndicator.dart';

var itemChecked;

class DetailScreen_CheckList_V3 extends StatefulWidget {
  final Map  listName;

  const DetailScreen_CheckList_V3(Map this.listName, {
      Key key}) : super(key: key);

 // DetailScreen_CheckList_V3({Key key,this.listName);

  @override
  _DetailScreen_CheckList_V3State createState() => _DetailScreen_CheckList_V3State(listName);
}

class _DetailScreen_CheckList_V3State extends State<DetailScreen_CheckList_V3> {
  Map listName;

  _DetailScreen_CheckList_V3State(
      this.listName
      );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:AppBar (
        title: Text('Your list items'),
        leading:
        InkWell(
          child:
          Icon(Icons.fast_rewind_outlined),
          onTap: (){
            Navigator.pop(context);
          },),

      ),
      body:
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 0.0, vertical: 8.0),
          child: Column(
            children: [
              Container(
                margin: EdgeInsets.symmetric(horizontal: 36.0, vertical: 0.0),
                height: 120,

                child:Container(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                   // Element_of_List_Badge(
                   //   color: _color,
                      //codePoint: _task.codePoint,
                      //id: _hero.codePointId,
                   // ),

                    Container(
                      margin: EdgeInsets.only(bottom: 10.0, top:24.0),
                      child: Hero(
                        tag: 'List Name',
                        //tag: _hero.remainingTaskId,
                        child: Text(
                          "N# of Items",
                          style: Theme.of(context)
                              .textTheme
                              .body1
                              ?.copyWith(color: Colors.grey[500]),
                        ),
                      ),
                    ),
                    Container(
                      height: 100,
                      child: ListView(
                        children:[

                          Hero(
                          tag: 'List Name', //_hero.titleId,
                          child: Text(listName['allItems'].toString(),
                              style: Theme.of(context)
                                  .textTheme
                                  .title
                                  ?.copyWith(color: Colors.black54)),
                        ),
                          ListTile(
                          leading: ConstrainedBox(
                            constraints: BoxConstraints(
                              minWidth: leadingIconMinSize,
                              minHeight: leadingIconMinSize,
                              maxWidth: leadingIconMaxSize,
                              maxHeight: leadingIconMaxSize,
                            ),

                            child: IconButton(
                                icon: itemChecked == "true" ? Icon(
                                  Icons.check_box,
                                  color: Colors.blue,) :
                                Icon(Icons.check_box_outline_blank,
                                  color: Colors.grey,),
                                onPressed: () {
                                  setState(() {
                                    if (itemChecked == 'true') {
                                      itemChecked = 'false';
                                    }
                                    else {
                                      itemChecked = 'true';
                                    }
                                  });
                                  //TODO coder pour que case à cocher devienne pleine
                                }), //InkWell(child: Icon(Icons.check_box_outline_blank),
                          )
                          )]),
                    ),
                    Spacer(),


                   /* ListView(
                      children: [
                        _getAllItems(),
                      ],
                    ),*/



                    Hero(
                      tag: 'hello66',
                     // tag: _hero.progressId,
                      child: ElementOfAListCompletedProgressIndicator(
                        color: Colors.red,
                        //progress: model.getTaskCompletionPercent(_task),
                      ),
                    )
                   /* Hero(
                      tag: 'List Name', //_hero.titleId,
                      child: Text(listName,//_task.name,
                          style: Theme.of(context)
                              .textTheme
                              .title
                              ?.copyWith(color: Colors.black54)),
                    ),*/
                  ],
                ),
                )),
            ],
          ),
        ),
      );

  }
 /* Widget _getAllItems()  {

    var snapshot =  FirebaseFirestore.instance
        .collection('currentUser')
        .doc('uid')
        .collection('lists')
        .doc(listName)
        .get();

    //return snapshot;


  }*/
}



enter image description here

enter image description here

1 Answers

It might be usefull to someone else, here is the solution

Container(
                    height: 550,
                    child: ListView.builder(
                        itemCount: listName['allItems'].length,
                        itemBuilder: (context, index){
                        Map allItems = listName;

                              return InkWell(
                              child: Card(
                              child: ListTile(
                              leading: Icon(Icons.skip_next_rounded),
                              title:
                                  Text((allItems['allItems'][index]['itemName'])),
                              onTap:(){},
                              ),

                         ));}),
                  )
Related