所以我創建了一個服裝小部件,我想在一個列中顯示它,但是每當我把它放在一個列中并運行應用程式時,小部件就不會顯示在螢屏上。
這是我的服裝小工具
@override
Widget build(BuildContext context) {
return new FractionallySizedBox(
widthFactor: 1,
heightFactor: 0.3,
child: Container(
child: new LineChart(linechartData()),
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
),
);
}
這是我的 main.dart 小部件
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: new Text("hello"),
),
body: new Container(
child: new Column(
children: [
new Container(child: new Text("hello")),
new Chart()],
)),
),
);
}
}
我試圖通過從列小部件中洗掉我的服裝小部件并放置一個文本小部件來檢查問題是否與列小部件有關,但文本小部件顯示正常問題是當我在其中添加我的服裝小部件時,一切都消失了
uj5u.com熱心網友回復:
您需要將小部件包裝在Flexible其中,如下所示:
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: new Text("hello"),
),
body: new Container(
child: new Column(
children: [
new Flexible(child: Costume()),
new Chart()],
)),
),
);
}
}
查看FractionallySizedBox(本周 Flutter Widget)視頻
uj5u.com熱心網友回復:
您可以包裝FractionallySizedBoxwithExpanded以獲得可用的高度,然后heightFactor將使用它的孩子
body: Container(
child: Column(
children: [
Container(
child: new Text("hello"),
),
Expanded(
child: FractionallySizedBox(
widthFactor: 1,
heightFactor: 0.3,
child: Container(
),
),
)
],
),
),
你也可能感興趣LayoutBuilder
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/529297.html
標籤:扑镖颤振布局小部件
上一篇:AS3粒子爆炸
下一篇:如何使用WebView.platform=WebWebViewPlatform();和WebView.platform=AndroidWebView();在同一個dart檔案中
