在我用PreferredSize顫振包裹 appBar 子組件后,appBar 仍然無法正常作業并顯示:
The argument type 'Widget' can't be assigned to the parameter type 'PreferredSizeWidget?'.
這是我構建 flutter 頁面的 appBar 和 body 的代碼:
@override
Widget build(BuildContext context) {
return SafeArea(child: Scaffold(
appBar: _buildAppBar(context),
body:_buildBody(context),
));
}
這是_buildAppBar實作:
Widget _buildAppBar(BuildContext context) {
return PreferredSize(
child: Container(
padding: EdgeInsets.only(left: 8, right: 8, top: 0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ToolbarItemAlwaysOnTop(),
Expanded(child: Container()),
// ToolbarItemSponsor(),
ToolbarItemSettings(
onSettingsPageDismiss: () {
setState(() {});
},
),
],
),
),
preferredSize: Size.fromHeight(34),
);
}
我該怎么做才能讓它發揮作用?我已經閱讀了這個問題并建議擴展PreferredSizeWidget,我現在無法PreferredSizeWidget在我的代碼中實作(我已經嘗試過但不適用于這種情況)。
uj5u.com熱心網友回復:
更換的回傳型別_buildAppBar()從Widget到PreferredSize
你可以從PreferredSize課堂上查看
class PreferredSize extends StatelessWidget implements PreferredSizeWidget
uj5u.com熱心網友回復:
只需讓_buildAppBar(context) 函式的回傳型別回傳preferredSize
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/362201.html
標籤:扑
