【发布时间】:2020-10-01 15:56:44
【问题描述】:
如何在每个屏幕上固定浮动操作按钮?当我更改主屏幕上的屏幕浮动操作按钮时,会消失。有什么办法吗?
谢谢
【问题讨论】:
如何在每个屏幕上固定浮动操作按钮?当我更改主屏幕上的屏幕浮动操作按钮时,会消失。有什么办法吗?
谢谢
【问题讨论】:
老实说,我不确定这是否是最好的方法,但是... 您可以定义一个如下所示的类,并将其用作您想要 FAB 的每个屏幕中的小部件的父级,
class MyParent extends StatelessWidget {
final Widget child;
const MyParent({Key key, this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
child,
Positioned(
bottom: 0,
left: 0,
child: FloatingActionButton(
onPressed: (){},
),
)
],
);
}
}
【讨论】:
在这里你可以像这样定义所有的floastingAction按钮
floatingActionButton:myFloatingActionButton()
然后在一个新页面中创建一个像这样的小部件
FloatingActionButton myFloatingActionButton({here you can add variables if you want a bit different things on every page}){
return FloatingActionButton(
child:Icon(Icons.add),//You can make any child,
//Any customization like colors and all
onPressed:(){}
);
}
【讨论】: