dialogs.dart 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import 'package:appflowy_popover/popover.dart';
  2. import 'package:easy_localization/easy_localization.dart';
  3. import 'package:flowy_infra/text_style.dart';
  4. import 'package:flowy_infra/theme.dart';
  5. import 'package:flowy_infra_ui/style_widget/text.dart';
  6. import 'package:flowy_infra_ui/widget/buttons/primary_button.dart';
  7. import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart';
  8. import 'package:flowy_infra_ui/widget/spacing.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:provider/provider.dart';
  11. import 'package:app_flowy/startup/tasks/app_widget.dart';
  12. import 'package:flowy_infra/size.dart';
  13. import 'package:flowy_infra_ui/style_widget/text_input.dart';
  14. import 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
  15. import 'package:textstyle_extensions/textstyle_extensions.dart';
  16. export 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
  17. import 'package:app_flowy/generated/locale_keys.g.dart';
  18. class NavigatorTextFieldDialog extends StatefulWidget {
  19. final String value;
  20. final String title;
  21. final void Function()? cancel;
  22. final void Function(String) confirm;
  23. const NavigatorTextFieldDialog({
  24. required this.title,
  25. required this.value,
  26. required this.confirm,
  27. this.cancel,
  28. Key? key,
  29. }) : super(key: key);
  30. @override
  31. State<NavigatorTextFieldDialog> createState() => _CreateTextFieldDialog();
  32. }
  33. class _CreateTextFieldDialog extends State<NavigatorTextFieldDialog> {
  34. String newValue = "";
  35. @override
  36. void initState() {
  37. newValue = widget.value;
  38. super.initState();
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. final theme = context.watch<AppTheme>();
  43. return StyledDialog(
  44. child: Column(
  45. crossAxisAlignment: CrossAxisAlignment.start,
  46. children: <Widget>[
  47. ...[
  48. FlowyText.medium(widget.title, color: theme.shader4),
  49. VSpace(Insets.sm * 1.5),
  50. ],
  51. FlowyFormTextInput(
  52. hintText: LocaleKeys.dialogCreatePageNameHint.tr(),
  53. initialValue: widget.value,
  54. textStyle:
  55. const TextStyle(fontSize: 24, fontWeight: FontWeight.w400),
  56. autoFocus: true,
  57. onChanged: (text) {
  58. newValue = text;
  59. },
  60. onEditingComplete: () {
  61. widget.confirm(newValue);
  62. AppGlobals.nav.pop();
  63. },
  64. ),
  65. const VSpace(10),
  66. OkCancelButton(
  67. onOkPressed: () {
  68. widget.confirm(newValue);
  69. Navigator.of(context).pop();
  70. },
  71. onCancelPressed: () {
  72. if (widget.cancel != null) {
  73. widget.cancel!();
  74. }
  75. Navigator.of(context).pop();
  76. },
  77. )
  78. ],
  79. ),
  80. );
  81. }
  82. }
  83. class PopoverAlertView extends StatelessWidget {
  84. final PopoverMutex popoverMutex;
  85. final String title;
  86. final void Function()? cancel;
  87. final void Function()? confirm;
  88. const PopoverAlertView({
  89. required this.popoverMutex,
  90. required this.title,
  91. this.confirm,
  92. this.cancel,
  93. Key? key,
  94. }) : super(key: key);
  95. @override
  96. Widget build(BuildContext context) {
  97. final theme = context.watch<AppTheme>();
  98. return StyledDialog(
  99. child: Column(
  100. crossAxisAlignment: CrossAxisAlignment.start,
  101. mainAxisAlignment: MainAxisAlignment.center,
  102. children: <Widget>[
  103. ...[
  104. FlowyText.medium(title, color: theme.shader4),
  105. ],
  106. if (confirm != null) ...[
  107. const VSpace(20),
  108. OkCancelButton(
  109. onOkPressed: confirm,
  110. onCancelPressed: cancel,
  111. )
  112. ]
  113. ],
  114. ),
  115. );
  116. }
  117. }
  118. class NavigatorAlertDialog extends StatefulWidget {
  119. final String title;
  120. final void Function()? cancel;
  121. final void Function()? confirm;
  122. const NavigatorAlertDialog({
  123. required this.title,
  124. this.confirm,
  125. this.cancel,
  126. Key? key,
  127. }) : super(key: key);
  128. @override
  129. State<NavigatorAlertDialog> createState() => _CreateFlowyAlertDialog();
  130. }
  131. class _CreateFlowyAlertDialog extends State<NavigatorAlertDialog> {
  132. @override
  133. void initState() {
  134. super.initState();
  135. }
  136. @override
  137. Widget build(BuildContext context) {
  138. final theme = context.watch<AppTheme>();
  139. return StyledDialog(
  140. child: Column(
  141. crossAxisAlignment: CrossAxisAlignment.start,
  142. mainAxisAlignment: MainAxisAlignment.center,
  143. children: <Widget>[
  144. ...[
  145. FlowyText.medium(widget.title, color: theme.shader4),
  146. ],
  147. if (widget.confirm != null) ...[
  148. const VSpace(20),
  149. OkCancelButton(onOkPressed: () {
  150. widget.confirm?.call();
  151. Navigator.of(context).pop();
  152. }, onCancelPressed: () {
  153. widget.cancel?.call();
  154. Navigator.of(context).pop();
  155. })
  156. ]
  157. ],
  158. ),
  159. );
  160. }
  161. }
  162. class NavigatorOkCancelDialog extends StatelessWidget {
  163. final VoidCallback? onOkPressed;
  164. final VoidCallback? onCancelPressed;
  165. final String? okTitle;
  166. final String? cancelTitle;
  167. final String? title;
  168. final String message;
  169. final double? maxWidth;
  170. const NavigatorOkCancelDialog(
  171. {Key? key,
  172. this.onOkPressed,
  173. this.onCancelPressed,
  174. this.okTitle,
  175. this.cancelTitle,
  176. this.title,
  177. required this.message,
  178. this.maxWidth})
  179. : super(key: key);
  180. @override
  181. Widget build(BuildContext context) {
  182. final theme = context.watch<AppTheme>();
  183. return StyledDialog(
  184. maxWidth: maxWidth ?? 500,
  185. child: Column(
  186. crossAxisAlignment: CrossAxisAlignment.start,
  187. children: <Widget>[
  188. if (title != null) ...[
  189. FlowyText.medium(title!.toUpperCase(), color: theme.shader1),
  190. VSpace(Insets.sm * 1.5),
  191. Container(color: theme.bg1, height: 1),
  192. VSpace(Insets.m * 1.5),
  193. ],
  194. Text(message, style: TextStyles.Body1.textHeight(1.5)),
  195. SizedBox(height: Insets.l),
  196. OkCancelButton(
  197. onOkPressed: () {
  198. onOkPressed?.call();
  199. Navigator.of(context).pop();
  200. },
  201. onCancelPressed: () {
  202. onCancelPressed?.call();
  203. Navigator.of(context).pop();
  204. },
  205. okTitle: okTitle?.toUpperCase(),
  206. cancelTitle: cancelTitle?.toUpperCase(),
  207. )
  208. ],
  209. ),
  210. );
  211. }
  212. }
  213. class OkCancelButton extends StatelessWidget {
  214. final VoidCallback? onOkPressed;
  215. final VoidCallback? onCancelPressed;
  216. final String? okTitle;
  217. final String? cancelTitle;
  218. final double? minHeight;
  219. const OkCancelButton(
  220. {Key? key,
  221. this.onOkPressed,
  222. this.onCancelPressed,
  223. this.okTitle,
  224. this.cancelTitle,
  225. this.minHeight})
  226. : super(key: key);
  227. @override
  228. Widget build(BuildContext context) {
  229. return SizedBox(
  230. height: 48,
  231. child: Row(
  232. mainAxisAlignment: MainAxisAlignment.end,
  233. children: <Widget>[
  234. if (onCancelPressed != null)
  235. SecondaryTextButton(
  236. cancelTitle ?? LocaleKeys.button_Cancel.tr(),
  237. onPressed: onCancelPressed,
  238. bigMode: true,
  239. ),
  240. HSpace(Insets.m),
  241. if (onOkPressed != null)
  242. PrimaryTextButton(
  243. okTitle ?? LocaleKeys.button_OK.tr(),
  244. onPressed: onOkPressed,
  245. bigMode: true,
  246. ),
  247. ],
  248. ),
  249. );
  250. }
  251. }