I am trying to call
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(\"Snack text\"),
));
inside onPressed
of fl
This is even simpler. Tried it. Create the FloatingActionButton as a separate Stateless Widget. Call this Stateless Widget from the Scaffold.
class Abc extends StatelessWidget
{
Widget build(BuildContext context)
{
return Scaffold(
appBar:AppBar(title:Text("Long List View")),
body:SomeOtherWidget(),
floatingActionButton:MyFAB()
);
}
}
class MyFAB extends StatelessWidget
{
Widget build(BuildContext context)
{
return FloatingActionButton(
onPressed:(){
showSnackBarHandler(context);
},
child:Icon(Icons.add),
tooltip:"Press to Add More"
);
}
}
void showSnackBarHandler(BuildContext context){
var snackBar = SnackBar(
content:Text("Hello")
);
Scaffold.of(context).showSnackBar(snackBar);
}