dialogs.dart 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. 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 NavigatorTextFieldDialog extends StatefulWidget {
  18. final String value;
  19. final String title;
  20. final void Function()? cancel;
  21. final void Function(String) confirm;
  22. const NavigatorTextFieldDialog({
  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<NavigatorTextFieldDialog> createState() => _CreateTextFieldDialog();
  31. }
  32. class _CreateTextFieldDialog extends State<NavigatorTextFieldDialog> {
  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:
  54. const TextStyle(fontSize: 24, fontWeight: FontWeight.w400),
  55. autoFocus: true,
  56. onChanged: (text) {
  57. newValue = text;
  58. },
  59. onEditingComplete: () {
  60. widget.confirm(newValue);
  61. AppGlobals.nav.pop();
  62. },
  63. ),
  64. const VSpace(10),
  65. OkCancelButton(
  66. onOkPressed: () {
  67. widget.confirm(newValue);
  68. Navigator.of(context).pop();
  69. },
  70. onCancelPressed: () {
  71. if (widget.cancel != null) {
  72. widget.cancel!();
  73. }
  74. Navigator.of(context).pop();
  75. },
  76. )
  77. ],
  78. ),
  79. );
  80. }
  81. }
  82. class PopoverAlertView extends StatelessWidget {
  83. final String title;
  84. final void Function()? cancel;
  85. final void Function()? confirm;
  86. const PopoverAlertView({
  87. required this.title,
  88. this.confirm,
  89. this.cancel,
  90. Key? key,
  91. }) : super(key: key);
  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(title, color: theme.shader4),
  102. ],
  103. if (confirm != null) ...[
  104. const VSpace(20),
  105. OkCancelButton(
  106. onOkPressed: confirm,
  107. onCancelPressed: cancel,
  108. )
  109. ]
  110. ],
  111. ),
  112. );
  113. }
  114. }
  115. class NavigatorAlertDialog extends StatefulWidget {
  116. final String title;
  117. final void Function()? cancel;
  118. final void Function()? confirm;
  119. const NavigatorAlertDialog({
  120. required this.title,
  121. this.confirm,
  122. this.cancel,
  123. Key? key,
  124. }) : super(key: key);
  125. @override
  126. State<NavigatorAlertDialog> createState() => _CreateFlowyAlertDialog();
  127. }
  128. class _CreateFlowyAlertDialog extends State<NavigatorAlertDialog> {
  129. @override
  130. void initState() {
  131. super.initState();
  132. }
  133. @override
  134. Widget build(BuildContext context) {
  135. final theme = context.watch<AppTheme>();
  136. return StyledDialog(
  137. child: Column(
  138. crossAxisAlignment: CrossAxisAlignment.start,
  139. mainAxisAlignment: MainAxisAlignment.center,
  140. children: <Widget>[
  141. ...[
  142. FlowyText.medium(widget.title, color: theme.shader4),
  143. ],
  144. if (widget.confirm != null) ...[
  145. const VSpace(20),
  146. OkCancelButton(onOkPressed: () {
  147. widget.confirm?.call();
  148. Navigator.of(context).pop();
  149. }, onCancelPressed: () {
  150. widget.cancel?.call();
  151. Navigator.of(context).pop();
  152. })
  153. ]
  154. ],
  155. ),
  156. );
  157. }
  158. }
  159. class NavigatorOkCancelDialog extends StatelessWidget {
  160. final VoidCallback? onOkPressed;
  161. final VoidCallback? onCancelPressed;
  162. final String? okTitle;
  163. final String? cancelTitle;
  164. final String? title;
  165. final String message;
  166. final double? maxWidth;
  167. const NavigatorOkCancelDialog(
  168. {Key? key,
  169. this.onOkPressed,
  170. this.onCancelPressed,
  171. this.okTitle,
  172. this.cancelTitle,
  173. this.title,
  174. required this.message,
  175. this.maxWidth})
  176. : super(key: key);
  177. @override
  178. Widget build(BuildContext context) {
  179. final theme = context.watch<AppTheme>();
  180. return StyledDialog(
  181. maxWidth: maxWidth ?? 500,
  182. child: Column(
  183. crossAxisAlignment: CrossAxisAlignment.start,
  184. children: <Widget>[
  185. if (title != null) ...[
  186. FlowyText.medium(title!.toUpperCase(), color: theme.shader1),
  187. VSpace(Insets.sm * 1.5),
  188. Container(color: theme.bg1, height: 1),
  189. VSpace(Insets.m * 1.5),
  190. ],
  191. Text(message, style: TextStyles.Body1.textHeight(1.5)),
  192. SizedBox(height: Insets.l),
  193. OkCancelButton(
  194. onOkPressed: () {
  195. onOkPressed?.call();
  196. Navigator.of(context).pop();
  197. },
  198. onCancelPressed: () {
  199. onCancelPressed?.call();
  200. Navigator.of(context).pop();
  201. },
  202. okTitle: okTitle?.toUpperCase(),
  203. cancelTitle: cancelTitle?.toUpperCase(),
  204. )
  205. ],
  206. ),
  207. );
  208. }
  209. }
  210. class OkCancelButton extends StatelessWidget {
  211. final VoidCallback? onOkPressed;
  212. final VoidCallback? onCancelPressed;
  213. final String? okTitle;
  214. final String? cancelTitle;
  215. final double? minHeight;
  216. const OkCancelButton(
  217. {Key? key,
  218. this.onOkPressed,
  219. this.onCancelPressed,
  220. this.okTitle,
  221. this.cancelTitle,
  222. this.minHeight})
  223. : super(key: key);
  224. @override
  225. Widget build(BuildContext context) {
  226. return SizedBox(
  227. height: 48,
  228. child: Row(
  229. mainAxisAlignment: MainAxisAlignment.end,
  230. children: <Widget>[
  231. if (onCancelPressed != null)
  232. SecondaryTextButton(
  233. cancelTitle ?? LocaleKeys.button_Cancel.tr(),
  234. onPressed: onCancelPressed,
  235. bigMode: true,
  236. ),
  237. HSpace(Insets.m),
  238. if (onOkPressed != null)
  239. PrimaryTextButton(
  240. okTitle ?? LocaleKeys.button_OK.tr(),
  241. onPressed: onOkPressed,
  242. bigMode: true,
  243. ),
  244. ],
  245. ),
  246. );
  247. }
  248. }