简体   繁体   English

错误:在 null 上调用了方法“round”。 接收方:null 尝试调用:round()。 构建小部件时抛出错误

[英]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.

相关问题 错误“在 null 上调用了方法 '[]'。 接收方:null 尝试调用:[](”0tm2JqPY0oNq5vSM74BqOufhGao1“)” - Error “The method '[]' was called on null. Receiver: null Tried calling: [](”0tm2JqPY0oNq5vSM74BqOufhGao1“)” 我正面临一个错误在 null 上调用了方法 '[]'。接收方:null 尝试调用:[]("postId") - I'm facing a error The method '[]' was called on null. Receiver: null Tried calling: []("postId") Flutter 问题:在 null 上调用了方法“[]”。 接收方:null 尝试调用:[](0),“错误” - Flutter Problem : The method '[]' was called on null. Receiver: null Tried calling: [](0) , “Error” 在 null 上调用了方法“[]”。 接收方:null 尝试调用:[](“color”) - The method '[]' was called on null. Receiver: null Tried calling: [](“color”) 在 null 上调用了方法“toDate”。 接收方:null 尝试调用:toDate() - The method 'toDate' was called on null. Receiver: null Tried calling: toDate() 在 null 上调用了方法“[]”。接收方:null 尝试调用:[]("displayName") - The method '[]' was called on null. Receiver: null Tried calling: []("displayName") 在 null 上调用了方法“toDate”。 Receiver: null 尝试调用: toDate() ,有没有解决这个错误的方法。 我是火力基地的新手 - The method 'toDate' was called on null. Receiver: null Tried calling: toDate() ,Is there any solution to get rod of this error. i am new to firebase NoSuchMethodError:在 null 上调用了方法“[]”。 接收器:null。 尝试调用:[](“名称”) - NoSuchMethodError: The method '[]' was called on null. Receiver: null. Tried calling: [](“name”) getter &#39;email&#39; 被调用为 null。 接收方:空尝试调用:电子邮件 - The getter 'email' was called on null. Receiver: null Tried calling: email 在 null 上调用了 getter 'data'。 接收方:null 尝试调用:数据 - The getter 'data' was called on null. Receiver: null Tried calling: data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM