dialogs.dart 6.3 KB

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