dialog_util.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. void showErrorDialog(BuildContext context, String title, String content) {
  26. AlertDialog alert = AlertDialog(
  27. title: Text(title),
  28. content: Text(content),
  29. actions: [
  30. FlatButton(
  31. child: Text("ok"),
  32. onPressed: () {
  33. Navigator.of(context, rootNavigator: true).pop('dialog');
  34. },
  35. ),
  36. ],
  37. );
  38. showDialog(
  39. context: context,
  40. builder: (BuildContext context) {
  41. return alert;
  42. },
  43. barrierColor: Colors.black87,
  44. );
  45. }
  46. void showGenericErrorDialog(BuildContext context) {
  47. showErrorDialog(context, "something went wrong", "please try again.");
  48. }
  49. Future<T> showConfettiDialog<T>({
  50. @required BuildContext context,
  51. WidgetBuilder builder,
  52. bool barrierDismissible = true,
  53. Color barrierColor,
  54. bool useSafeArea = true,
  55. bool useRootNavigator = true,
  56. RouteSettings routeSettings,
  57. Alignment confettiAlignment = Alignment.center,
  58. }) {
  59. final pageBuilder = Builder(
  60. builder: builder,
  61. );
  62. ConfettiController _confettiController =
  63. ConfettiController(duration: const Duration(seconds: 1));
  64. _confettiController.play();
  65. return showDialog(
  66. context: context,
  67. builder: (BuildContext buildContext) {
  68. return Stack(
  69. children: [
  70. pageBuilder,
  71. Align(
  72. alignment: confettiAlignment,
  73. child: ConfettiWidget(
  74. confettiController: _confettiController,
  75. blastDirection: pi / 2,
  76. emissionFrequency: 0,
  77. numberOfParticles: 100, // a lot of particles at once
  78. gravity: 1,
  79. blastDirectionality: BlastDirectionality.explosive,
  80. ),
  81. ),
  82. ],
  83. );
  84. },
  85. barrierDismissible: barrierDismissible,
  86. barrierColor: barrierColor,
  87. useSafeArea: useSafeArea,
  88. useRootNavigator: useRootNavigator,
  89. routeSettings: routeSettings,
  90. );
  91. }