| 
									
										
										
										
											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/text_style.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra/theme.dart'; | 
					
						
							|  |  |  | 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'; | 
					
						
							|  |  |  | import 'package:provider/provider.dart'; | 
					
						
							| 
									
										
										
										
											2022-02-19 23:19:33 +08:00
										 |  |  | import 'package:app_flowy/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'; | 
					
						
							|  |  |  | import 'package:textstyle_extensions/textstyle_extensions.dart'; | 
					
						
							|  |  |  | export 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart'; | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  | import 'package:app_flowy/generated/locale_keys.g.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  | class TextFieldDialog extends StatefulWidget { | 
					
						
							|  |  |  |   final String value; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |   final String title; | 
					
						
							|  |  |  |   final void Function()? cancel; | 
					
						
							|  |  |  |   final void Function(String) confirm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |   const TextFieldDialog({ | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |     required this.title, | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |     required this.value, | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |     required this.confirm, | 
					
						
							|  |  |  |     this.cancel, | 
					
						
							|  |  |  |     Key? key, | 
					
						
							|  |  |  |   }) : super(key: key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |   State<TextFieldDialog> createState() => _CreateTextFieldDialog(); | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  | class _CreateTextFieldDialog extends State<TextFieldDialog> { | 
					
						
							|  |  |  |   String newValue = ""; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							| 
									
										
										
										
											2021-10-23 20:32:39 +08:00
										 |  |  |     newValue = widget.value; | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |     super.initState(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     final theme = context.watch<AppTheme>(); | 
					
						
							|  |  |  |     return StyledDialog( | 
					
						
							|  |  |  |       child: Column( | 
					
						
							|  |  |  |         crossAxisAlignment: CrossAxisAlignment.start, | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           ...[ | 
					
						
							|  |  |  |             FlowyText.medium(widget.title, color: theme.shader4), | 
					
						
							|  |  |  |             VSpace(Insets.sm * 1.5), | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |           FlowyFormTextInput( | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  |             hintText: LocaleKeys.dialogCreatePageNameHint.tr(), | 
					
						
							| 
									
										
										
										
											2021-11-10 19:25:38 +08:00
										 |  |  |             initialValue: widget.value, | 
					
						
							| 
									
										
										
										
											2021-10-29 14:43:10 +08:00
										 |  |  |             textStyle: const TextStyle(fontSize: 24, fontWeight: FontWeight.w400), | 
					
						
							| 
									
										
										
										
											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
										 |  |  |           ), | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |           const VSpace(10), | 
					
						
							|  |  |  |           OkCancelButton( | 
					
						
							|  |  |  |             onOkPressed: () { | 
					
						
							|  |  |  |               widget.confirm(newValue); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             onCancelPressed: () { | 
					
						
							|  |  |  |               if (widget.cancel != null) { | 
					
						
							|  |  |  |                 widget.cancel!(); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |           ) | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-10 15:09:24 +08:00
										 |  |  | class FlowyAlertDialog extends StatefulWidget { | 
					
						
							|  |  |  |   final String title; | 
					
						
							|  |  |  |   final void Function()? cancel; | 
					
						
							|  |  |  |   final void Function()? confirm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const FlowyAlertDialog({ | 
					
						
							|  |  |  |     required this.title, | 
					
						
							|  |  |  |     this.confirm, | 
					
						
							|  |  |  |     this.cancel, | 
					
						
							|  |  |  |     Key? key, | 
					
						
							|  |  |  |   }) : super(key: key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<FlowyAlertDialog> createState() => _CreateFlowyAlertDialog(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _CreateFlowyAlertDialog extends State<FlowyAlertDialog> { | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     final theme = context.watch<AppTheme>(); | 
					
						
							|  |  |  |     return StyledDialog( | 
					
						
							|  |  |  |       child: Column( | 
					
						
							|  |  |  |         crossAxisAlignment: CrossAxisAlignment.start, | 
					
						
							|  |  |  |         mainAxisAlignment: MainAxisAlignment.center, | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           ...[ | 
					
						
							|  |  |  |             FlowyText.medium(widget.title, color: theme.shader4), | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |           if (widget.confirm != null) ...[ | 
					
						
							|  |  |  |             const VSpace(20), | 
					
						
							|  |  |  |             OkCancelButton( | 
					
						
							|  |  |  |               onOkPressed: widget.confirm!, | 
					
						
							|  |  |  |               onCancelPressed: widget.confirm, | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  | class OkCancelDialog extends StatelessWidget { | 
					
						
							|  |  |  |   final VoidCallback? onOkPressed; | 
					
						
							|  |  |  |   final VoidCallback? onCancelPressed; | 
					
						
							|  |  |  |   final String? okTitle; | 
					
						
							|  |  |  |   final String? cancelTitle; | 
					
						
							|  |  |  |   final String? title; | 
					
						
							|  |  |  |   final String message; | 
					
						
							|  |  |  |   final double? maxWidth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const OkCancelDialog( | 
					
						
							|  |  |  |       {Key? key, | 
					
						
							|  |  |  |       this.onOkPressed, | 
					
						
							|  |  |  |       this.onCancelPressed, | 
					
						
							|  |  |  |       this.okTitle, | 
					
						
							|  |  |  |       this.cancelTitle, | 
					
						
							|  |  |  |       this.title, | 
					
						
							|  |  |  |       required this.message, | 
					
						
							|  |  |  |       this.maxWidth}) | 
					
						
							|  |  |  |       : super(key: key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     final theme = context.watch<AppTheme>(); | 
					
						
							|  |  |  |     return StyledDialog( | 
					
						
							|  |  |  |       maxWidth: maxWidth ?? 500, | 
					
						
							|  |  |  |       child: Column( | 
					
						
							|  |  |  |         crossAxisAlignment: CrossAxisAlignment.start, | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           if (title != null) ...[ | 
					
						
							|  |  |  |             Text(title!.toUpperCase(), style: TextStyles.T1.textColor(theme.shader1)), | 
					
						
							|  |  |  |             VSpace(Insets.sm * 1.5), | 
					
						
							|  |  |  |             Container(color: theme.bg1, height: 1), | 
					
						
							|  |  |  |             VSpace(Insets.m * 1.5), | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |           Text(message, style: TextStyles.Body1.textHeight(1.5)), | 
					
						
							|  |  |  |           SizedBox(height: Insets.l), | 
					
						
							|  |  |  |           OkCancelButton( | 
					
						
							|  |  |  |             onOkPressed: onOkPressed, | 
					
						
							|  |  |  |             onCancelPressed: onCancelPressed, | 
					
						
							|  |  |  |             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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const OkCancelButton( | 
					
						
							|  |  |  |       {Key? key, this.onOkPressed, this.onCancelPressed, this.okTitle, this.cancelTitle, this.minHeight}) | 
					
						
							|  |  |  |       : super(key: key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |     return SizedBox( | 
					
						
							|  |  |  |       height: 48, | 
					
						
							|  |  |  |       child: Row( | 
					
						
							|  |  |  |         mainAxisAlignment: MainAxisAlignment.end, | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           if (onCancelPressed != null) | 
					
						
							|  |  |  |             SecondaryTextButton( | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  |               cancelTitle ?? LocaleKeys.button_Cancel.tr(), | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |               onPressed: () { | 
					
						
							|  |  |  |                 onCancelPressed!(); | 
					
						
							|  |  |  |                 AppGlobals.nav.pop(); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               bigMode: true, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           HSpace(Insets.m), | 
					
						
							|  |  |  |           if (onOkPressed != null) | 
					
						
							|  |  |  |             PrimaryTextButton( | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  |               okTitle ?? LocaleKeys.button_OK.tr(), | 
					
						
							| 
									
										
										
										
											2021-10-24 18:54:41 +08:00
										 |  |  |               onPressed: () { | 
					
						
							|  |  |  |                 onOkPressed!(); | 
					
						
							|  |  |  |                 AppGlobals.nav.pop(); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               bigMode: true, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2021-10-20 14:56:25 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |