dialogs.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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(
  117. onOkPressed: () {
  118. widget.confirm?.call();
  119. Navigator.of(context).pop();
  120. },
  121. onCancelPressed: () {
  122. widget.cancel?.call();
  123. Navigator.of(context).pop();
  124. },
  125. )
  126. ]
  127. ],
  128. ),
  129. );
  130. }
  131. }
  132. class NavigatorOkCancelDialog extends StatelessWidget {
  133. final VoidCallback? onOkPressed;
  134. final VoidCallback? onCancelPressed;
  135. final String? okTitle;
  136. final String? cancelTitle;
  137. final String? title;
  138. final String message;
  139. final double? maxWidth;
  140. const NavigatorOkCancelDialog({
  141. Key? key,
  142. this.onOkPressed,
  143. this.onCancelPressed,
  144. this.okTitle,
  145. this.cancelTitle,
  146. this.title,
  147. required this.message,
  148. this.maxWidth,
  149. }) : super(key: key);
  150. @override
  151. Widget build(BuildContext context) {
  152. return StyledDialog(
  153. maxWidth: maxWidth ?? 500,
  154. child: Column(
  155. crossAxisAlignment: CrossAxisAlignment.start,
  156. children: <Widget>[
  157. if (title != null) ...[
  158. FlowyText.medium(
  159. title!.toUpperCase(),
  160. fontSize: FontSizes.s16,
  161. ),
  162. VSpace(Insets.sm * 1.5),
  163. Container(
  164. color: Theme.of(context).colorScheme.surfaceVariant,
  165. height: 1,
  166. ),
  167. VSpace(Insets.m * 1.5),
  168. ],
  169. FlowyText.medium(message),
  170. SizedBox(height: Insets.l),
  171. OkCancelButton(
  172. onOkPressed: () {
  173. onOkPressed?.call();
  174. Navigator.of(context).pop();
  175. },
  176. onCancelPressed: () {
  177. onCancelPressed?.call();
  178. Navigator.of(context).pop();
  179. },
  180. okTitle: okTitle?.toUpperCase(),
  181. cancelTitle: cancelTitle?.toUpperCase(),
  182. )
  183. ],
  184. ),
  185. );
  186. }
  187. }
  188. class OkCancelButton extends StatelessWidget {
  189. final VoidCallback? onOkPressed;
  190. final VoidCallback? onCancelPressed;
  191. final String? okTitle;
  192. final String? cancelTitle;
  193. final double? minHeight;
  194. const OkCancelButton({
  195. Key? key,
  196. this.onOkPressed,
  197. this.onCancelPressed,
  198. this.okTitle,
  199. this.cancelTitle,
  200. this.minHeight,
  201. }) : super(key: key);
  202. @override
  203. Widget build(BuildContext context) {
  204. return SizedBox(
  205. height: 48,
  206. child: Row(
  207. mainAxisAlignment: MainAxisAlignment.end,
  208. children: <Widget>[
  209. if (onCancelPressed != null)
  210. SecondaryTextButton(
  211. cancelTitle ?? LocaleKeys.button_Cancel.tr(),
  212. onPressed: onCancelPressed,
  213. bigMode: true,
  214. ),
  215. HSpace(Insets.m),
  216. if (onOkPressed != null)
  217. PrimaryTextButton(
  218. okTitle ?? LocaleKeys.button_OK.tr(),
  219. onPressed: onOkPressed,
  220. bigMode: true,
  221. ),
  222. ],
  223. ),
  224. );
  225. }
  226. }