dialog_util.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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: Theme.of(context).colorScheme.onSurface,
  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. }
  98. Widget test() {
  99. return Container(
  100. width: 355,
  101. height: 236,
  102. child: Row(
  103. mainAxisSize: MainAxisSize.min,
  104. mainAxisAlignment: MainAxisAlignment.center,
  105. crossAxisAlignment: CrossAxisAlignment.center,
  106. children: [
  107. Container(
  108. width: 355,
  109. height: 236,
  110. decoration: BoxDecoration(
  111. borderRadius: BorderRadius.circular(8),
  112. color: Color(0x4c000000),
  113. ),
  114. padding: const EdgeInsets.only(
  115. top: 20,
  116. bottom: 16,
  117. ),
  118. child: Column(
  119. mainAxisSize: MainAxisSize.min,
  120. mainAxisAlignment: MainAxisAlignment.end,
  121. crossAxisAlignment: CrossAxisAlignment.center,
  122. children: [
  123. SizedBox(
  124. width: 234,
  125. child: Text(
  126. "Are you sure you want to logout?",
  127. style: TextStyle(
  128. color: Colors.white,
  129. fontSize: 24,
  130. fontFamily: "SF Pro Display",
  131. fontWeight: FontWeight.w600,
  132. ),
  133. ),
  134. ),
  135. SizedBox(height: 16),
  136. Container(
  137. width: 323,
  138. height: 48,
  139. child: Row(
  140. mainAxisSize: MainAxisSize.min,
  141. mainAxisAlignment: MainAxisAlignment.center,
  142. crossAxisAlignment: CrossAxisAlignment.center,
  143. children: [
  144. Container(
  145. width: 323,
  146. height: 48,
  147. decoration: BoxDecoration(
  148. borderRadius: BorderRadius.circular(8),
  149. color: Color(0x4c000000),
  150. ),
  151. padding: const EdgeInsets.only(
  152. left: 135,
  153. right: 136,
  154. ),
  155. child: Row(
  156. mainAxisSize: MainAxisSize.min,
  157. mainAxisAlignment: MainAxisAlignment.center,
  158. crossAxisAlignment: CrossAxisAlignment.center,
  159. children: [
  160. Text(
  161. "Cancel",
  162. style: TextStyle(
  163. color: Colors.white,
  164. fontSize: 16,
  165. fontFamily: "SF Pro Text",
  166. fontWeight: FontWeight.w500,
  167. ),
  168. ),
  169. ],
  170. ),
  171. ),
  172. ],
  173. ),
  174. ),
  175. SizedBox(height: 16),
  176. Container(
  177. width: 323,
  178. height: 48,
  179. child: Row(
  180. mainAxisSize: MainAxisSize.min,
  181. mainAxisAlignment: MainAxisAlignment.center,
  182. crossAxisAlignment: CrossAxisAlignment.center,
  183. children: [
  184. Container(
  185. width: 323,
  186. height: 48,
  187. decoration: BoxDecoration(
  188. borderRadius: BorderRadius.circular(8),
  189. color: Colors.white,
  190. ),
  191. padding: const EdgeInsets.symmetric(
  192. horizontal: 120,
  193. vertical: 12,
  194. ),
  195. child: Row(
  196. mainAxisSize: MainAxisSize.min,
  197. mainAxisAlignment: MainAxisAlignment.center,
  198. crossAxisAlignment: CrossAxisAlignment.center,
  199. children: [
  200. Text(
  201. "Yes Logout",
  202. style: TextStyle(
  203. color: Colors.black,
  204. fontSize: 16,
  205. fontFamily: "SF Pro Text",
  206. fontWeight: FontWeight.w500,
  207. ),
  208. ),
  209. ],
  210. ),
  211. ),
  212. ],
  213. ),
  214. ),
  215. ],
  216. ),
  217. ),
  218. ],
  219. ),
  220. );
  221. }