[英]Error: The method 'round' was called on null. Receiver: null Tried calling: round(). Error thrown when building widget
In my program, I'm pulling values from cloud firestore as an initial value and want them to react on user input in case of the slider.在我的程序中,我从云 Firestore 中提取值作为初始值,并希望它们在 slider 的情况下对用户输入做出反应。 However, the aforementioned error gets thrown.
但是,会抛出上述错误。 I haven't posted the entire class as it didn't let me.
我没有发布整个 class 因为它没有让我发布。 Just kept it to the essentials.
只是保持它的必需品。 Do let me know if you require further information.
如果您需要更多信息,请告诉我。 Thanks in advance!
提前致谢!
Here's my code:这是我的代码:
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]),
);
}),
);
}
}
```
double _progress =0.0;
label: _progress?.round().toString()??"0.0",
Change two lines of code in your code更改代码中的两行代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.