dialogs.dart 6.0 KB

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