flutter TabBarView 沒有跟Scaffold 一起使用的時候,容易報 Horizontal viewport was given unbounded height 錯誤,
例如將其作為Column的子元素,就會出現該錯誤。錯誤提示意思是水平視圖高是無限的,這里由於是用在Column中,
所以水平應該理解為垂直方向。解決該問題就是需要在其父級添加高度限制。
例如在其外層包裹Expanded,並設置flex。如下: Widget build(BuildContext context) { return Column( children: <Widget>[ header(),// 自定義組件 Expanded(// 設置高度。直接將TabBarView作為Column子元素,而不設置高度,會報錯 flex: 1, child: TabBarView(....),// 省略無關代碼 ), ], ); }
參考https://blog.csdn.net/supming1/article/details/104904937/