fix platform exceptions

This commit is contained in:
Fabian Freund
2026-03-09 16:25:19 +01:00
parent 9700b3868a
commit 7939b73146
2 changed files with 24 additions and 13 deletions
@@ -19,6 +19,7 @@
*/ */
import 'dart:async'; import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart'; import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:nullability/nullability.dart'; import 'package:nullability/nullability.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart';
@@ -105,11 +106,16 @@ class BookmarksSearch extends _$BookmarksSearch {
Future<void> search(String query, {int limit = 10}) async { Future<void> search(String query, {int limit = 10}) async {
if (query.isNotEmpty) { if (query.isNotEmpty) {
await _service.searchBookmarks(query, limit: limit).then((value) { try {
if (!_streamController.isClosed) { await _service.searchBookmarks(query, limit: limit).then((value) {
_streamController.add(value.map((e) => e.guid).toSet()); if (!_streamController.isClosed) {
} _streamController.add(value.map((e) => e.guid).toSet());
}); }
});
} on PlatformException catch (e) {
if (e.code == 'OperationInterrupted') return;
rethrow;
}
} }
} }
@@ -135,12 +141,17 @@ class BookmarkSearchResults extends _$BookmarkSearchResults {
return; return;
} }
final results = await _service.searchBookmarks(query, limit: limit); try {
if (!ref.mounted) return; final results = await _service.searchBookmarks(query, limit: limit);
state = results if (!ref.mounted) return;
.map(BookmarkItem.parseRecursive) state = results
.whereType<BookmarkEntry>() .map(BookmarkItem.parseRecursive)
.toList(); .whereType<BookmarkEntry>()
.toList();
} on PlatformException catch (e) {
if (e.code == 'OperationInterrupted') return;
rethrow;
}
} }
@override @override
@@ -33,7 +33,7 @@ final class BookmarksSearchProvider
BookmarksSearch create() => BookmarksSearch(); BookmarksSearch create() => BookmarksSearch();
} }
String _$bookmarksSearchHash() => r'ac2ce51c4fd66c2c0e25bdf2475cf2fba57c9e0c'; String _$bookmarksSearchHash() => r'41053cbc1014e0fdd04d9510bf15c9896a9f752d';
abstract class _$BookmarksSearch extends $StreamNotifier<Set<String>> { abstract class _$BookmarksSearch extends $StreamNotifier<Set<String>> {
Stream<Set<String>> build(); Stream<Set<String>> build();
@@ -86,7 +86,7 @@ final class BookmarkSearchResultsProvider
} }
String _$bookmarkSearchResultsHash() => String _$bookmarkSearchResultsHash() =>
r'44af94b2234c817b08b0bde2dc68f9ab8d2d0a9a'; r'49ebd21a137bc09bbd67b692aacb2554b8364564';
abstract class _$BookmarkSearchResults extends $Notifier<List<BookmarkEntry>> { abstract class _$BookmarkSearchResults extends $Notifier<List<BookmarkEntry>> {
List<BookmarkEntry> build(); List<BookmarkEntry> build();