dialog_util.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import 'dart:math';
  2. import 'package:confetti/confetti.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/widgets.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(
  9. context,
  10. type: ProgressDialogType.Normal,
  11. isDismissible: false,
  12. barrierColor: Colors.black.withOpacity(0.85),
  13. );
  14. dialog.style(
  15. message: message,
  16. messageTextStyle: TextStyle(color: Colors.white),
  17. backgroundColor: Color.fromRGBO(10, 15, 15, 1.0),
  18. progressWidget: loadWidget,
  19. borderRadius: 4.0,
  20. elevation: 10.0,
  21. insetAnimCurve: Curves.easeInOut,
  22. );
  23. return dialog;
  24. }
  25. Future<dynamic> showErrorDialog(
  26. BuildContext context, String title, String content) {
  27. AlertDialog alert = AlertDialog(
  28. title: Text(title),
  29. content: Text(content),
  30. actions: [
  31. TextButton(
  32. child: Text(
  33. "ok",
  34. style: TextStyle(
  35. color: Colors.white,
  36. ),
  37. ),
  38. onPressed: () {
  39. Navigator.of(context, rootNavigator: true).pop('dialog');
  40. },
  41. ),
  42. ],
  43. );
  44. return showDialog(
  45. context: context,
  46. builder: (BuildContext context) {
  47. return alert;
  48. },
  49. barrierColor: Colors.black87,
  50. );
  51. }
  52. Future<dynamic> showGenericErrorDialog(BuildContext context) {
  53. return showErrorDialog(context, "something went wrong", "please try again.");
  54. }
  55. Future<T> showConfettiDialog<T>({
  56. @required BuildContext context,
  57. WidgetBuilder builder,
  58. bool barrierDismissible = true,
  59. Color barrierColor,
  60. bool useSafeArea = true,
  61. bool useRootNavigator = true,
  62. RouteSettings routeSettings,
  63. Alignment confettiAlignment = Alignment.center,
  64. }) {
  65. final pageBuilder = Builder(
  66. builder: builder,
  67. );
  68. ConfettiController _confettiController =
  69. ConfettiController(duration: const Duration(seconds: 1));
  70. _confettiController.play();
  71. return showDialog(
  72. context: context,
  73. builder: (BuildContext buildContext) {
  74. return Stack(
  75. children: [
  76. pageBuilder,
  77. Align(
  78. alignment: confettiAlignment,
  79. child: ConfettiWidget(
  80. confettiController: _confettiController,
  81. blastDirection: pi / 2,
  82. emissionFrequency: 0,
  83. numberOfParticles: 100, // a lot of particles at once
  84. gravity: 1,
  85. blastDirectionality: BlastDirectionality.explosive,
  86. ),
  87. ),
  88. ],
  89. );
  90. },
  91. barrierDismissible: barrierDismissible,
  92. barrierColor: barrierColor,
  93. useSafeArea: useSafeArea,
  94. useRootNavigator: useRootNavigator,
  95. routeSettings: routeSettings,
  96. );
  97. }