我正在阅读carName,carCheckbox表单firebase集合,并显示在Listview中。列表视图中未启用复选框。
1)我在ListView中的输出看起来像 <-,carName,SportCarCheckBox [],FamilyCarCheckbox [],-> 2)这些是我面临的问题: a)任一复选框均被禁用 b)或选中所有行和列中的所有checkBox或取消选中
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
该代码应允许我选中或取消选中任何复选框。任何帮助都将是可贵的。