0

How do create a floating button and animate different options on its button press in Flutter? I am trying to make something like below:

When I try to add multiple floating buttons, I get 'argument for the name floating button action has already been specified' error

    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
      ),
    );
  }

enter image description here or animate floating options like this

2
  • 1
    Is a fab_dialer what you're after? Here's also a version which doesn't use a package. Commented Jan 28, 2019 at 9:10
  • yes.. got it .. ! Commented Jan 28, 2019 at 9:14

1 Answer 1

3

Give every FloatingActionButton a unique heroTag tag, and you should be good to go.

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

Your solution:

@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),
          ],
        ),
      ],
    ),
  );
}
Sign up to request clarification or add additional context in comments.

7 Comments

I gave different heroTag , but I still get the same error.
I made an edit in my question. See where am I trying to add floating point
that worked.. but how do I animate and display different options? Other floating buttons should be hidden on initial load of the view
@DeepakThakur Kindly ask that as a separate question. And don't forget to upvote and accept this answer. Thank you :)
But the inital part of my question was to animate and display floating buttons only
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.