Skip to content

Commit

Permalink
TICKET-B-17757:RefApp-Fixed App freezing on 'Download Maps' button pr…
Browse files Browse the repository at this point in the history
…essed. (#89)

- Since the API used to retrieve the list of downloadable regions
operates async and may take some time to provide a response,
this may appear to be the app not responding so
we have implemented a loading animation.

- We have implemented a check to determine whether the 'MapUpdate' option
should be displayed, ensuring that it is only visible
if it has not been initiated previously.

Signed-off-by: Gururaj <[email protected]>
  • Loading branch information
Guru-cm-here authored Jun 2, 2023
1 parent 0f028d9 commit 5be6ca1
Showing 1 changed file with 46 additions and 26 deletions.
72 changes: 46 additions & 26 deletions lib/download_maps/download_maps_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DownloadMapsScreen extends StatefulWidget {
class _DownloadMapsScreenState extends State<DownloadMapsScreen> {
static const double _kDownloadedMapMenuTitleHeight = 80;
late StreamSubscription<MapLoaderError> _errorStreamSubscription;
bool _isRegionsSearchInProgress = false;

@override
void initState() {
Expand Down Expand Up @@ -77,18 +78,29 @@ class _DownloadMapsScreenState extends State<DownloadMapsScreen> {
),
title: Text(AppLocalizations.of(context)!.downloadMapsTitle),
),
body: FutureBuilder(
future: Provider.of<MapLoaderController>(context, listen: false).getDownloadableRegions(),
builder: (context, snapshot) {
return ListView(
children: [
StorageSpace(),
if (controller.mapUpdateState != MapUpdateState.none) MapUpdateProgress(),
..._buildInstalledMapsList(context, snapshot.data),
_buildDownloadButton(context),
],
);
},
body: Stack(
children: [
FutureBuilder(
future: Provider.of<MapLoaderController>(context, listen: false).getDownloadableRegions(),
builder: (context, snapshot) {
return ListView(
children: [
StorageSpace(),
if (controller.mapUpdateState != MapUpdateState.none) MapUpdateProgress(),
..._buildInstalledMapsList(context, snapshot.data),
_buildDownloadButton(context),
],
);
},
),
if (_isRegionsSearchInProgress)
Container(
color: Colors.white54,
child: Center(
child: CircularProgressIndicator(),
),
),
],
),
),
);
Expand Down Expand Up @@ -245,18 +257,23 @@ class _DownloadMapsScreenState extends State<DownloadMapsScreen> {
);

void _openMapRegions(BuildContext context) async {
MapLoaderController controller = Provider.of<MapLoaderController>(context, listen: false);

controller.getDownloadableRegions().then((regions) {
setState(() {
_isRegionsSearchInProgress = true;
});
try {
MapLoaderController controller = Provider.of<MapLoaderController>(context, listen: false);
List<Region> regions = await controller.getDownloadableRegions();
Navigator.of(context).pushNamed(MapRegionsListScreen.navRoute, arguments: [regions]);
}).catchError(
(error) async {
Util.displayErrorSnackBar(
context,
Util.formatString(AppLocalizations.of(context)!.downloadMapsErrorText, [error.toString()]),
);
},
);
} catch (error) {
Util.displayErrorSnackBar(
context,
Util.formatString(AppLocalizations.of(context)!.downloadMapsErrorText, [error.toString()]),
);
} finally {
setState(() {
_isRegionsSearchInProgress = false;
});
}
}

Widget _buildDownloadedMapsHeader(BuildContext context, MapLoaderController controller) => Container(
Expand All @@ -269,9 +286,12 @@ class _DownloadMapsScreenState extends State<DownloadMapsScreen> {

void _checkMapUpdate(MapLoaderController controller) async {
try {
bool? isMapUpdateAvailable = await controller.isMapUpdateAvailable();
if (isMapUpdateAvailable && await showMapUpdatesAvailableDialog(context)) {
controller.performMapUpdate();
// Display the "MapUpdate" option only if it has not been initiated before.
if (controller.mapUpdateState == MapUpdateState.none) {
bool? isMapUpdateAvailable = await controller.isMapUpdateAvailable();
if (isMapUpdateAvailable && await showMapUpdatesAvailableDialog(context)) {
controller.performMapUpdate();
}
}
} catch (error) {
print('Error while checking map update $error');
Expand Down

0 comments on commit 5be6ca1

Please sign in to comment.