如果我的應用程式中的狀態發生變化,我需要洗掉一個應用程式欄,并且我需要在頂部放置一個容器,以允許我使用自定義描述文本。我試圖在 appBar 之前放置一個條件陳述句,但它不允許我這樣做。還有其他選擇嗎?
return SafeArea(
child: Scaffold(
context.watch<UseData>().hideBar == false ? appBar:
AppBar(
// automaticallyImplyLeading: false,
title:
Text("Test", style: TextStyle(
color: Colors.black
)),
centerTitle: true,
bottomOpacity: 0,
elevation: 2,
backgroundColor: Colors.transparent,
iconTheme: IconThemeData(color: Colors.black),
) : Container(child: ...)),
Too many positional arguments: 0 expected, but 1 found. (Documentation) Try removing the extra positional arguments, or specifying the name for named arguments.
我也嘗試使用定位,但 top: 0 一直停留在 AppBar 下,我需要在應用欄上使用自定義容器。
Positioned(
top: 0,
child: Container(
child: Column(
children: [
Text("hi")
],
)
),
),

uj5u.com熱心網友回復:
appBar接受PreferredSizeWidget,因此您不能直接將Container小部件傳遞給它,而不僅僅是根據您的要求將您的Container 包裝到PreferredSize小部件height內部傳遞的preferredSize屬性中。檢查以下代碼以供參考:
return Scaffold(
appBar: isAppBar
? AppBar(
title: Text("Title Here"),
)
: PreferredSize(
preferredSize: Size.fromHeight(100.00),
child: Container(
child: Text("Second Title"),
),
),
);
uj5u.com熱心網友回復:
您可以PreferredSize在AppBar
return Scaffold(
appBar: PreferredSize(
child: context.watch<UseData>().hideBar == false
? AppBar(
// automaticallyImplyLeading: false,
title: Text("Test", style: TextStyle(color: Colors.black)),
centerTitle: true,
bottomOpacity: 0,
elevation: 2,
backgroundColor: Colors.transparent,
iconTheme: IconThemeData(color: Colors.black),
)
: Container(),
preferredSize: const Size.fromHeight(kToolbarHeight)),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/400741.html
標籤:扑
