在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还不够友好
版权声明:本文为Stromg_zzp原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。