dialogs.dart 5.9 KB

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