• flutter 莫名其妙错误集锦


    1、回调函数的时候,报错:

    ════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
    The following NoSuchMethodError was thrown while handling a gesture:
    The method 'call' was called on null.
    Receiver: null
    Tried calling: call()
    
    When the exception was thrown, this was the stack: 
    #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
    #1      _BillAddPageState.build.<anonymous closure>.<anonymous closure> (package:flutter_bcd/pages/bill/bill_add_page.dart:139:19)
    #2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
    #3      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
    #4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
    ...
    Handler: "onTap"
    

      

           return InkWell(
                    onTap: () {
                      setState(() {
                        _selectedIndex = index;
                      });
                      print(_scaffoldKey);
                      // 调用 回调函数必须加括号
                      _showBottomSheetCallback();
                    },
                    child: Container(
                      alignment: Alignment.center,
                      padding: EdgeInsets.only(bottom: 10),
                      color: flag ? Colors.amber : Colors.transparent,
                      child: Column(
                        children: <Widget>[
                          Expanded(child: categoryList[index].icon),
                          Text(
                            categoryList[index].title,
                            style: TextStyle(
                              fontSize: 14,
                              color: Color(0xFF333333),
                            ),
                          ),
                        ],
                      ),
                    ));
    

      空指针这种错误,一般是自己的程序逻辑问题:

    解决方法就是判空:

    // 调用 回调函数必须加括号
    if (_showBottomSheetCallback != null) {
    _showBottomSheetCallback();
    }

    2、setState() or markNeedsBuild() called during build.

    onTap: () {
                        setState(() {
                          _selectedIndex = index;
                          print(_scaffoldKey);
                          // 调用 回调函数必须加括号
                          WidgetsBinding.instance.addPostFrameCallback((_){
                            // 通过addPostFrameCallback可以做一些安全的操作,在有些时候是很有用的,它会在当前Frame绘制完后进行回调,并只会回调一次,如果要再次监听需要再设置。
                            print("Frame has been rendered");
                            if (_showBottomSheetCallback != null) {
                              _showBottomSheetCallback();
                            }
                          });
    
                        });
    
                      },
    

      

    www.beicaiduo.com
  • 相关阅读:
    牛客-DongDong数颜色 及其相似题
    设置某个exe文件为启动项
    oracle nvl nvl2 decode
    oracle 查看表空间名称大小以及物理路径
    oracle cmd导入、导出dup文件
    div模拟弹框窗口
    token工具类
    转 nginx报502 bad GateWay错误的解决方法
    转 Nginx connect() failed (110: Connection timed out)
    转 Cannot assign requested address出现的原因及解决方案
  • 原文地址:https://www.cnblogs.com/hoge66/p/13286929.html
Copyright © 2020-2023  润新知