Matthias Nott
2026-04-01 59a9917225dd64cdc77bfcd3b280054728b26cd1
lib/services/message_store.dart
....@@ -2,6 +2,7 @@
22 import 'dart:convert';
33 import 'dart:io';
44
5
+import 'package:flutter/services.dart';
56 import 'package:path_provider/path_provider.dart';
67
78 import '../models/message.dart';
....@@ -14,14 +15,32 @@
1415 static Timer? _debounceTimer;
1516 static final Map<String, List<Message>> _pendingSaves = {};
1617
18
+ static const _backupChannel =
19
+ MethodChannel('com.mnsoft.pailot/backup');
20
+
1721 /// Initialize the base directory for message storage.
22
+ /// On iOS, the directory is excluded from iCloud / iTunes backup so that
23
+ /// large base64 image attachments do not bloat the user's cloud storage.
24
+ /// Messages can be re-fetched from the server if needed.
1825 static Future<Directory> _getBaseDir() async {
1926 if (_baseDir != null) return _baseDir!;
2027 final appDir = await getApplicationDocumentsDirectory();
2128 _baseDir = Directory('${appDir.path}/messages');
22
- if (!await _baseDir!.exists()) {
29
+ final created = !await _baseDir!.exists();
30
+ if (created) {
2331 await _baseDir!.create(recursive: true);
2432 }
33
+ // Exclude from iCloud / iTunes backup (best-effort, iOS only).
34
+ if (Platform.isIOS) {
35
+ try {
36
+ await _backupChannel.invokeMethod<void>(
37
+ 'excludeFromBackup',
38
+ _baseDir!.path,
39
+ );
40
+ } catch (_) {
41
+ // Non-fatal: if the channel call fails, backup exclusion is skipped.
42
+ }
43
+ }
2544 return _baseDir!;
2645 }
2746