Flutter-如何使SnackBar不向上推动FloatingActionButton?

问题描述 投票:0回答:1

如何使SnackbarFloatingActionButton重叠并在弹出时不向上推?我已附上我的简化代码以供参考。预先谢谢你。

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)
  ));
}
android flutter floating-action-button android-snackbar
1个回答
0
投票

您可以将behaviorSnackBar属性设置为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链接以获取更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.