Flutter Firebase - Checkbox is not enabled in SliverList

297 views
Skip to first unread message

flutter testing

unread,
Jun 15, 2019, 12:53:06 PM6/15/19
to Flutter Development (flutter-dev)
I'm reading fields carName, sportsCheckbox, familyCheckboxfrom firebase collection 'testcrud', and displaying in Listview. 

1) The output in the ListView looks like (Left Arrow, carName, SportCarCheckBox [], FamilyCarCheckbox[]>, Right Arrow)
The code should allow me to check or uncheck any checkbox but These are the issues I'm facing:
a) Either checkboxes are disabled
b) or all the checkBoxes in all the rows and columns are checked or unchecked 
 
Any help will be appreciable.
----------------------------

    import 'package:flutter/material.dart';
    import 'package:cloud_firestore/cloud_firestore.dart';
    final formKey = new GlobalKey<FormState>();
    String carName = '';
    void main() => runApp(MyApp());
    //====================================
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {return MaterialApp(home: TestListPage(),);}}
    //====================================
    class TestListPage extends StatefulWidget {
      @override
      _TestListPageState createState() => _TestListPageState();}
    //====================================
    class _TestListPageState extends State<TestListPage> {
      Stream<int> stream;
      @override
      Widget build(BuildContext context) {
        return Scaffold(appBar: AppBar(title: Text('Title Checkbox'),),
          body: TestListCustomScrollViewWidget(),);}
    //====================================
      Widget TestListCustomScrollViewWidget() {
        print ('.............................................');
        return CustomScrollView(scrollDirection: Axis.vertical, slivers: <Widget>[
          SliverAppBar(title: Text('Sliverlist')),
          Form(key: formKey, child: TestListStreamBuilderListWidget(),)]);}
    
      //================================
      Widget TestListStreamBuilderListWidget() {
        return    StreamBuilder(stream: Firestore.instance.collection('testcrud').orderBy('carName').snapshots(),
            builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
                 if(snapshot.hasData) {return SliverList(
                  delegate: SliverChildBuilderDelegate(
                        (context, index) => Container(child: TestListTileWidget(snapshot, index),),
                    childCount: snapshot.hasData ? snapshot.data.documents.length : 0,),);}});}
    
    //====================================
      Widget TestListTileWidget(snapshot, index){
    //    print('carName:' + snapshot.data.documents[index]['carName']);
        return ListTile(
          enabled: true, leading: Icon(Icons.arrow_back_ios), trailing: Icon(Icons.arrow_forward_ios,),
          title: new Row(
            children: <Widget>[
              new Expanded(child: new Text(snapshot.data.documents[index]['carName'])),
              _checkBox('Sports', snapshot.data.documents[index]['sportsCheckbox']),
              _checkBox('Family', snapshot.data.documents[index]['familyCheckbox']),],),);}
    //=======================================
      Widget _checkBox(String category, bool isChecked) {
        return Column(
          children: <Widget>[
            Text('$category',),
            Checkbox(value: isChecked,
              onChanged: (bool value) {setState(() {isChecked = value;});
                print('updated $category value to: $value');},)],);}
    //====================================
    } // End of Class

Muhd Fauzi

unread,
Jun 15, 2019, 6:14:11 PM6/15/19
to Flutter Development (flutter-dev)
I want this what app-release.apk i do not download
Reply all
Reply to author
Forward
0 new messages