Floating Action Button pinned on every screen

Viewed 993

How can i have floating action button pinned on every screen? When i change the screen float action button on home screen gets dissapear. Is there any way for it?

Thanks

2 Answers

honestly i am not sure this is best way or not but ... you can Define a class like below and use it as parent of your widgets in every screen you want FAB,

class MyParent extends StatelessWidget {
  final Widget child;
  const MyParent({Key key, this.child}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        child,
        Positioned(
          bottom: 0,
          left: 0,
          child: FloatingActionButton(
            onPressed: (){},
          ),
        )
      ],
    );
  }
}

Here you can define all the floastingAction buttons like this

floatingActionButton:myFloatingActionButton()

And then in a new page create a widget like this

FloatingActionButton myFloatingActionButton({here you can add variables if you want a bit different things on every page}){
  return FloatingActionButton(
     child:Icon(Icons.add),//You can make any child,
     //Any customization like colors and all
     onPressed:(){}
);
}
Related