dialogs.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import 'package:easy_localization/easy_localization.dart';
  2. import 'package:flowy_infra/text_style.dart';
  3. import 'package:flowy_infra/theme.dart';
  4. import 'package:flowy_infra_ui/style_widget/text.dart';
  5. import 'package:flowy_infra_ui/widget/buttons/primary_button.dart';
  6. import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart';
  7. import 'package:flowy_infra_ui/widget/spacing.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:provider/provider.dart';
  10. import 'package:app_flowy/startup/tasks/app_widget.dart';
  11. import 'package:flowy_infra/size.dart';
  12. import 'package:flowy_infra_ui/style_widget/text_input.dart';
  13. import 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
  14. import 'package:textstyle_extensions/textstyle_extensions.dart';
  15. export 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
  16. import 'package:app_flowy/generated/locale_keys.g.dart';
  17. class NavigatorTextFieldDialog extends StatefulWidget {
  18. final String value;
  19. final String title;
  20. final void Function()? cancel;
  21. final void Function(String) confirm;
  22. const NavigatorTextFieldDialog({
  23. required this.title,
  24. required this.value,
  25. required this.confirm,
  26. this.cancel,
  27. Key? key,
  28. }) : super(key: key);
  29. @override
  30. State<NavigatorTextFieldDialog> createState() => _CreateTextFieldDialog();
  31. }
  32. class _CreateTextFieldDialog extends State<NavigatorTextFieldDialog> {
  33. String newValue = "";
  34. @override
  35. void initState() {
  36. newValue = widget.value;
  37. super.initState();
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. final theme = context.watch<AppTheme>();
  42. return StyledDialog(
  43. child: Column(
  44. crossAxisAlignment: CrossAxisAlignment.start,
  45. children: <Widget>[
  46. ...[
  47. FlowyText.medium(widget.title, color: theme.shader4),
  48. VSpace(Insets.sm * 1.5),
  49. ],
  50. FlowyFormTextInput(
  51. hintText: LocaleKeys.dialogCreatePageNameHint.tr(),
  52. initialValue: widget.value,
  53. textStyle:
  54. const TextStyle(fontSize: 24, fontWeight: FontWeight.w400),
  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. final theme = context.watch<AppTheme>();
  103. return StyledDialog(
  104. child: Column(
  105. crossAxisAlignment: CrossAxisAlignment.start,
  106. mainAxisAlignment: MainAxisAlignment.center,
  107. children: <Widget>[
  108. ...[
  109. FlowyText.medium(widget.title, color: theme.shader4),
  110. ],
  111. if (widget.confirm != null) ...[
  112. const VSpace(20),
  113. OkCancelButton(onOkPressed: () {
  114. widget.confirm?.call();
  115. Navigator.of(context).pop();
  116. }, onCancelPressed: () {
  117. widget.cancel?.call();
  118. Navigator.of(context).pop();
  119. })
  120. ]
  121. ],
  122. ),
  123. );
  124. }
  125. }
  126. class NavigatorOkCancelDialog extends StatelessWidget {
  127. final VoidCallback? onOkPressed;
  128. final VoidCallback? onCancelPressed;
  129. final String? okTitle;
  130. final String? cancelTitle;
  131. final String? title;
  132. final String message;
  133. final double? maxWidth;
  134. const NavigatorOkCancelDialog(
  135. {Key? key,
  136. this.onOkPressed,
  137. this.onCancelPressed,
  138. this.okTitle,
  139. this.cancelTitle,
  140. this.title,
  141. required this.message,
  142. this.maxWidth})
  143. : super(key: key);
  144. @override
  145. Widget build(BuildContext context) {
  146. final theme = context.watch<AppTheme>();
  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(), color: theme.shader1),
  154. VSpace(Insets.sm * 1.5),
  155. Container(color: theme.bg1, height: 1),
  156. VSpace(Insets.m * 1.5),
  157. ],
  158. Text(message, style: TextStyles.Body1.textHeight(1.5)),
  159. SizedBox(height: Insets.l),
  160. OkCancelButton(
  161. onOkPressed: () {
  162. onOkPressed?.call();
  163. Navigator.of(context).pop();
  164. },
  165. onCancelPressed: () {
  166. onCancelPressed?.call();
  167. Navigator.of(context).pop();
  168. },
  169. okTitle: okTitle?.toUpperCase(),
  170. cancelTitle: cancelTitle?.toUpperCase(),
  171. )
  172. ],
  173. ),
  174. );
  175. }
  176. }
  177. class OkCancelButton extends StatelessWidget {
  178. final VoidCallback? onOkPressed;
  179. final VoidCallback? onCancelPressed;
  180. final String? okTitle;
  181. final String? cancelTitle;
  182. final double? minHeight;
  183. const OkCancelButton(
  184. {Key? key,
  185. this.onOkPressed,
  186. this.onCancelPressed,
  187. this.okTitle,
  188. this.cancelTitle,
  189. this.minHeight})
  190. : super(key: key);
  191. @override
  192. Widget build(BuildContext context) {
  193. return SizedBox(
  194. height: 48,
  195. child: Row(
  196. mainAxisAlignment: MainAxisAlignment.end,
  197. children: <Widget>[
  198. if (onCancelPressed != null)
  199. SecondaryTextButton(
  200. cancelTitle ?? LocaleKeys.button_Cancel.tr(),
  201. onPressed: onCancelPressed,
  202. bigMode: true,
  203. ),
  204. HSpace(Insets.m),
  205. if (onOkPressed != null)
  206. PrimaryTextButton(
  207. okTitle ?? LocaleKeys.button_OK.tr(),
  208. onPressed: onOkPressed,
  209. bigMode: true,
  210. ),
  211. ],
  212. ),
  213. );
  214. }
  215. }