feat: improve snackbar UI style (#3562)

This commit is contained in:
Aman Negi 2023-10-02 12:44:40 +05:30 committed by GitHub
parent 94a3a59001
commit 01c3fec5aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 76 additions and 95 deletions

View File

@ -10,6 +10,7 @@ import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/plugins/document/presentation/export_page_widget.dart'; import 'package:appflowy/plugins/document/presentation/export_page_widget.dart';
import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/base64_string.dart'; import 'package:appflowy/util/base64_string.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart' import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart'
hide DocumentEvent; hide DocumentEvent;
@ -17,7 +18,6 @@ import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log; import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/file_picker/file_picker_service.dart'; import 'package:flowy_infra/file_picker/file_picker_service.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/error_page.dart'; import 'package:flowy_infra_ui/widget/error_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
@ -145,18 +145,8 @@ class _DocumentPageState extends State<DocumentPage> {
const encoder = JsonEncoder.withIndent(' '); const encoder = JsonEncoder.withIndent(' ');
final json = encoder.convert(data.toProto3Json()); final json = encoder.convert(data.toProto3Json());
await File(path).writeAsString(json.base64.base64); await File(path).writeAsString(json.base64.base64);
if (mounted) {
_showMessage('Export success to $path'); showSnackBarMessage(context, 'Export success to $path');
}
void _showMessage(String message) {
if (!mounted) {
return;
} }
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: FlowyText(message),
),
);
} }
} }

View File

@ -1,5 +1,6 @@
import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
@ -65,12 +66,9 @@ class _ImageMenuState extends State<ImageMenu> {
final url = widget.node.attributes[ImageBlockKeys.url]; final url = widget.node.attributes[ImageBlockKeys.url];
if (url != null) { if (url != null) {
Clipboard.setData(ClipboardData(text: url)); Clipboard.setData(ClipboardData(text: url));
ScaffoldMessenger.of(context).showSnackBar( showSnackBarMessage(
SnackBar( context,
content: FlowyText( LocaleKeys.document_plugins_image_copiedToPasteBoard.tr(),
LocaleKeys.document_plugins_image_copiedToPasteBoard.tr(),
),
),
); );
} }
} }

View File

@ -5,6 +5,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/uti
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/discard_dialog.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/discard_dialog.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/loading.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/loading.dart';
import 'package:appflowy/user/application/user_service.dart'; import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flowy_infra_ui/style_widget/button.dart'; import 'package:flowy_infra_ui/style_widget/button.dart';
import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/style_widget/text.dart';
@ -196,9 +197,13 @@ class _AutoCompletionBlockComponentState
.then((value) => value.toOption().toNullable()); .then((value) => value.toOption().toNullable());
if (userProfile == null) { if (userProfile == null) {
loading.stop(); loading.stop();
await _showError( if (mounted) {
LocaleKeys.document_plugins_autoGeneratorCantGetOpenAIKey.tr(), showSnackBarMessage(
); context,
LocaleKeys.document_plugins_autoGeneratorCantGetOpenAIKey.tr(),
showCancel: true,
);
}
return; return;
} }
@ -231,7 +236,11 @@ class _AutoCompletionBlockComponentState
}, },
onError: (error) async { onError: (error) async {
loading.stop(); loading.stop();
await _showError(error.message); showSnackBarMessage(
context,
error.message,
showCancel: true,
);
}, },
); );
await _updateGenerationCount(); await _updateGenerationCount();
@ -282,9 +291,13 @@ class _AutoCompletionBlockComponentState
.then((value) => value.toOption().toNullable()); .then((value) => value.toOption().toNullable());
if (userProfile == null) { if (userProfile == null) {
loading.stop(); loading.stop();
await _showError( if (mounted) {
LocaleKeys.document_plugins_autoGeneratorCantGetOpenAIKey.tr(), showSnackBarMessage(
); context,
LocaleKeys.document_plugins_autoGeneratorCantGetOpenAIKey.tr(),
showCancel: true,
);
}
return; return;
} }
final textRobot = TextRobot(editorState: editorState); final textRobot = TextRobot(editorState: editorState);
@ -311,7 +324,11 @@ class _AutoCompletionBlockComponentState
onEnd: () async {}, onEnd: () async {},
onError: (error) async { onError: (error) async {
loading.stop(); loading.stop();
await _showError(error.message); showSnackBarMessage(
context,
error.message,
showCancel: true,
);
}, },
); );
await _updateGenerationCount(); await _updateGenerationCount();
@ -399,20 +416,6 @@ class _AutoCompletionBlockComponentState
await editorState.apply(transaction); await editorState.apply(transaction);
} }
Future<void> _showError(String message) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
action: SnackBarAction(
label: LocaleKeys.button_Cancel.tr(),
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
content: FlowyText(message),
),
);
}
void _subscribeSelectionGesture() { void _subscribeSelectionGesture() {
interceptor = SelectionGestureInterceptor( interceptor = SelectionGestureInterceptor(
key: AutoCompletionBlockKeys.type, key: AutoCompletionBlockKeys.type,

View File

@ -5,6 +5,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/uti
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/discard_dialog.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/discard_dialog.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_action.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_action.dart';
import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart';
@ -454,24 +455,14 @@ class _SmartEditInputWidgetState extends State<SmartEditInputWidget> {
}); });
}, },
onError: (error) async { onError: (error) async {
await _showError(error.message); showSnackBarMessage(
context,
error.message,
showCancel: true,
);
await _onExit(); await _onExit();
}, },
); );
} }
} }
Future<void> _showError(String message) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
action: SnackBarAction(
label: LocaleKeys.button_Cancel.tr(),
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
content: FlowyText(message),
),
);
}
} }

View File

@ -2,12 +2,12 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_action.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_action.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/user/application/user_service.dart'; import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart'; import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/icon_button.dart'; import 'package:flowy_infra_ui/style_widget/icon_button.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
final ToolbarItem smartEditItem = ToolbarItem( final ToolbarItem smartEditItem = ToolbarItem(
@ -71,7 +71,11 @@ class _SmartEditActionListState extends State<SmartEditActionList> {
if (isOpenAIEnabled) { if (isOpenAIEnabled) {
controller.show(); controller.show();
} else { } else {
_showError(LocaleKeys.document_plugins_smartEditDisabled.tr()); showSnackBarMessage(
context,
LocaleKeys.document_plugins_smartEditDisabled.tr(),
showCancel: true,
);
} }
}, },
); );
@ -111,18 +115,4 @@ class _SmartEditActionListState extends State<SmartEditActionList> {
withUpdateSelection: false, withUpdateSelection: false,
); );
} }
Future<void> _showError(String message) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
action: SnackBarAction(
label: LocaleKeys.button_Cancel.tr(),
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
content: FlowyText(message),
),
);
}
} }

View File

@ -1,4 +1,6 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/startup/startup.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/size.dart';
import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -40,9 +42,22 @@ void showMessageToast(String message) {
); );
} }
void showSnackBarMessage(BuildContext context, String message) { void showSnackBarMessage(
BuildContext context,
String message, {
bool showCancel = false,
}) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
action: !showCancel
? null
: SnackBarAction(
label: LocaleKeys.button_Cancel.tr(),
textColor: Theme.of(context).colorScheme.onSurface,
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
content: FlowyText( content: FlowyText(
message, message,
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,

View File

@ -1,6 +1,7 @@
import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/appearance.dart'; import 'package:appflowy/workspace/application/appearance.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_appearance/theme_setting_entry_template.dart'; import 'package:appflowy/workspace/presentation/settings/widgets/settings_appearance/theme_setting_entry_template.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/theme_upload/theme_upload_view.dart'; import 'package:appflowy/workspace/presentation/settings/widgets/theme_upload/theme_upload_view.dart';
import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:appflowy_popover/appflowy_popover.dart';
@ -65,13 +66,9 @@ class ColorSchemeUploadOverlayButton extends StatelessWidget {
), ),
).then((value) { ).then((value) {
if (value == null) return; if (value == null) return;
ScaffoldMessenger.of(context).showSnackBar( showSnackBarMessage(
SnackBar( context,
content: FlowyText.medium( LocaleKeys.settings_appearance_themeUpload_uploadSuccess.tr(),
color: Theme.of(context).colorScheme.onPrimary,
LocaleKeys.settings_appearance_themeUpload_uploadSuccess.tr(),
),
),
); );
}), }),
); );

View File

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/export/document_exporter.dart'; import 'package:appflowy/workspace/application/export/document_exporter.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart'; import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:flowy_infra/file_picker/file_picker_service.dart'; import 'package:flowy_infra/file_picker/file_picker_service.dart';
import 'package:appflowy/workspace/application/settings/settings_file_exporter_cubit.dart'; import 'package:appflowy/workspace/application/settings/settings_file_exporter_cubit.dart';
@ -106,17 +107,24 @@ class _FileExporterWidgetState extends State<FileExporterWidget> {
final views = cubit!.state.selectedViews; final views = cubit!.state.selectedViews;
final result = final result =
await _AppFlowyFileExporter.exportToPath(exportPath, views); await _AppFlowyFileExporter.exportToPath(exportPath, views);
if (result.$1) { if (result.$1 && mounted) {
// success // success
_showToast(LocaleKeys.settings_files_exportFileSuccess.tr()); showSnackBarMessage(
context,
LocaleKeys.settings_files_exportFileSuccess.tr(),
);
} else { } else {
_showToast( showSnackBarMessage(
context,
LocaleKeys.settings_files_exportFileFail.tr() + LocaleKeys.settings_files_exportFileFail.tr() +
result.$2.join('\n'), result.$2.join('\n'),
); );
} }
} else { } else {
_showToast(LocaleKeys.settings_files_exportFileFail.tr()); showSnackBarMessage(
context,
LocaleKeys.settings_files_exportFileFail.tr(),
);
} }
if (mounted) { if (mounted) {
Navigator.of(context).popUntil( Navigator.of(context).popUntil(
@ -129,17 +137,6 @@ class _FileExporterWidgetState extends State<FileExporterWidget> {
], ],
); );
} }
void _showToast(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: FlowyText(
message,
color: Theme.of(context).colorScheme.onSurface,
),
),
);
}
} }
class _ExpandedList extends StatefulWidget { class _ExpandedList extends StatefulWidget {