dialogs.dart 5.8 KB

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