123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- import 'package:appflowy_popover/popover.dart';
- import 'package:easy_localization/easy_localization.dart';
- 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';
- import 'package:app_flowy/startup/tasks/app_widget.dart';
- 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';
- import 'package:app_flowy/generated/locale_keys.g.dart';
- class NavigatorTextFieldDialog extends StatefulWidget {
- final String value;
- final String title;
- final void Function()? cancel;
- final void Function(String) confirm;
- const NavigatorTextFieldDialog({
- required this.title,
- required this.value,
- required this.confirm,
- this.cancel,
- Key? key,
- }) : super(key: key);
- @override
- State<NavigatorTextFieldDialog> createState() => _CreateTextFieldDialog();
- }
- class _CreateTextFieldDialog extends State<NavigatorTextFieldDialog> {
- String newValue = "";
- @override
- void initState() {
- newValue = widget.value;
- 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(
- hintText: LocaleKeys.dialogCreatePageNameHint.tr(),
- initialValue: widget.value,
- textStyle:
- const TextStyle(fontSize: 24, fontWeight: FontWeight.w400),
- autoFocus: true,
- onChanged: (text) {
- newValue = text;
- },
- onEditingComplete: () {
- widget.confirm(newValue);
- AppGlobals.nav.pop();
- },
- ),
- const VSpace(10),
- OkCancelButton(
- onOkPressed: () {
- widget.confirm(newValue);
- Navigator.of(context).pop();
- },
- onCancelPressed: () {
- if (widget.cancel != null) {
- widget.cancel!();
- }
- Navigator.of(context).pop();
- },
- )
- ],
- ),
- );
- }
- }
- class PopoverAlertView extends StatelessWidget {
- final PopoverMutex popoverMutex;
- final String title;
- final void Function()? cancel;
- final void Function()? confirm;
- const PopoverAlertView({
- required this.popoverMutex,
- required this.title,
- this.confirm,
- this.cancel,
- Key? key,
- }) : super(key: key);
- @override
- Widget build(BuildContext context) {
- final theme = context.watch<AppTheme>();
- return StyledDialog(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- ...[
- FlowyText.medium(title, color: theme.shader4),
- ],
- if (confirm != null) ...[
- const VSpace(20),
- OkCancelButton(
- onOkPressed: confirm,
- onCancelPressed: cancel,
- )
- ]
- ],
- ),
- );
- }
- }
- 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();
- }
- class _CreateFlowyAlertDialog extends State<NavigatorAlertDialog> {
- @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?.call();
- Navigator.of(context).pop();
- }, onCancelPressed: () {
- widget.cancel?.call();
- Navigator.of(context).pop();
- })
- ]
- ],
- ),
- );
- }
- }
- class NavigatorOkCancelDialog extends StatelessWidget {
- final VoidCallback? onOkPressed;
- final VoidCallback? onCancelPressed;
- final String? okTitle;
- final String? cancelTitle;
- final String? title;
- final String message;
- final double? maxWidth;
- const NavigatorOkCancelDialog(
- {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) ...[
- FlowyText.medium(title!.toUpperCase(), color: 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?.call();
- Navigator.of(context).pop();
- },
- onCancelPressed: () {
- onCancelPressed?.call();
- Navigator.of(context).pop();
- },
- 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) {
- return SizedBox(
- height: 48,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- if (onCancelPressed != null)
- SecondaryTextButton(
- cancelTitle ?? LocaleKeys.button_Cancel.tr(),
- onPressed: onCancelPressed,
- bigMode: true,
- ),
- HSpace(Insets.m),
- if (onOkPressed != null)
- PrimaryTextButton(
- okTitle ?? LocaleKeys.button_OK.tr(),
- onPressed: onOkPressed,
- bigMode: true,
- ),
- ],
- ),
- );
- }
- }
|