dialog_util.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import 'dart:math';
  2. import 'dart:ui';
  3. import 'package:confetti/confetti.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:photos/ui/loading_widget.dart';
  6. import 'package:photos/ui/progress_dialog.dart';
  7. ProgressDialog createProgressDialog(BuildContext context, String message) {
  8. final dialog = ProgressDialog(context,
  9. type: ProgressDialogType.Normal,
  10. isDismissible: false,
  11. barrierColor: Colors.black12);
  12. dialog.style(
  13. message: message,
  14. messageTextStyle: Theme.of(context).textTheme.caption,
  15. backgroundColor: Theme.of(context).dialogTheme.backgroundColor,
  16. progressWidget: loadWidget,
  17. borderRadius: 10,
  18. elevation: 10.0,
  19. insetAnimCurve: Curves.easeInOut,
  20. );
  21. return dialog;
  22. }
  23. Future<dynamic> showErrorDialog(
  24. BuildContext context, String title, String content) {
  25. AlertDialog alert = AlertDialog(
  26. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  27. title: Text(
  28. title,
  29. style: Theme.of(context).textTheme.headline6,
  30. ),
  31. content: Text(content),
  32. actions: [
  33. TextButton(
  34. child: Text(
  35. "Ok",
  36. style: TextStyle(
  37. color: Theme.of(context).colorScheme.onSurface,
  38. ),
  39. ),
  40. onPressed: () {
  41. Navigator.of(context, rootNavigator: true).pop('dialog');
  42. },
  43. ),
  44. ],
  45. );
  46. return showDialog(
  47. context: context,
  48. builder: (BuildContext context) {
  49. return BackdropFilter(
  50. filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
  51. child: alert,
  52. );
  53. },
  54. barrierColor: Colors.black12,
  55. );
  56. }
  57. Future<dynamic> showGenericErrorDialog(BuildContext context) {
  58. return showErrorDialog(context, "Something went wrong", "Please try again.");
  59. }
  60. Future<T> showConfettiDialog<T>({
  61. @required BuildContext context,
  62. WidgetBuilder builder,
  63. bool barrierDismissible = true,
  64. Color barrierColor,
  65. bool useSafeArea = true,
  66. bool useRootNavigator = true,
  67. RouteSettings routeSettings,
  68. Alignment confettiAlignment = Alignment.center,
  69. }) {
  70. final pageBuilder = Builder(
  71. builder: builder,
  72. );
  73. ConfettiController _confettiController =
  74. ConfettiController(duration: const Duration(seconds: 1));
  75. _confettiController.play();
  76. return showDialog(
  77. context: context,
  78. builder: (BuildContext buildContext) {
  79. return Stack(
  80. children: [
  81. pageBuilder,
  82. Align(
  83. alignment: confettiAlignment,
  84. child: ConfettiWidget(
  85. confettiController: _confettiController,
  86. blastDirection: pi / 2,
  87. emissionFrequency: 0,
  88. numberOfParticles: 100,
  89. // a lot of particles at once
  90. gravity: 1,
  91. blastDirectionality: BlastDirectionality.explosive,
  92. ),
  93. ),
  94. ],
  95. );
  96. },
  97. barrierDismissible: barrierDismissible,
  98. barrierColor: barrierColor,
  99. useSafeArea: useSafeArea,
  100. useRootNavigator: useRootNavigator,
  101. routeSettings: routeSettings,
  102. );
  103. }