# 错误集锦及规避方法
::: waring 写纵向或横向的布局的时候,一不小心就会遇到这个异常,宽度或高度溢出,导致 widget 不显示。 :::
# flutter Vertical viewport was given unbounded height
- Column 里面嵌套 Column、ListView、EasyRefresh 等空间具有无限延展性等控件,每一层都需要用 Expanded 包裹,漏掉一层都不行。
- 只要每层可无限延展的控件外面都套上 Expanded,允许他们最大值延展,那就没问题
# Horizontal viewport was given unbounded height
- 解决办法一:固定高度
body: Column(
children: <Widget>[
Text("aaaaaa"),
Container(
height: 200,
child: new ListView.builder(
itemCount: articleDatas.length,
itemBuilder: (BuildContext context, int position) {
if (position.isOdd) return new Divider();
return getRow(position);
}),
)
],
),
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- 解决办法二:shrinkWrap: true
- 给 ListView 的 shrinkWrap 属性设置为 true
- shrinkWrap: true 在 android 中有点像 wrap_content 的意思。
- 但是编译之后会发现页面底部会有超长的黄色警告。
- 解决办法三:Flexible
- Flexible 是 flutter 中的一个弹性布局,相当于 android 中的 LinearLayout。
- Flexible 中有一个 flex 属性,等于 layout_weight,把剩余空间全部占掉。
# The library 'package:flute_music_player/flute_music_player.dart' is legacy
# Your Flutter application is created using an older version of the Android embedding
# Converting object to an encodable object failed: Instance of 'xxx'
class JsonItem {
String title;
bool done;
JsonItem({required this.title, required this.done});
/// jsonDecode(jsonStr) 方法中会调用实体类的这个方法。如果实体类中没有这个方法,会报错。
toJson() {
Map<String, dynamic> m = {};
m['title'] = title;
m['done'] = done;
return m;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# [flutter_svg]The <style> element is not implemented in this library
- 解决方法是使用一个叫做svgcleaner清除一下多余的信息
- 调整svg文件,将
<style>中的颜色信息放到<path>中
<style type="text/css">
.st0{fill:#333333;}
</style>
<path class="st0" ……/>
1
2
3
4
2
3
4
调整为
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 1955.5 2178.9" style="enable-background:new 0 0 1955.5 2178.9;" xml:space="preserve">
<path fill="#e96a25" class="st0" ……/>
1
2
3
2
3
# _MySimpleHomeState#bc1f3(ticker active) was disposed with an active Ticker
_MySimpleHomeState created a Ticker via its SingleTickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. The Ticker must be disposed before calling super.dispose().
Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak.
# IntelliJ IDEA Ultimate Edition (the doctor check crashed)
flutter版本旧,跟不上新版本的idea