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