From c5d6b2ad217fdbe613193036edd2fbea57719244 Mon Sep 17 00:00:00 2001 From: Daniele Ricci Date: Mon, 14 Aug 2023 17:48:35 +0200 Subject: [PATCH] fix: wait properly for avatar cache to be evicted close #73 --- lib/helpers/config.dart | 10 +++++----- lib/screens/about/about_screen.dart | 11 ++++++----- lib/screens/aircraft_select/aircraft_data_screen.dart | 4 ++-- screenshots/fake_data.dart | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/helpers/config.dart b/lib/helpers/config.dart index 372d6e8..ea74f26 100644 --- a/lib/helpers/config.dart +++ b/lib/helpers/config.dart @@ -20,7 +20,7 @@ class AppConfig extends ChangeNotifier { // load current aircraft try { final aircraftReader = await loadAircraft(_currentAircraftId!); - currentAircraft = aircraftReader.toAircraftData(); + await setCurrentAircraft(aircraftReader.toAircraftData()); } catch (e) { _log.info('Error loading current aircraft, cleaning everything ($e)'); _currentAircraftId = null; @@ -147,7 +147,7 @@ class AppConfig extends ChangeNotifier { AircraftData? get currentAircraft => _currentAircraft; - set currentAircraft(AircraftData? data) { + Future setCurrentAircraft(AircraftData? data) async { if (data != null) { _log.fine('Switching aircraft: ${data.callSign}'); } else { @@ -192,10 +192,10 @@ class AppConfig extends ChangeNotifier { notifyListeners(); } - void _clearPictureCache() { - aircraftPicture.evict(); + void _clearPictureCache() async { + await aircraftPicture.evict(); for (var name in pilotNames) { - getPilotAvatar(name).evict(); + await getPilotAvatar(name).evict(); } } } diff --git a/lib/screens/about/about_screen.dart b/lib/screens/about/about_screen.dart index df42dd6..67f2d8d 100644 --- a/lib/screens/about/about_screen.dart +++ b/lib/screens/about/about_screen.dart @@ -54,8 +54,8 @@ class _AboutScreenState extends State { final userpass = value[0]; final downloadTask = downloadAircraftData( _appConfig.currentAircraft!.url!, userpass, _downloadProvider) - .then((AircraftData aircraftData) { - _appConfig.currentAircraft = aircraftData; + .then((AircraftData aircraftData) async { + await _appConfig.setCurrentAircraft(aircraftData); _appConfig.updateAircraft(aircraftData); return aircraftData; }).catchError((error, StackTrace? stacktrace) { @@ -106,9 +106,10 @@ class _AboutScreenState extends State { destructiveOk: true, okCallback: () { _appConfig.pilotName = null; - _appConfig.currentAircraft = null; - Navigator.of(context, rootNavigator: true) - .popAndPushNamed('aircraft-data'); + _appConfig.setCurrentAircraft(null).whenComplete(() { + Navigator.of(context, rootNavigator: true) + .popAndPushNamed('aircraft-data'); + }); }, ); } diff --git a/lib/screens/aircraft_select/aircraft_data_screen.dart b/lib/screens/aircraft_select/aircraft_data_screen.dart index 2931776..2a04e15 100644 --- a/lib/screens/aircraft_select/aircraft_data_screen.dart +++ b/lib/screens/aircraft_select/aircraft_data_screen.dart @@ -77,8 +77,8 @@ class _SetAircraftDataScreenState extends State { final downloadTask = downloadAircraftData( _aircraftUrl!, _aircraftPassword, downloadProvider) - .then((AircraftData aircraftData) { - appConfig.currentAircraft = aircraftData; + .then((AircraftData aircraftData) async { + await appConfig.setCurrentAircraft(aircraftData); appConfig.addAircraft(aircraftData); return aircraftData; }).catchError((error, StackTrace? stacktrace) { diff --git a/screenshots/fake_data.dart b/screenshots/fake_data.dart index 23ec4c4..6b42f52 100644 --- a/screenshots/fake_data.dart +++ b/screenshots/fake_data.dart @@ -239,7 +239,7 @@ class FakeAppConfig extends AppConfig { ); await reader.open(); - currentAircraft = reader.toAircraftData(); + await setCurrentAircraft(reader.toAircraftData()); } }