| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | import 'package:flowy_infra_ui/style_widget/text.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/widget/buttons/primary_button.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/widget/spacing.dart'; | 
					
						
							|  |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/startup/tasks/app_widget.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | import 'package:flowy_infra/size.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/style_widget/text_input.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart'; | 
					
						
							|  |  |  | export 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/generated/locale_keys.g.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  | class NavigatorTextFieldDialog extends StatefulWidget { | 
					
						
							|  |  |  |   const NavigatorTextFieldDialog({ | 
					
						
							| 
									
										
										
										
											2023-06-23 10:54:35 +08:00
										 |  |  |     super.key, | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |     required this.title, | 
					
						
							| 
									
										
										
										
											2023-06-23 10:54:35 +08:00
										 |  |  |     this.autoSelectAllText = false, | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |     required this.value, | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |     required this.confirm, | 
					
						
							|  |  |  |     this.cancel, | 
					
						
							| 
									
										
										
										
											2023-06-23 10:54:35 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   final String value; | 
					
						
							|  |  |  |   final String title; | 
					
						
							|  |  |  |   final void Function()? cancel; | 
					
						
							|  |  |  |   final void Function(String) confirm; | 
					
						
							|  |  |  |   final bool autoSelectAllText; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2023-06-23 10:54:35 +08:00
										 |  |  |   State<NavigatorTextFieldDialog> createState() => | 
					
						
							|  |  |  |       _NavigatorTextFieldDialogState(); | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-23 10:54:35 +08:00
										 |  |  | class _NavigatorTextFieldDialogState extends State<NavigatorTextFieldDialog> { | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |   String newValue = ""; | 
					
						
							| 
									
										
										
										
											2023-06-23 10:54:35 +08:00
										 |  |  |   final controller = TextEditingController(); | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |     newValue = widget.value; | 
					
						
							| 
									
										
										
										
											2023-06-23 10:54:35 +08:00
										 |  |  |     controller.text = newValue; | 
					
						
							|  |  |  |     if (widget.autoSelectAllText) { | 
					
						
							|  |  |  |       controller.selection = TextSelection( | 
					
						
							|  |  |  |         baseOffset: 0, | 
					
						
							|  |  |  |         extentOffset: newValue.length, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |     super.initState(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return StyledDialog( | 
					
						
							|  |  |  |       child: Column( | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							| 
									
										
										
										
											2023-04-14 01:21:10 -04:00
										 |  |  |           FlowyText.medium( | 
					
						
							|  |  |  |             widget.title, | 
					
						
							|  |  |  |             color: Theme.of(context).colorScheme.tertiary, | 
					
						
							|  |  |  |             fontSize: FontSizes.s16, | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           VSpace(Insets.m), | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |           FlowyFormTextInput( | 
					
						
							| 
									
										
										
										
											2023-04-14 01:21:10 -04:00
										 |  |  |             textAlign: TextAlign.center, | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  |             hintText: LocaleKeys.dialogCreatePageNameHint.tr(), | 
					
						
							| 
									
										
										
										
											2023-06-23 10:54:35 +08:00
										 |  |  |             controller: controller, | 
					
						
							| 
									
										
										
										
											2023-04-14 01:21:10 -04:00
										 |  |  |             textStyle: Theme.of(context).textTheme.bodySmall?.copyWith( | 
					
						
							|  |  |  |                   fontSize: FontSizes.s16, | 
					
						
							|  |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |             autoFocus: true, | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |             onChanged: (text) { | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |               newValue = text; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2021-11-11 23:11:15 +08:00
										 |  |  |             onEditingComplete: () { | 
					
						
							|  |  |  |               widget.confirm(newValue); | 
					
						
							|  |  |  |               AppGlobals.nav.pop(); | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |           ), | 
					
						
							| 
									
										
										
										
											2023-04-14 01:21:10 -04:00
										 |  |  |           VSpace(Insets.xl), | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |           OkCancelButton( | 
					
						
							|  |  |  |             onOkPressed: () { | 
					
						
							|  |  |  |               widget.confirm(newValue); | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  |               Navigator.of(context).pop(); | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |             }, | 
					
						
							|  |  |  |             onCancelPressed: () { | 
					
						
							|  |  |  |               if (widget.cancel != null) { | 
					
						
							|  |  |  |                 widget.cancel!(); | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  |               Navigator.of(context).pop(); | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |           ) | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  | class NavigatorAlertDialog extends StatefulWidget { | 
					
						
							|  |  |  |   final String title; | 
					
						
							|  |  |  |   final void Function()? cancel; | 
					
						
							|  |  |  |   final void Function()? confirm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const NavigatorAlertDialog({ | 
					
						
							|  |  |  |     required this.title, | 
					
						
							|  |  |  |     this.confirm, | 
					
						
							|  |  |  |     this.cancel, | 
					
						
							|  |  |  |     Key? key, | 
					
						
							|  |  |  |   }) : super(key: key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<NavigatorAlertDialog> createState() => _CreateFlowyAlertDialog(); | 
					
						
							| 
									
										
										
										
											2021-11-10 15:09:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  | class _CreateFlowyAlertDialog extends State<NavigatorAlertDialog> { | 
					
						
							| 
									
										
										
										
											2021-11-10 15:09:24 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return StyledDialog( | 
					
						
							|  |  |  |       child: Column( | 
					
						
							|  |  |  |         crossAxisAlignment: CrossAxisAlignment.start, | 
					
						
							|  |  |  |         mainAxisAlignment: MainAxisAlignment.center, | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           ...[ | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  |             ConstrainedBox( | 
					
						
							|  |  |  |               constraints: const BoxConstraints( | 
					
						
							| 
									
										
										
										
											2023-08-22 00:19:15 +08:00
										 |  |  |                 maxWidth: 400, | 
					
						
							|  |  |  |                 maxHeight: 260, | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  |               ), | 
					
						
							|  |  |  |               child: FlowyText.medium( | 
					
						
							|  |  |  |                 widget.title, | 
					
						
							|  |  |  |                 fontSize: FontSizes.s16, | 
					
						
							|  |  |  |                 color: Theme.of(context).colorScheme.tertiary, | 
					
						
							|  |  |  |                 maxLines: null, | 
					
						
							|  |  |  |               ), | 
					
						
							| 
									
										
										
										
											2022-11-10 14:22:18 +08:00
										 |  |  |             ), | 
					
						
							| 
									
										
										
										
											2021-11-10 15:09:24 +08:00
										 |  |  |           ], | 
					
						
							|  |  |  |           if (widget.confirm != null) ...[ | 
					
						
							|  |  |  |             const VSpace(20), | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |             OkCancelButton( | 
					
						
							|  |  |  |               onOkPressed: () { | 
					
						
							|  |  |  |                 widget.confirm?.call(); | 
					
						
							|  |  |  |                 Navigator.of(context).pop(); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               onCancelPressed: () { | 
					
						
							|  |  |  |                 widget.cancel?.call(); | 
					
						
							|  |  |  |                 Navigator.of(context).pop(); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2021-11-10 15:09:24 +08:00
										 |  |  |           ] | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  | class NavigatorOkCancelDialog extends StatelessWidget { | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |   final VoidCallback? onOkPressed; | 
					
						
							|  |  |  |   final VoidCallback? onCancelPressed; | 
					
						
							|  |  |  |   final String? okTitle; | 
					
						
							|  |  |  |   final String? cancelTitle; | 
					
						
							|  |  |  |   final String? title; | 
					
						
							|  |  |  |   final String message; | 
					
						
							|  |  |  |   final double? maxWidth; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |   const NavigatorOkCancelDialog({ | 
					
						
							|  |  |  |     Key? key, | 
					
						
							|  |  |  |     this.onOkPressed, | 
					
						
							|  |  |  |     this.onCancelPressed, | 
					
						
							|  |  |  |     this.okTitle, | 
					
						
							|  |  |  |     this.cancelTitle, | 
					
						
							|  |  |  |     this.title, | 
					
						
							|  |  |  |     required this.message, | 
					
						
							|  |  |  |     this.maxWidth, | 
					
						
							|  |  |  |   }) : super(key: key); | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return StyledDialog( | 
					
						
							|  |  |  |       maxWidth: maxWidth ?? 500, | 
					
						
							|  |  |  |       child: Column( | 
					
						
							|  |  |  |         crossAxisAlignment: CrossAxisAlignment.start, | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           if (title != null) ...[ | 
					
						
							| 
									
										
										
										
											2022-11-19 17:53:30 +08:00
										 |  |  |             FlowyText.medium( | 
					
						
							|  |  |  |               title!.toUpperCase(), | 
					
						
							|  |  |  |               fontSize: FontSizes.s16, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |             VSpace(Insets.sm * 1.5), | 
					
						
							| 
									
										
										
										
											2022-11-10 14:22:18 +08:00
										 |  |  |             Container( | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |               color: Theme.of(context).colorScheme.surfaceVariant, | 
					
						
							|  |  |  |               height: 1, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |             VSpace(Insets.m * 1.5), | 
					
						
							|  |  |  |           ], | 
					
						
							| 
									
										
										
										
											2022-11-19 17:53:30 +08:00
										 |  |  |           FlowyText.medium(message), | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |           SizedBox(height: Insets.l), | 
					
						
							|  |  |  |           OkCancelButton( | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  |             onOkPressed: () { | 
					
						
							|  |  |  |               onOkPressed?.call(); | 
					
						
							|  |  |  |               Navigator.of(context).pop(); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             onCancelPressed: () { | 
					
						
							|  |  |  |               onCancelPressed?.call(); | 
					
						
							|  |  |  |               Navigator.of(context).pop(); | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |             okTitle: okTitle?.toUpperCase(), | 
					
						
							|  |  |  |             cancelTitle: cancelTitle?.toUpperCase(), | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class OkCancelButton extends StatelessWidget { | 
					
						
							|  |  |  |   final VoidCallback? onOkPressed; | 
					
						
							|  |  |  |   final VoidCallback? onCancelPressed; | 
					
						
							|  |  |  |   final String? okTitle; | 
					
						
							|  |  |  |   final String? cancelTitle; | 
					
						
							|  |  |  |   final double? minHeight; | 
					
						
							| 
									
										
										
										
											2023-04-14 01:21:10 -04:00
										 |  |  |   final MainAxisAlignment alignment; | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  |   final TextButtonMode mode; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |   const OkCancelButton({ | 
					
						
							|  |  |  |     Key? key, | 
					
						
							|  |  |  |     this.onOkPressed, | 
					
						
							|  |  |  |     this.onCancelPressed, | 
					
						
							|  |  |  |     this.okTitle, | 
					
						
							|  |  |  |     this.cancelTitle, | 
					
						
							|  |  |  |     this.minHeight, | 
					
						
							| 
									
										
										
										
											2023-04-14 01:21:10 -04:00
										 |  |  |     this.alignment = MainAxisAlignment.spaceAround, | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  |     this.mode = TextButtonMode.big, | 
					
						
							| 
									
										
										
										
											2023-04-10 15:10:42 +08:00
										 |  |  |   }) : super(key: key); | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |     return SizedBox( | 
					
						
							|  |  |  |       height: 48, | 
					
						
							|  |  |  |       child: Row( | 
					
						
							| 
									
										
										
										
											2023-04-14 01:21:10 -04:00
										 |  |  |         mainAxisAlignment: alignment, | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           if (onCancelPressed != null) | 
					
						
							|  |  |  |             SecondaryTextButton( | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  |               cancelTitle ?? LocaleKeys.button_Cancel.tr(), | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  |               onPressed: onCancelPressed, | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  |               mode: mode, | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           HSpace(Insets.m), | 
					
						
							|  |  |  |           if (onOkPressed != null) | 
					
						
							|  |  |  |             PrimaryTextButton( | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  |               okTitle ?? LocaleKeys.button_OK.tr(), | 
					
						
							| 
									
										
										
										
											2022-09-15 16:05:55 +08:00
										 |  |  |               onPressed: onOkPressed, | 
					
						
							| 
									
										
										
										
											2023-08-17 23:46:39 +08:00
										 |  |  |               mode: mode, | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |