【问题标题】:How to create a floating button for attachments in flutter如何在颤动中为附件创建浮动按钮
【发布时间】:2019-01-28 04:42:19
【问题描述】:

如何在 Flutter 中创建一个浮动按钮并在其按钮按下时为不同的选项设置动画?我正在尝试制作如下内容:

当我尝试添加多个浮动按钮时,出现“argument for the name floating button action has already been specified”错误

    class MyBills extends StatelessWidget {
  MyBills({Key key}) : super(key: key);

  //@override
  //MyBillsPageState createState() => MyBillsPageState();
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: ListView.builder(
        itemCount: 20,
        itemBuilder: (context, index) {
          return new Container(height: 100, child: BillItem());
        }
      ),
      floatingActionButton: new FloatingActionButton(
        child: new Icon(Icons.add),
        heroTag: 1,
        onPressed: _addAttachment
      ),
      floatingActionButton: new FloatingActionButton(
        child: new Icon(Icons.camera),
        heroTag: 2,
        onPressed: _cameraAttachment
      ),
    );
  }

或动画浮动选项like this

【问题讨论】:

  • fab_dialer 是您想要的吗?这里还有a version,它不使用包。
  • 是的..明白了..!

标签: flutter flutter-layout


【解决方案1】:

给每个FloatingActionButton 一个唯一的heroTag 标签,你应该很高兴。

floatingActionButton: FloatingActionButton(
  heroTag: 0, // you can use any object here
),

您的解决方案:

@override
Widget build(BuildContext context) {
  return new Scaffold(
    body: Stack(
      alignment: Alignment.bottomRight,
      children: <Widget>[
        ListView.builder(
          itemCount: 20,
            itemBuilder: (context, index) {
              return new Container(height: 100, child: BillItem());
            }
        ),
        Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            new FloatingActionButton(child: new Icon(Icons.add), heroTag: 1, onPressed: _addAttachment),
            new FloatingActionButton(child: new Icon(Icons.camera), heroTag: 2, onPressed: _cameraAttachment),
          ],
        ),
      ],
    ),
  );
}

【讨论】:

  • 我给了不同的 heroTag ,但我仍然得到同样的错误。
  • 我对我的问题进行了编辑。看看我在哪里尝试添加浮点
  • 那行得通..但是我如何动画和显示不同的选项?其他浮动按钮应在视图初始加载时隐藏
  • @DeepakThakur 请作为一个单独的问题提出。并且不要忘记投票并接受这个答案。谢谢你:)
  • 但我的问题的最初部分是动画和仅显示浮动按钮
猜你喜欢
  • 1970-01-01
  • 2020-10-31
  • 2021-08-18
  • 2018-12-14
  • 2022-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-13
相关资源
最近更新 更多