吸气剂“ isEmpty”在null上被调用-相机抖动

时间:2019-12-04 08:30:01

标签: flutter dart

当我尝试通过单击按钮打开相机时,出现此错误

错误:

The following NoSuchMethodError was thrown building CameraHomeScreen(dirty, state: _CameraHomeScreenState#5d87d):

The getter 'isEmpty' was called on null.

Receiver: null

Tried calling: isEmpty

而hrer是我的代码:

   .
   .
   .
List<CameraDescription> cameras;

    String _videoPath = null;

    Future _recordVideo() async {
      final videoPath = await Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: CameraHomeScreen(cameras)));
      setState(() {
        _videoPath = videoPath;
      });
    }
   .
   .
   .

1 个答案:

答案 0 :(得分:0)

我想给cameras赋任何值,只是给cameras赋一些值,效果很好。

顺便说一句:我是怎么发现这个错误的?

isEmpaty行中进行了一些更改,以了解应用程序是否可以访问下一屏幕。

更改前:

if (widget.cameras.isEmpty) {
    .
    .
    .
}

更改后:

if (widget?.cameras?.isEmpty ?? true) {
    .
    .
    .
}

我希望这个答案对某人有所帮助:)