【问题标题】:The getter 'isEmpty' was called on null - Camera flutter吸气剂“isEmpty”在 null 上被调用 - 相机颤动
【发布时间】:2019-12-04 08:30:01
【问题描述】:

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

错误:

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;
      });
    }
   .
   .
   .

【问题讨论】:

  • 能否请您发布整个代码,就像您调用 .isEmpty 的位置一样?
  • 谢谢,我解决了。
  • 这只是一些愚蠢的错误:)
  • 出错了,很高兴你解决了它。

标签: flutter dart


【解决方案1】:

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

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

isEmpaty 行添加了一些更改,以了解应用程序是否访问下一个屏幕。

变更前:

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

更改后:

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

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

【讨论】:

  • 也许是widget?.cameras?.isEmpty == true
猜你喜欢
  • 2020-10-30
  • 2021-03-24
  • 1970-01-01
  • 2021-06-22
  • 2021-08-05
  • 2021-04-02
  • 1970-01-01
  • 1970-01-01
  • 2020-10-28
相关资源
最近更新 更多