gpt4 book ai didi

android - Flutter - 如何让 SnackBar 不向上插入 FloatingActionButton?

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

如何制作 Snackbar重叠FloatingActionButton弹出时不向上推?我附上了我的简化代码以供引用。先感谢您。

class Screen extends StatefulWidget{

@override
State<StatefulWidget> createState() => ScreenState();
}

class ScreenState extends State<Screen>{

BuildContext context;

@override
Widget build(BuildContext context) => Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: action,
),
body: Builder(
builder : (BuildContext context){
this.context = context;
return Container();
}
)
);

action() => Scaffold.of(context).showSnackBar(SnackBar(
duration: Duration(milliseconds : 1000),
content: Container(height: 10)
));
}

最佳答案

您可以设置behavior SnackBar 的属性(property)至SnackBarBehavior.floating这将显示 Snackbar高于其他小部件。

这应该这样做 -

class Screen extends StatefulWidget{

@override
State<StatefulWidget> createState() => ScreenState();
}

class ScreenState extends State<Screen>{

BuildContext context;

@override
Widget build(BuildContext context) => Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: action,
),
body: Builder(
builder : (BuildContext context){
this.context = context;
return Container();
}
)
);

action() => Scaffold.of(context).showSnackBar(SnackBar(
duration: Duration(milliseconds : 1000),
content: Container(height: 10)
behavior: SnackBarBehavior.floating, // Add this line
));
}

this链接以获取更多信息。

关于android - Flutter - 如何让 SnackBar 不向上插入 FloatingActionButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58830257/

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