refactor: use open_filex instead of open_file with xdg-open workaround
- Replace open_file + manual xdg-open with open_filex (maintained fork) - open_filex has better Linux support built-in - Removes platform-specific code, cleaner implementation Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
co-authored by
Qwen-Coder
parent
052dd6426d
commit
5984137bdc
@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
import 'package:open_file/open_file.dart';
|
||||
import 'package:open_filex/open_filex.dart';
|
||||
|
||||
import '../../core/models/account.dart';
|
||||
import '../../core/models/email.dart';
|
||||
@@ -187,20 +187,7 @@ class _ComposeScreenState extends ConsumerState<ComposeScreen> {
|
||||
setState(() => _opening = true);
|
||||
try {
|
||||
final path = _attachments[index].path;
|
||||
|
||||
// On Linux, OpenFile.open may fail with "file type not supported".
|
||||
// Use xdg-open directly for better compatibility.
|
||||
if (Platform.isLinux) {
|
||||
final result = await Process.run('xdg-open', [path]);
|
||||
if (result.exitCode != 0 && mounted) {
|
||||
throw Exception(
|
||||
'xdg-open failed: ${result.stderr}\n'
|
||||
'File path: $path',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await OpenFile.open(path);
|
||||
}
|
||||
await OpenFilex.open(path);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:open_file/open_file.dart';
|
||||
import 'package:open_filex/open_filex.dart';
|
||||
|
||||
import '../../core/models/email.dart';
|
||||
import '../../core/utils/format_utils.dart';
|
||||
@@ -162,20 +161,7 @@ class _EmailDetailScreenState extends ConsumerState<EmailDetailScreen> {
|
||||
final path = await ref
|
||||
.read(emailRepositoryProvider)
|
||||
.downloadAttachment(widget.emailId, att);
|
||||
|
||||
// On Linux, OpenFile.open may fail with "file type not supported".
|
||||
// Use xdg-open directly for better compatibility.
|
||||
if (Platform.isLinux) {
|
||||
final result = await Process.run('xdg-open', [path]);
|
||||
if (result.exitCode != 0 && mounted) {
|
||||
throw Exception(
|
||||
'xdg-open failed: ${result.stderr}\n'
|
||||
'File saved to: $path',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await OpenFile.open(path);
|
||||
}
|
||||
await OpenFilex.open(path);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ dependencies:
|
||||
|
||||
# File picking (compose attachments) and opening downloaded attachments
|
||||
file_picker: ^8.0.0
|
||||
open_file: ^3.3.2
|
||||
open_filex: ^4.6.0
|
||||
mime: ^2.0.0
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user