showFlashDialog Navigator pop
callmejm opened this issue · comments
Hi, I cant use Navigator.pop(context)
inside context.showFlashDialog
content
Recommended use persistent
to false, reference resources; eg: context.showFlashDialog(persistent: false)
.
but I have to set persistent
to true, order to show on top of other widget, because I having other issue GeekyAnts/flick-video-player#125 , only showFlashDialog can on top of it
An alternative:
context.showFlashDialog(onWillPop: () => Future.value(false))
onWillPop
not firing
can the dialog support controller , so we can control dismiss anywhere ?
You can get the controller with a Completer
, eg:
Future<T?> showFlashDialog<T>({
......
required Completer<FlashController<T>> completer,
}) {
final controller = FlashController<T>(
this,
builder: (context, controller) {
return Container();
},
);
completer.complete(controller);
return controller.show();
}
Usage:
final completer = Completer<FlashController>();
showFlashDialog(completer: completer);
// dismiss the dialog.
await completer.future.dismiss();
static Future<dynamic> showBottomFlash({
bool persistent = true,
EdgeInsets margin = EdgeInsets.zero,
context,
@required String message,
IconData icon,
String title,
Completer<FlashController> completer,
}) {final controller = FlashController<Completer>(
context,
(context, controller) {
return Flash(
controller: controller,
margin: EdgeInsets.all(15),
position: FlashPosition.bottom,
borderRadius: BorderRadius.circular(0.0),
boxShadows: kElevationToShadow[8],
backgroundGradient: RadialGradient(
colors: [
Theme.of(context).primaryColorDark,
Theme.of(context).primaryColorDark,
],
center: Alignment.topLeft,
radius: 2,
),
onTap: () => controller.dismiss(),
forwardAnimationCurve: Curves.easeInCirc,
reverseAnimationCurve: Curves.bounceIn,
child: DefaultTextStyle(
style: TextStyle(color: Colors.white, fontSize: 13),
child: FlashBar(
message: Text(message),
shouldIconPulse: true,
icon: icon == null ? null : Icon(icon ?? Icons.info_outline, color: Colors.white),
primaryAction: TextButton(
onPressed: () => controller.dismiss(),
child: Text(
S.of(context).dismiss,
style: TextStyle(color: Colors.white, fontSize: 11),
),
),
),
),
);
},
duration: Duration(milliseconds: 2000),
);
completer.complete(controller);
return controller.show();}
Usage:
final completer = Completer<FlashController>();
.. call to Flash
await completer.future.dismiss();
Problem:
dismiss() is not defined here
I am using Flash version 1.3.1
@Insha-Siddiquii Try (await completer.future).dismiss();
.
@sososdk using this (await completer.future).dismiss();
Flash does not show up at all, which I believe dismiss calls immediately and await does not work.
can the dialog support controller , so we can control dismiss anywhere ?
@Insha-Siddiquii await completer.future
just get the FlashController
, and you can control dismiss anywhere.
@sososdk but how to dismiss it? the approach you have mentioned does not work.
(await completer.future).dismiss();
does not show up Flash at all, because here await does not work that at least first show Flash and then dismiss it.
& this below does not have dismiss()
defined
await completer.future.dismiss();
😕
You can get the controller with a
Completer
, eg:Future<T?> showFlashDialog<T>({ ...... required Completer<FlashController<T>> completer, }) { final controller = FlashController<T>( this, builder: (context, controller) { return Container(); }, ); completer.complete(controller); return controller.show(); }Usage:
final completer = Completer<FlashController>(); showFlashDialog(completer: completer); // dismiss the dialog. await completer.future.dismiss();
dont hv completer
only have dismissCompleter
@Insha-Siddiquii await completer.future.dismiss();
is a typo.
class _MyState extends State<MyPage> {
final completer = Completer<>(FlashController);
@override
Widget build(BuildContext context) {
return ElevatedButton(onPressed: () async {
// Add a custom content.
showBottomFlash(completer: completer, content: (context) {
return ElevatedButton(onPressed: () {
(await completer.future).dismiss();
});
});
// Don't dismiss flash dialog here. call it anywhere you want.
// (await completer.future).dismiss();
});
}
}
You can get the controller with a
Completer
, eg:Future<T?> showFlashDialog<T>({ ...... required Completer<FlashController<T>> completer, }) { final controller = FlashController<T>( this, builder: (context, controller) { return Container(); }, ); completer.complete(controller); return controller.show(); }Usage:
final completer = Completer<FlashController>(); showFlashDialog(completer: completer); // dismiss the dialog. await completer.future.dismiss();dont hv
completer
only havedismissCompleter
@callmejm you need custom it.
@sososdk yes we can dismiss it over any Elevated Button call but could not automate it like this for now. as it is not available:
await completer.future.dismiss();
I did a workaround for this:
await completer.future.timeout(Duration(milliseconds: 2100));
P.S: make sure the Duration of Flash itself should be lesser than the timeout duration
await completer.future.dismiss();
is a typo of(await completer.future).dismiss();
- Please create a new issue to describe your problems.