Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

dart - extract the checked list form Flutter 's checkboxlistile using firestore as DB

hello I need to extract the list of the checked items in the checkboxlistile widget based on code below and print it in console.

for example I should get in this case a printable map{[clientA, False]; [clientF, True];[clientG, False]} or a list with selected items in the case [clientF]

enter image description here

thanks for your help

here is the code:

`

class ListClients5 extends StatefulWidget {

final String  title;

  const ListClients5({Key key, this.title}) : super(key: key);

  @override
  _ListClients5 createState() => _ListClients5();
}

class _ListClients5 extends State<ListClients5> {



@override
  Widget build (BuildContext context) {


return Scaffold(
    appBar:AppBar(
      title: Container(alignment: Alignment.centerLeft,child: Padding(
        padding: const EdgeInsets.all(0.0),
        child: Text("Horus  ${emailUser.split('@')[0].split('.')[0].toUpperCase()} ${emailUser.split('@')[0].split('.')[1].toUpperCase()}", textAlign: TextAlign.left,),
      )),
    ),
  body: FutureBuilder(
future: getList(),

      builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return CircularProgressIndicator();
        } else {
          return Center(
            child: ListView.builder(
                padding: const EdgeInsets.only(bottom: 20.0),
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                itemCount: snapshot.data.length,
                itemBuilder: (context, index) {
                  final item = snapshot.data[index].toString();




                  return Center(
                    child:Card(
                        elevation: 9,
                        child: Column(
                            children: <Widget>[
                              

                        Exercise(

                                                title:  snapshot.data[index]?.toString(),
                          
  
                  ),


                               //snapshot data should dispaly in this text field

                              ]
                  )
                  )
                  );

                }),
          );
        }
      },
    )

);

  }
  Future<List<dynamic>> getList() async {
    var firestore = Firestore.instance;

    DocumentReference docRef = firestore.collection('admin_users').document(idUser);

    // ignore: missing_return
    return docRef.get().then((datasnapshot) {
      if (datasnapshot.exists) {
        List<dynamic> info = datasnapshot.data['clients'].toList();
        print('#');
        print(info); //this line prints [aa, aghshs, fffg, fug, ghh, fggg, ghhh]
        print(info.length); //this line prints 7
        return info;
      }
    });
  }

}

class Exercise extends StatefulWidget {


  String title;
  int index;

  Exercise( {this.title, this.index});

  @override
  _ExerciseState createState() => _ExerciseState();

  }

class _ExerciseState extends State<Exercise> {

  bool selected = false;

  @override
  Widget build(BuildContext context) {

    return new CheckboxListTile(

      title: Text( widget.title ),

      value: selected,
      onChanged: (bool val) {
        setState( () {
          selected = val;

        } );
        ;
      },
    );

;

  }



}
`

the idea is that the selected list will allow me to query the right client

question from:https://stackoverflow.com/questions/65863761/extract-the-checked-list-form-flutter-s-checkboxlistile-using-firestore-as-db

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...