dialogs.dart 6.4 KB

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