Created
May 12, 2021 22:11
-
-
Save derekedelaney/0bd36b370daceaf56712a22bd097cdc8 to your computer and use it in GitHub Desktop.
Adds confetti to a flutter Dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:confetti/confetti.dart'; | |
Future<T> showConfettiDialog<T>({ | |
@required BuildContext context, | |
WidgetBuilder builder, | |
bool barrierDismissible = true, | |
Color barrierColor, | |
bool useSafeArea = true, | |
bool useRootNavigator = true, | |
RouteSettings routeSettings, | |
Alignment confettiAlignment = Alignment.center, | |
}) { | |
final pageBuilder = Builder( | |
builder: builder, | |
); | |
ConfettiController _confettiController = | |
ConfettiController(duration: const Duration(seconds: 2)); | |
_confettiController.play(); | |
return showDialog( | |
context: context, | |
builder: (BuildContext buildContext) { | |
return Stack( | |
children: [ | |
pageBuilder, | |
Align( | |
alignment: confettiAlignment, | |
child: ConfettiWidget( | |
confettiController: _confettiController, | |
blastDirectionality: BlastDirectionality.explosive, | |
emissionFrequency: 0.1, | |
), | |
), | |
], | |
); | |
}, | |
barrierDismissible: barrierDismissible, | |
barrierColor: barrierColor, | |
useSafeArea: useSafeArea, | |
useRootNavigator: useRootNavigator, | |
routeSettings: routeSettings, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice approach! Need to dispose
_confettiController
though.