dialogs.dart 6.4 KB

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