【问题标题】:Multiple floating buttons - Flutter多个浮动按钮 - Flutter
【发布时间】:2019-11-03 03:02:54
【问题描述】:

可以创建一个可以打开更多浮动按钮的浮动操作按钮,如果可以,你能给我举个例子吗?

像这些:

【问题讨论】:

标签: flutter flutter-layout


【解决方案1】:

Flutter 在 Scaffold Widget - 'floatingActionButton' 中提供了一个 named parameter。命名参数 floatingActionButton 不应该只采用 FloatingActionButton 小部件,它应该采用 Widget 并且确实如此。因此,您可以分配另一个小部件而不是 FloatingActionButton,例如 Column, Row, Stack。它有效。

floatingActionButton: Row(
  children: [
    RaisedButton(child: Text('Button1'), onPressed: (){}),
    RaisedButton(child: Text('Button1'), onPressed: (){}),
  ]
),

我只是给你一个参考例子,它会起作用 - 你只需要根据需要自定义样式和定位。希望对您有所帮助。

【讨论】:

  • 您需要将Row 包裹在SingleChildScrollView 中。
【解决方案2】:

使用 flutter_speed_dial 包提供的 SpeedDial 小部件,您可以使用多个浮动按钮作为父浮动操作按钮的子级。您还可以添加动画图标。

在依赖项下的 pubspec.yaml 中,添加:

dependencies:
 flutter_speed_dial: ^1.2.5

现在您可以在 FAB 中使用 SpeedDial 小部件:

floatingActionButton: SpeedDial(

//provide here features of your parent FAB

children: [
        SpeedDialChild(
          child: Icon(Icons.accessibility),
          label: 'First',
          onTap: null,),
        SpeedDialChild(
          child: Icon(Icons.accessibility),
          label: 'Second',
          onTap: null,),
        ...
 ]
),

【讨论】:

    【解决方案3】:

    试试这个

    floatingActionButton: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                FloatingActionButton(
                  onPressed: getImage,
                  child: Icon(Icons.camera),
                ),
                SizedBox(height: 8,),
                FloatingActionButton(
                  onPressed: getImage,
                  child: Icon(Icons.camera),
                ),
              ],
            )
    

    【讨论】:

      猜你喜欢
      • 2020-07-03
      • 2018-11-23
      • 2020-03-25
      • 2018-08-21
      • 1970-01-01
      • 2020-09-23
      • 2021-09-20
      • 2021-07-15
      • 2019-08-05
      相关资源
      最近更新 更多