【问题标题】:Flutter: Is there a way to add a floating action button inside a container?Flutter:有没有办法在容器内添加浮动操作按钮?
【发布时间】:2020-10-22 06:14:59
【问题描述】:

有没有办法在容器内添加浮动操作按钮?或者至少达到类似的效果?

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Padding(
        child: Column(
          children: <Widget>[
            Text('Hello'),
            SizedBox(height: 30),
            Expanded(
              child: Container(
                child: TaskList(),
              ),
            )
          ],
        ),
      ),
    );
  }
}

附言。我不能使用脚手架有几个原因,所以不要建议。

【问题讨论】:

  • 当然。将浮动操作按钮添加为 Container 的子项。
  • @JohnJoe 不,我不能将 FAB 用作孩子。容器已经有一个孩子和多个孙子。
  • 由于 FAB 已经存在于 Flutter 材料的世界中,您需要提供小部件树的其他信息。
  • 这能回答你的问题吗? Flutter position fixed equivalent
  • @xlsra 我玩了一下。按预期工作。我使用堆栈,然后将 FAB 包裹在 align 中以使其与右下角对齐。谢谢!

标签: flutter dart


【解决方案1】:

是的,您可以利用Containerchild 属性

Container (
    child: FloatingActionButton()
)

【讨论】:

    猜你喜欢
    • 2019-03-06
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多