Я читаю carName, коллекцию firebase из carCheckbox и отображаю их в Listview. Флажок не включен в ListView.
1) Мой вывод в ListView выглядит следующим образом
<-, carName, SportCarCheckBox [], FamilyCarCheckbox [], ->
2) Вот вопросы, с которыми я сталкиваюсь:
а) Либо флажки отключены
б) или все флажки во всех строках и столбцах отмечены или не отмечены
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
Код должен позволять мне ставить или снимать любые флажки. Любая помощь будет заметна.