在我的程序中,我将从Cloud Firestore中提取值作为初始值,并希望它们在使用滑块的情况下对用户输入做出反应。但是,会抛出上述错误。我没有发布整个课程,因为它没有让我参加。只是保持它的要领。如果您需要更多信息,请告诉我。预先感谢!
这是我的代码:
class _ListPlusScreenState extends State<ListPlusScreen> {
@override
double _progress;
String _name;
Widget _BuildListItem(BuildContext context, DocumentSnapshot doc) {
_progress = doc['Progress'];
final _name = doc['Name'].toString();
final _due = doc['Due'];
final _priority = doc['Priority'];
DocumentReference _listRef =
Firestore.instance.collection("List Items").document();
return Container(
padding: EdgeInsets.all(15),
width: 200,
height: 600,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xffacb3b8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
_name,
style: TextStyle(fontSize: 20),
),
Checkbox(value: false, onChanged: null)
],
),
Slider(
value: _progress,
min: 0.0,
max: 100.0,
divisions: 10,
label: _progress.round().toString(),
onChanged: (value) {
setState(
() {
_progress = value;
_listRef.updateData({'Progress': value});
},
);
},
),
],
),
);
}
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: const Color(0xFF6EC6CA),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(20.0),
),
child: StreamBuilder(
stream: Firestore.instance.collection('List Items').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading..');
return ListView.builder(
itemExtent: 150,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) =>
_BuildListItem(context, snapshot.data.documents[index]),
);
}),
);
}
}
```
答案 0 :(得分:0)
double _progress =0.0;
label: _progress?.round().toString()??"0.0",
在代码中更改两行代码