[READ ONLY MIRROR] Open Source TikTok alternative built on AT Protocol github.com/sprksocial/client
flutter atproto video dart
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: widget lifecycle & mounted checks in providers

+46 -18
+36 -18
lib/src/features/feed/providers/feed_provider.dart
··· 116 116 } catch (e, stackTrace) { 117 117 _logger.e('Error in loadAndUpdateFirstLoad: $e', stackTrace: stackTrace); 118 118 _lastErrorTime = DateTime.now(); 119 - state = state.copyWith(loadingFirstLoad: false, error: true); 119 + if (ref.mounted) { 120 + state = state.copyWith(loadingFirstLoad: false, error: true); 121 + } 120 122 } finally { 121 123 _isLoadingInProgress = false; 122 - if (state.loadingFirstLoad) { 124 + if (ref.mounted && state.loadingFirstLoad) { 123 125 state = state.copyWith(loadingFirstLoad: false); 124 126 } 125 127 } ··· 204 206 extraInfo, 205 207 ); 206 208 209 + if (!ref.mounted) return; 210 + 207 211 if (filteredPosts.isEmpty) { 208 212 state = state.copyWith( 209 213 cursor: cursor, ··· 244 248 stackTrace: stackTrace, 245 249 ); 246 250 // Ensure loadingFirstLoad is set to false even on error 247 - state = state.copyWith(loadingFirstLoad: false, error: true); 251 + if (ref.mounted) { 252 + state = state.copyWith(loadingFirstLoad: false, error: true); 253 + } 248 254 } 249 255 } 250 256 ··· 312 318 if (fetchedPosts.isEmpty) { 313 319 if (fetchedCount == 0 || cursor == null) { 314 320 await endOfNetworkFeed(); 315 - state = state.copyWith( 316 - loadingFirstLoad: false, 317 - isEndOfNetworkFeed: true, 318 - ); 321 + if (ref.mounted) { 322 + state = state.copyWith( 323 + loadingFirstLoad: false, 324 + isEndOfNetworkFeed: true, 325 + ); 326 + } 319 327 break; 320 328 } 321 329 if (fetchedCount > 0) { 322 330 consecutiveEmptyResults++; 323 331 if (consecutiveEmptyResults >= maxConsecutiveEmpty) { 324 332 await endOfNetworkFeed(); 325 - state = state.copyWith( 326 - loadingFirstLoad: false, 327 - isEndOfNetworkFeed: true, 328 - ); 333 + if (ref.mounted) { 334 + state = state.copyWith( 335 + loadingFirstLoad: false, 336 + isEndOfNetworkFeed: true, 337 + ); 338 + } 329 339 break; 330 340 } 331 341 } 332 - state = state.copyWith(cursor: cursor, loadingFirstLoad: false); 342 + if (ref.mounted) { 343 + state = state.copyWith(cursor: cursor, loadingFirstLoad: false); 344 + } 333 345 continue; 334 346 } 335 347 ··· 339 351 if (newPosts.isEmpty) { 340 352 if (fetchedCount == 0 || cursor == null) { 341 353 await endOfNetworkFeed(); 342 - state = state.copyWith( 343 - loadingFirstLoad: false, 344 - isEndOfNetworkFeed: true, 345 - ); 354 + if (ref.mounted) { 355 + state = state.copyWith( 356 + loadingFirstLoad: false, 357 + isEndOfNetworkFeed: true, 358 + ); 359 + } 346 360 break; 347 361 } 348 - state = state.copyWith(cursor: cursor, loadingFirstLoad: false); 362 + if (ref.mounted) { 363 + state = state.copyWith(cursor: cursor, loadingFirstLoad: false); 364 + } 349 365 continue; 350 366 } 351 367 ··· 359 375 } catch (e, stackTrace) { 360 376 _logger.e('Error prefetching feed: $e', stackTrace: stackTrace); 361 377 _lastErrorTime = DateTime.now(); 362 - state = state.copyWith(error: true, loadingFirstLoad: false); 378 + if (ref.mounted) { 379 + state = state.copyWith(error: true, loadingFirstLoad: false); 380 + } 363 381 rethrow; 364 382 } finally { 365 383 _isFetching = false;
+10
lib/src/features/notifications/providers/notification_provider.dart
··· 54 54 reasons: reasons, 55 55 ); 56 56 57 + if (!ref.mounted) return; 58 + 57 59 state = state.copyWith( 58 60 notifications: response.notifications, 59 61 cursor: response.cursor, ··· 67 69 error: e, 68 70 stackTrace: stackTrace, 69 71 ); 72 + 73 + if (!ref.mounted) return; 74 + 70 75 state = state.copyWith( 71 76 isLoading: false, 72 77 isRefreshing: false, ··· 94 99 reasons: reasons, 95 100 ); 96 101 102 + if (!ref.mounted) return; 103 + 97 104 state = state.copyWith( 98 105 notifications: [...state.notifications, ...response.notifications], 99 106 cursor: response.cursor, ··· 105 112 error: e, 106 113 stackTrace: stackTrace, 107 114 ); 115 + 116 + if (!ref.mounted) return; 117 + 108 118 state = state.copyWith( 109 119 isLoadingMore: false, 110 120 hasError: true,