Flutter Exception :boolean expression must not be null

在as上运行flutter的时候,莫名其妙的报了个错误,如下:

Performing hot reload...
Syncing files to device Android SDK built for x86...

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building FadeDemo(dirty, state: _FadeDemoState#9c859):
Failed assertion: boolean expression must not be null


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

User-created ancestor of the error-causing widget was: 
  MaterialApp file:///E:/WorkSpace/Flutter/StudyDemo/flutter_study_demo/lib/main.dart:13:12
When the exception was thrown, this was the stack: 
#0      _FadeDemoState.build (package:flutter_study_demo/page/animal/fade_demo.dart:21:21)
#1      StatefulElement.build (package:flutter/src/widgets/framework.dart:4040:27)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3934:15)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:3731:5)
#4      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2341:33)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
Reloaded 3 of 550 libraries in 327ms.

这个错误来得很突然,查看我了代码,一个bool类型的参数未初始化.但是肉眼可见已经写了 true 了

import 'package:flutter/material.dart';

class FadeDemo extends StatefulWidget {
  @override
  _FadeDemoState createState() => _FadeDemoState();
}

class _FadeDemoState extends State<FadeDemo> {
  bool _visible = true;

  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("淡入淡出"),
      ),

      body: Center(
        child: AnimatedOpacity(
          opacity: _visible ? 1.0 : 0.0,
          duration: Duration(milliseconds: 500),
          child: Container(
            color: Colors.green,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.flip),
        onPressed: () {
          setState(() {
            _visible = !_visible;
          });
        },
      ),
    );
  }
}

.百思不得其解.

最终as重启后这个问题就被解决了

估计是as目前对flutter还不够友好

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值