我得到了“每個孩子都必須被布置一次”。以及以下代碼的“不正確使用 ParentDataWidget”。
我想底部面板對所有螢屏進行持久化。所以我創建了Base Widget。如果我不使用堆疊,它作業正常。我使用 Stack 是因為我的底部面板有圓角并且想讓角落透明。
所以現在底部面板是透明的,但出現了錯誤。
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Stack(
children: [
Positioned(
left: 0,
right: 0,
top: 0,
height: MediaQuery.of(context).size.height,
child: Expanded(
child: child,
),
),
const Positioned(
left: 0,
right: 0,
bottom: 0,
child: BottomPanel(),
),
],
),
);
}
}

uj5u.com熱心網友回復:
您不能Expanded在內部使用小部件positioned或stack小部件。您必須將該Expanded小部件包裝在 中Row,flex或者Column如果您想使用Expanded或嘗試另一種方式來完成此任務
使用 Expanded 小部件可以使 Row、Column 或 Flex 的子項擴展以填充沿主軸的可用空間(例如,水平用于行或垂直用于列)。如果擴展了多個子項,則根據彈性系數在它們之間分配可用空間。
uj5u.com熱心網友回復:
您應該使用 Positioned.fill 而不是 Positioned with Expanded 作為子項。像這樣做:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Stack(
children: [
Positioned.fll(
child: child, // if you want to specify this widget height add it here
),
const Positioned(
left: 0,
right: 0,
bottom: 0,
child: BottomPanel(),
),
],
),
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/340057.html
