Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: file block on mobile (#6245)
Mathias Mogensen7bd876bf857c
diff --git a/frontend/appflowy_flutter/ios/Podfile.lock b/frontend/appflowy_flutter/ios/Podfile.lockindex 28d37bfa23..a8d1d344be 100644--- a/frontend/appflowy_flutter/ios/Podfile.lock+++ b/frontend/appflowy_flutter/ios/Podfile.lock@@ -56,6 +56,8 @@ PODS:- Flutter- keyboard_height_plugin (0.0.1):- Flutter+ - open_filex (0.0.2):+ - Flutter- package_info_plus (0.4.5):- Flutter- path_provider_foundation (0.0.1):@@ -100,6 +102,7 @@ DEPENDENCIES:- integration_test (from `.symlinks/plugins/integration_test/ios`)- irondash_engine_context (from `.symlinks/plugins/irondash_engine_context/ios`)- keyboard_height_plugin (from `.symlinks/plugins/keyboard_height_plugin/ios`)+ - open_filex (from `.symlinks/plugins/open_filex/ios`)- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)@@ -145,6 +148,8 @@ EXTERNAL SOURCES::path: ".symlinks/plugins/irondash_engine_context/ios"keyboard_height_plugin::path: ".symlinks/plugins/keyboard_height_plugin/ios"+ open_filex:+ :path: ".symlinks/plugins/open_filex/ios"package_info_plus::path: ".symlinks/plugins/package_info_plus/ios"path_provider_foundation:@@ -179,6 +184,7 @@ SPEC CHECKSUMS:integration_test: ce0a3ffa1de96d1a89ca0ac26fca7ea18a749ef4irondash_engine_context: 3458bf979b90d616ffb8ae03a150bafe2e860cc9keyboard_height_plugin: 43fa8bba20fd5c4fdeed5076466b8b9d43cc6b86+ open_filex: 6e26e659846ec990262224a12ef1c528bb4edbe4package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1cpath_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147cpermission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dartindex 0e3a83ba7c..97224fb9c2 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart@@ -3,11 +3,16 @@ import 'package:flutter/material.dart';import 'package:appflowy/core/helpers/url_launcher.dart';import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart';+import 'package:appflowy/mobile/presentation/widgets/flowy_option_tile.dart';import 'package:appflowy/plugins/document/application/document_bloc.dart';import 'package:appflowy/plugins/document/presentation/editor_drop_manager.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_util.dart';+import 'package:appflowy/startup/startup.dart';import 'package:appflowy/workspace/presentation/home/toast.dart';+import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:appflowy_popover/appflowy_popover.dart';import 'package:cross_file/cross_file.dart';@@ -15,8 +20,11 @@ import 'package:desktop_drop/desktop_drop.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flowy_infra_ui/flowy_infra_ui.dart';import 'package:flowy_infra_ui/style_widget/hover.dart';+import 'package:go_router/go_router.dart';+import 'package:open_filex/open_filex.dart';import 'package:provider/provider.dart';import 'package:string_validator/string_validator.dart';+import 'package:toastification/toastification.dart';import 'file_block_menu.dart';import 'file_upload_menu.dart';@@ -169,6 +177,8 @@ class FileBlockComponentState extends State<FileBlockComponent>@overrideWidget build(BuildContext context) {final url = node.attributes[FileBlockKeys.url];+ final FileUrlType urlType =+ FileUrlType.fromIntValue(node.attributes[FileBlockKeys.urlType] ?? 0);Widget child = MouseRegion(cursor: SystemMouseCursors.click,@@ -186,11 +196,8 @@ class FileBlockComponentState extends State<FileBlockComponent>child: GestureDetector(behavior: HitTestBehavior.translucent,onTap: url != null && url.isNotEmpty- ? () => afLaunchUrlString(url)- : () {- controller.show();- dropManagerState.add(FileBlockKeys.type);- },+ ? () async => _openFile(context, urlType, url)+ : _openMenu,child: DecoratedBox(decoration: BoxDecoration(color: isHovering@@ -269,8 +276,16 @@ class FileBlockComponentState extends State<FileBlockComponent>supportTypes: const [BlockSelectionType.block],child: Padding(key: fileKey, padding: padding, child: child),);- } else {- child = Padding(key: fileKey, padding: padding, child: child);+ } else if (url == null || url.isEmpty) {+ return Padding(+ key: fileKey,+ padding: padding,+ child: MobileBlockActionButtons(+ node: widget.node,+ editorState: editorState,+ child: child,+ ),+ );}if (widget.showActions && widget.actionBuilder != null) {@@ -284,9 +299,9 @@ class FileBlockComponentState extends State<FileBlockComponent>if (!PlatformExtension.isDesktopOrWeb) {// show a fixed menu on mobilechild = MobileBlockActionButtons(- showThreeDots: false,node: node,editorState: editorState,+ extendActionWidgets: _buildExtendActionWidgets(context),child: child,);}@@ -294,6 +309,39 @@ class FileBlockComponentState extends State<FileBlockComponent>return child;}+ Future<void> _openFile(+ BuildContext context,+ FileUrlType urlType,+ String url,+ ) async {+ if ([FileUrlType.cloud, FileUrlType.network].contains(urlType) ||+ PlatformExtension.isDesktopOrWeb) {+ await afLaunchUrlString(url);+ } else {+ final result = await OpenFilex.open(url);+ if (result.type == ResultType.done) {+ return;+ }++ if (context.mounted) {+ showToastNotification(+ context,+ message: LocaleKeys.document_plugins_file_failedToOpenMsg.tr(),+ type: ToastificationType.error,+ );+ }+ }+ }++ void _openMenu() {+ if (PlatformExtension.isDesktopOrWeb) {+ controller.show();+ dropManagerState.add(FileBlockKeys.type);+ } else {+ showUploadFileMobileMenu();+ }+ }+List<Widget> _buildTrailing(BuildContext context) {if (node.attributes[FileBlockKeys.url]?.isNotEmpty == true) {final name = node.attributes[FileBlockKeys.name] as String;@@ -360,6 +408,69 @@ class FileBlockComponentState extends State<FileBlockComponent>}}+ // only used on mobile platform+ List<Widget> _buildExtendActionWidgets(BuildContext context) {+ final String? url = widget.node.attributes[FileBlockKeys.url];+ if (url == null || url.isEmpty) {+ return [];+ }++ final urlType = FileUrlType.fromIntValue(+ widget.node.attributes[FileBlockKeys.urlType] ?? 0,+ );++ if (urlType != FileUrlType.network) {+ return [];+ }++ return [+ FlowyOptionTile.text(+ showTopBorder: false,+ text: LocaleKeys.editor_copyLink.tr(),+ leftIcon: const FlowySvg(+ FlowySvgs.m_field_copy_s,+ ),+ onTap: () async {+ context.pop();+ showSnackBarMessage(+ context,+ LocaleKeys.document_plugins_image_copiedToPasteBoard.tr(),+ );+ await getIt<ClipboardService>().setPlainText(url);+ },+ ),+ ];+ }++ void showUploadFileMobileMenu() {+ showMobileBottomSheet(+ context,+ title: LocaleKeys.document_plugins_file_name.tr(),+ showHeader: true,+ showCloseButton: true,+ showDragHandle: true,+ builder: (context) {+ return Container(+ margin: const EdgeInsets.only(top: 12.0),+ constraints: const BoxConstraints(+ maxHeight: 340,+ minHeight: 80,+ ),+ child: FileUploadMenu(+ onInsertLocalFile: (file) async {+ context.pop();+ await insertFileFromLocal(file);+ },+ onInsertNetworkFile: (url) async {+ context.pop();+ await insertNetworkFile(url);+ },+ ),+ );+ },+ );+ }+Future<void> insertFileFromLocal(XFile file) async {final path = file.path;final documentBloc = context.read<DocumentBloc>();@@ -406,7 +517,18 @@ class FileBlockComponentState extends State<FileBlockComponent>// Remove the file block from the drop state managerdropManagerState.remove(FileBlockKeys.type);- final name = Uri.tryParse(url)?.pathSegments.last ?? url;+ final uri = Uri.tryParse(url);+ if (uri == null) {+ return;+ }++ String name = uri.pathSegments.isNotEmpty ? uri.pathSegments.last : "";+ if (name.isEmpty && uri.pathSegments.length > 1) {+ name = uri.pathSegments[uri.pathSegments.length - 2];+ } else if (name.isEmpty) {+ name = uri.host;+ }+final transaction = editorState.transaction;transaction.updateNode(widget.node, {FileBlockKeys.url: url,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dartindex d09e2be349..5b1e8f1de9 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dart@@ -1,5 +1,7 @@import 'dart:async';+import 'package:flutter/material.dart';+import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/generated/locale_keys.g.dart';import 'package:appflowy/mobile/presentation/base/type_option_menu_item.dart';@@ -19,7 +21,6 @@ import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dartimport 'package:appflowy_editor/appflowy_editor.dart';import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';import 'package:easy_localization/easy_localization.dart';-import 'package:flutter/material.dart';import 'package:go_router/go_router.dart';final addBlockToolbarItem = AppFlowyMobileToolbarItem(@@ -210,6 +211,18 @@ class _AddBlockMenu extends StatelessWidget {});},),+ TypeOptionMenuItemValue(+ value: FileBlockKeys.type,+ backgroundColor: colorMap[ImageBlockKeys.type]!,+ text: LocaleKeys.document_plugins_file_name.tr(),+ icon: FlowySvgs.media_s,+ onTap: (_, __) async {+ AppGlobals.rootNavKey.currentContext?.pop(true);+ Future.delayed(const Duration(milliseconds: 400), () async {+ await editorState.insertEmptyFileBlock();+ });+ },+ ),// dateTypeOptionMenuItemValue(diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lockindex 7aabd9ea0f..7c27e51401 100644--- a/frontend/appflowy_flutter/pubspec.lock+++ b/frontend/appflowy_flutter/pubspec.lock@@ -1355,6 +1355,14 @@ packages:url: "https://pub.dev"source: hostedversion: "2.0.0"+ open_filex:+ dependency: "direct main"+ description:+ name: open_filex+ sha256: ba425ea49affd0a98a234aa9344b9ea5d4c4f7625a1377961eae9fe194c3d523+ url: "https://pub.dev"+ source: hosted+ version: "4.5.0"package_config:dependency: transitivedescription:diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yamlindex bd8594870f..b2931c42cd 100644--- a/frontend/appflowy_flutter/pubspec.yaml+++ b/frontend/appflowy_flutter/pubspec.yaml@@ -155,6 +155,9 @@ dependencies:sentry: ^8.8.0mime: ^1.0.6+ # Used to open local files on Mobile+ open_filex: ^4.5.0+dev_dependencies:flutter_lints: ^4.0.0diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex d9a3662b1a..975e362ac4 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -1705,7 +1705,8 @@"nameEmptyError": "File name cannot be left empty."},"uploadedAt": "Uploaded on {}",- "linkedAt": "Link added on {}"+ "linkedAt": "Link added on {}",+ "failedToOpenMsg": "Failed to open, file not found"}},"outlineBlock": {