dialogs.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. export 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
  15. import 'package:app_flowy/generated/locale_keys.g.dart';
  16. class NavigatorTextFieldDialog extends StatefulWidget {
  17. final String value;
  18. final String title;
  19. final void Function()? cancel;
  20. final void Function(String) confirm;
  21. const NavigatorTextFieldDialog({
  22. required this.title,
  23. required this.value,
  24. required this.confirm,
  25. this.cancel,
  26. Key? key,
  27. }) : super(key: key);
  28. @override
  29. State<NavigatorTextFieldDialog> createState() => _CreateTextFieldDialog();
  30. }
  31. class _CreateTextFieldDialog extends State<NavigatorTextFieldDialog> {
  32. String newValue = "";
  33. @override
  34. void initState() {
  35. newValue = widget.value;
  36. super.initState();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. final theme = context.watch<AppTheme>();
  41. return StyledDialog(
  42. child: Column(
  43. crossAxisAlignment: CrossAxisAlignment.start,
  44. children: <Widget>[
  45. ...[
  46. FlowyText.medium(widget.title, color: theme.shader4),
  47. VSpace(Insets.sm * 1.5),
  48. ],
  49. FlowyFormTextInput(
  50. hintText: LocaleKeys.dialogCreatePageNameHint.tr(),
  51. initialValue: widget.value,
  52. textStyle: TextStyles.general(
  53. fontSize: 24,
  54. fontWeight: FontWeight.w400,
  55. ),
  56. autoFocus: true,
  57. onChanged: (text) {
  58. newValue = text;
  59. },
  60. onEditingComplete: () {
  61. widget.confirm(newValue);
  62. AppGlobals.nav.pop();
  63. },
  64. ),
  65. const VSpace(10),
  66. OkCancelButton(
  67. onOkPressed: () {
  68. widget.confirm(newValue);
  69. Navigator.of(context).pop();
  70. },
  71. onCancelPressed: () {
  72. if (widget.cancel != null) {
  73. widget.cancel!();
  74. }
  75. Navigator.of(context).pop();
  76. },
  77. )
  78. ],
  79. ),
  80. );
  81. }
  82. }
  83. class NavigatorAlertDialog extends StatefulWidget {
  84. final String title;
  85. final void Function()? cancel;
  86. final void Function()? confirm;
  87. const NavigatorAlertDialog({
  88. required this.title,
  89. this.confirm,
  90. this.cancel,
  91. Key? key,
  92. }) : super(key: key);
  93. @override
  94. State<NavigatorAlertDialog> createState() => _CreateFlowyAlertDialog();
  95. }
  96. class _CreateFlowyAlertDialog extends State<NavigatorAlertDialog> {
  97. @override
  98. void initState() {
  99. super.initState();
  100. }
  101. @override
  102. Widget build(BuildContext context) {
  103. final theme = context.watch<AppTheme>();
  104. return StyledDialog(
  105. child: Column(
  106. crossAxisAlignment: CrossAxisAlignment.start,
  107. mainAxisAlignment: MainAxisAlignment.center,
  108. children: <Widget>[
  109. ...[
  110. FlowyText.medium(widget.title, color: theme.shader4),
  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. final theme = context.watch<AppTheme>();
  148. return StyledDialog(
  149. maxWidth: maxWidth ?? 500,
  150. child: Column(
  151. crossAxisAlignment: CrossAxisAlignment.start,
  152. children: <Widget>[
  153. if (title != null) ...[
  154. FlowyText.medium(title!.toUpperCase(), color: theme.shader1),
  155. VSpace(Insets.sm * 1.5),
  156. Container(color: theme.bg1, 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. }