dialogs.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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/application_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 TextFieldDialog extends StatefulWidget {
  18. final String value;
  19. final String title;
  20. final void Function()? cancel;
  21. final void Function(String) confirm;
  22. const TextFieldDialog({
  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<TextFieldDialog> createState() => _CreateTextFieldDialog();
  31. }
  32. class _CreateTextFieldDialog extends State<TextFieldDialog> {
  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: const TextStyle(fontSize: 24, fontWeight: FontWeight.w400),
  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. },
  68. onCancelPressed: () {
  69. if (widget.cancel != null) {
  70. widget.cancel!();
  71. }
  72. },
  73. )
  74. ],
  75. ),
  76. );
  77. }
  78. }
  79. class FlowyAlertDialog extends StatefulWidget {
  80. final String title;
  81. final void Function()? cancel;
  82. final void Function()? confirm;
  83. const FlowyAlertDialog({
  84. required this.title,
  85. this.confirm,
  86. this.cancel,
  87. Key? key,
  88. }) : super(key: key);
  89. @override
  90. State<FlowyAlertDialog> createState() => _CreateFlowyAlertDialog();
  91. }
  92. class _CreateFlowyAlertDialog extends State<FlowyAlertDialog> {
  93. @override
  94. void initState() {
  95. super.initState();
  96. }
  97. @override
  98. Widget build(BuildContext context) {
  99. final theme = context.watch<AppTheme>();
  100. return StyledDialog(
  101. child: Column(
  102. crossAxisAlignment: CrossAxisAlignment.start,
  103. mainAxisAlignment: MainAxisAlignment.center,
  104. children: <Widget>[
  105. ...[
  106. FlowyText.medium(widget.title, color: theme.shader4),
  107. ],
  108. if (widget.confirm != null) ...[
  109. const VSpace(20),
  110. OkCancelButton(
  111. onOkPressed: widget.confirm!,
  112. onCancelPressed: widget.confirm,
  113. )
  114. ]
  115. ],
  116. ),
  117. );
  118. }
  119. }
  120. class OkCancelDialog extends StatelessWidget {
  121. final VoidCallback? onOkPressed;
  122. final VoidCallback? onCancelPressed;
  123. final String? okTitle;
  124. final String? cancelTitle;
  125. final String? title;
  126. final String message;
  127. final double? maxWidth;
  128. const OkCancelDialog(
  129. {Key? key,
  130. this.onOkPressed,
  131. this.onCancelPressed,
  132. this.okTitle,
  133. this.cancelTitle,
  134. this.title,
  135. required this.message,
  136. this.maxWidth})
  137. : super(key: key);
  138. @override
  139. Widget build(BuildContext context) {
  140. final theme = context.watch<AppTheme>();
  141. return StyledDialog(
  142. maxWidth: maxWidth ?? 500,
  143. child: Column(
  144. crossAxisAlignment: CrossAxisAlignment.start,
  145. children: <Widget>[
  146. if (title != null) ...[
  147. Text(title!.toUpperCase(), style: TextStyles.T1.textColor(theme.shader1)),
  148. VSpace(Insets.sm * 1.5),
  149. Container(color: theme.bg1, height: 1),
  150. VSpace(Insets.m * 1.5),
  151. ],
  152. Text(message, style: TextStyles.Body1.textHeight(1.5)),
  153. SizedBox(height: Insets.l),
  154. OkCancelButton(
  155. onOkPressed: onOkPressed,
  156. onCancelPressed: onCancelPressed,
  157. okTitle: okTitle?.toUpperCase(),
  158. cancelTitle: cancelTitle?.toUpperCase(),
  159. )
  160. ],
  161. ),
  162. );
  163. }
  164. }
  165. class OkCancelButton extends StatelessWidget {
  166. final VoidCallback? onOkPressed;
  167. final VoidCallback? onCancelPressed;
  168. final String? okTitle;
  169. final String? cancelTitle;
  170. final double? minHeight;
  171. const OkCancelButton(
  172. {Key? key, this.onOkPressed, this.onCancelPressed, this.okTitle, this.cancelTitle, this.minHeight})
  173. : super(key: key);
  174. @override
  175. Widget build(BuildContext context) {
  176. return SizedBox(
  177. height: 48,
  178. child: Row(
  179. mainAxisAlignment: MainAxisAlignment.end,
  180. children: <Widget>[
  181. if (onCancelPressed != null)
  182. SecondaryTextButton(
  183. cancelTitle ?? LocaleKeys.button_Cancel.tr(),
  184. onPressed: () {
  185. onCancelPressed!();
  186. AppGlobals.nav.pop();
  187. },
  188. bigMode: true,
  189. ),
  190. HSpace(Insets.m),
  191. if (onOkPressed != null)
  192. PrimaryTextButton(
  193. okTitle ?? LocaleKeys.button_OK.tr(),
  194. onPressed: () {
  195. onOkPressed!();
  196. AppGlobals.nav.pop();
  197. },
  198. bigMode: true,
  199. ),
  200. ],
  201. ),
  202. );
  203. }
  204. }