I have same question as Show a snackbar after navigate in Flutter but for https://pub.dev/packages/flushbar
How can I show flushbar after navigation?
(In first route, when we navigate to second route, we have a background task, the task may fail, I want to show a message to end usee by flush bar, UI is in SecondRoute (or may be another route) and In FiratRout after (or before , no matter) navigation, background task runned and after a while may be failed
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
child: Text('Open route'),
onPressed: () async {
await Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
Flushbar(
title: "Hey Ninja",
message:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry",
duration: Duration(seconds: 3),
)..show(context);
},
),
),
);
}
}
class SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: Text(
"I want to show here Flushbar, Flushbar.show called in FirstRoute"),
),
);
}
}