gpt4 book ai didi

flutter - Widget get _appBar 在 flutter 中的含义是什么

转载 作者:行者123 更新时间:2023-12-01 23:43:37 25 4
gpt4 key购买 nike

我正在阅读这样的 flutter 代码:

  Widget get _appBar {
return Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0x66000000), Colors.transparent],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: Container(
padding: EdgeInsets.fromLTRB(14, 20, 0, 0),
height: 86.0,
decoration: BoxDecoration(
color:
Color.fromARGB((appBarAlpha * 255).toInt(), 255, 255, 255),
boxShadow: [
BoxShadow(
color: appBarAlpha == 1.0
? Colors.black12
: Colors.transparent,
offset: Offset(2, 3),
blurRadius: 6,
spreadRadius: 0.6,
),
]),
child: SearchBar(
searchBarType: appBarAlpha > 0.2
? SearchBarType.homeLight
: SearchBarType.home,
inputBoxClick: _jumpToSearch,
defaultText: SEARCH_BAR_DEFAULT_TEXT,
leftButtonClick: () {},
speakClick: _jumpToSpeak,
rightButtonClick: _jumpToUser,
),
),
),
Container(
height: appBarAlpha > 0.2 ? 0.5 : 0,
decoration: BoxDecoration(
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 0.5)]))
],
);
}

Widget get _appBar是什么意思?它有一个 appBar 控件吗?为什么不直接返回一个 AppBar?

最佳答案

它是一个“getter”:

Getters and setters are special methods that provide read and write access to an object’s properties. Recall that each instance variable has an implicit getter, plus a setter if appropriate. You can create additional properties by implementing getters and setters, using the get and set keywords

( Dart Documentation )

所以 Widget get _appBar_appBar 类型的 Widget 属性的 getter。您可以将其设为函数:Widget _appBar()

我猜你的代码在多个地方使用了这个应用程序栏,所以找到了一种方法将代码放在一个地方以从所有其他地方调用它而不是复制所有代码。

关于flutter - Widget get _appBar 在 flutter 中的含义是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64649317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com