gpt4 book ai didi

flutter - 如何使用Flutter将2个 float 操作按钮固定在某些特定位置?

转载 作者:行者123 更新时间:2023-12-03 04:20:23 25 4
gpt4 key购买 nike

我正在使用Flutter开发一个应用程序,并且希望在主屏幕上有2个FAB。我已经完成的BottomAppBar中的一个。

Scaffold(
appBard: AppBar(title: Text("My App")),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: ()=>{}
),
bottomNavigationBar: BottomAppBar(
color: Style.darkPrimaryColor,
shape: CircularNotchedRectangle(),
child: Container(
height: 50,
child: Row(
children: <Widget>[]
),
),
),
)
我想要第二个FAB定位并固定在屏幕的右下角,再加上居中的FAB,如下所示:
enter image description here
有什么方法可以实现?

最佳答案

我不认为使用脚手架有任何内置的方法,但是将堆栈用作脚手架主体应该很容易,因为您可以在任何位置添加 float 操作按钮。但是,如果有两个,则需要更改其中一个的hero标签,以避免在从该页面移入或移出该页面时出错。

Scaffold(
appBar: AppBar(title: Text("My App")),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: ()=>{}
),
bottomNavigationBar: BottomAppBar(
color: Style.darkPrimaryColor,
shape: CircularNotchedRectangle(),
child: Container(
height: 50,
child: Row(
children: <Widget>[]
),
),
),
body: Stack(
alignment: Alignment.bottomRight,
children: [
Container(
child: //Use this as if it were the body
),
//Setup the position however you like
Padding(
padding: const EdgeInsets.all(16.0),
child: FloatingActionButton(
heroTag: null, //Must be null to avoid hero animation errors
child: Icon(Icons.add),
onPressed: () => {},
),
),
],
),
)

关于flutter - 如何使用Flutter将2个 float 操作按钮固定在某些特定位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62996665/

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