Skip to content

Commit 92de6c0

Browse files
committed
Update to v5.1.1
1 parent aaf42e2 commit 92de6c0

File tree

14 files changed

+99
-79
lines changed

14 files changed

+99
-79
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
---
88

9+
## [5.1.1] - 2022/09/12
10+
11+
* Fixed bugs
12+
* Updated dependencies
13+
* Improved example application
14+
915
## [5.1.0] - 2022/08/09
1016

1117
* Added import/export functionality

example/currentAppVersion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.1.2
1+
5.1.3

example/lib/screens/import_store/import_store.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,11 @@ class _ImportStorePopupState extends State<ImportStorePopup> {
3737
: FutureBuilder<bool>(
3838
future: importingStores.values.toList()[i],
3939
builder: (context, successful) => ListTile(
40-
leading: FutureBuilder<bool>(
41-
future: importingStores.values.toList()[i],
42-
builder: (context, successful) => !successful.hasData
43-
? const CircularProgressIndicator()
44-
: successful.data!
45-
? const Icon(Icons.done, color: Colors.green)
46-
: const Icon(Icons.error, color: Colors.red),
47-
),
40+
leading: !successful.hasData
41+
? const CircularProgressIndicator()
42+
: successful.data!
43+
? const Icon(Icons.done, color: Colors.green)
44+
: const Icon(Icons.error, color: Colors.red),
4845
title: Text(importingStores.keys.toList()[i]),
4946
subtitle: successful.data ?? true
5047
? null

example/lib/screens/main/pages/update/update.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'dart:io';
22

3+
import 'package:better_open_file/better_open_file.dart';
34
import 'package:flutter/material.dart';
45
import 'package:flutter/services.dart' show rootBundle;
56
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
67
import 'package:http/http.dart' as http;
7-
import 'package:open_file/open_file.dart';
88
import 'package:path/path.dart' as p;
99
import 'package:version/version.dart';
1010

example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ description: The example application for 'flutter_map_tile_caching', showcasing
33
it's functionality and use-cases.
44
publish_to: "none"
55

6-
version: 5.1.0+1
6+
version: 5.1.3
77

88
environment:
99
sdk: ">=2.15.0 <3.0.0"
1010
flutter: ">=3.0.0"
1111

1212
dependencies:
1313
badges: ^2.0.2
14+
better_open_file: ^3.6.3
1415
flutter:
1516
sdk: flutter
1617
flutter_foreground_task: ^3.7.3
@@ -22,7 +23,6 @@ dependencies:
2223
http: ^0.13.4
2324
intl: ^0.17.0
2425
latlong2: ^0.8.1
25-
open_file: ^3.2.1
2626
osm_nominatim: ^2.0.1
2727
path: ^1.8.1
2828
provider: ^6.0.3

lib/src/internal/exts.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ extension DirectoryExtensions on Directory {
2525
name,
2626
),
2727
);
28+
29+
/// A safer version of [exists], but checks that the directory exists before listing it's contents
30+
///
31+
/// Returns same result as [list] in future.
32+
Future<Stream<FileSystemEntity>> listWithExists({
33+
bool recursive = false,
34+
bool followLinks = true,
35+
}) async {
36+
if (!await exists()) return const Stream.empty();
37+
return list(
38+
recursive: recursive,
39+
followLinks: followLinks,
40+
);
41+
}
2842
}
2943

3044
extension IterableNumExts on Iterable<num> {

lib/src/internal/image_provider.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ class FMTCImageProvider extends ImageProvider<FMTCImageProvider> {
195195
File? currentOldestFile;
196196
DateTime? currentOldestDateTime;
197197

198-
await for (final FileSystemEntity e
199-
in provider.storeDirectory.access.tiles.list()) {
198+
await for (final FileSystemEntity e in await provider
199+
.storeDirectory.access.tiles
200+
.listWithExists()) {
200201
if (e is! File) break;
201202

202203
currentIteration++;

lib/src/root/migrator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class RootMigrator {
4040
if (root == null) return false;
4141

4242
try {
43-
await root.list().whereType<Directory>().asyncMap((e) async {
43+
await (await root.listWithExists())
44+
.whereType<Directory>()
45+
.asyncMap((e) async {
4446
final StoreDirectory store = StoreDirectory(
4547
_rootDirectory,
4648
p.basename(e.absolute.path),

lib/src/root/recovery.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:meta/meta.dart';
55
import 'package:path/path.dart' as p;
66
import 'package:stream_transform/stream_transform.dart';
77

8+
import '../internal/exts.dart';
89
import '../internal/recovery/decode.dart';
910
import '../internal/recovery/encode.dart';
1011
import '../regions/downloadable_region.dart';
@@ -42,15 +43,15 @@ class RootRecovery {
4243
/// Get a list of all recoverable regions
4344
///
4445
/// See [failedRegions] for regions that correspond to failed/stopped downloads.
45-
Future<List<Future<RecoveredRegion>>> get recoverableRegions => _metadata
46-
.list()
47-
.map(
48-
(e) => e is File && p.extension(e.path, 2) == '.recovery.ini'
49-
? decode(e)
50-
: null,
51-
)
52-
.whereType<Future<RecoveredRegion>>()
53-
.toList();
46+
Future<List<Future<RecoveredRegion>>> get recoverableRegions async =>
47+
(await _metadata.listWithExists())
48+
.map(
49+
(e) => e is File && p.extension(e.path, 2) == '.recovery.ini'
50+
? decode(e)
51+
: null,
52+
)
53+
.whereType<Future<RecoveredRegion>>()
54+
.toList();
5455

5556
/// Get a list of all recoverable regions that correspond to failed/stopped downloads
5657
///

lib/src/root/statistics.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ class RootStats {
121121
///
122122
/// For synchronous version, see [storesAvailable]. Note that this statistic is not cached for performance, as the effect would be negligible.
123123
Future<List<StoreDirectory>> get storesAvailableAsync async =>
124-
(await _access.stores
125-
.list()
124+
(await (await _access.stores.listWithExists())
126125
.map(
127126
(e) => e is Directory
128127
? StoreDirectory(
@@ -143,12 +142,14 @@ class RootStats {
143142
/// Technically just sums up the size of all sub-stores, thus ignoring any cached root statistics, etc.
144143
///
145144
/// Includes all files in all stores, not necessarily just tiles.
146-
double get rootSize => double.parse(
145+
double get rootSize =>
146+
double.tryParse(
147147
_csgSync(
148148
'size',
149149
() => storesAvailable.map((e) => e.stats.storeSize).sum,
150150
),
151-
);
151+
) ??
152+
0;
152153

153154
/// Retrieve the size of the root in kibibytes (KiB)
154155
///
@@ -157,42 +158,48 @@ class RootStats {
157158
/// Technically just sums up the size of all sub-stores, thus ignoring any cached root statistics, etc.
158159
///
159160
/// Includes all files in all stores, not necessarily just tiles.
160-
Future<double> get rootSizeAsync async => double.parse(
161+
Future<double> get rootSizeAsync async =>
162+
double.tryParse(
161163
await _csgAsync(
162164
'size',
163165
() async => (await Future.wait(
164166
(await storesAvailableAsync).map((e) => e.stats.storeSizeAsync),
165167
))
166168
.sum,
167169
),
168-
);
170+
) ??
171+
0;
169172

170173
/// Retrieve the number of stored tiles in all sub-stores
171174
///
172175
/// For asynchronous version, see [rootLengthAsync].
173176
///
174177
/// Only includes tiles stored, not necessarily all files.
175-
int get rootLength => int.parse(
178+
int get rootLength =>
179+
int.tryParse(
176180
_csgSync(
177181
'length',
178182
() => storesAvailable.map((e) => e.stats.storeLength).sum,
179183
),
180-
);
184+
) ??
185+
0;
181186

182187
/// Retrieve the number of stored tiles in all sub-stores
183188
///
184189
/// For synchronous version, see [rootLength].
185190
///
186191
/// Only includes tiles stored, not necessarily all files.
187-
Future<int> get rootLengthAsync async => int.parse(
192+
Future<int> get rootLengthAsync async =>
193+
int.tryParse(
188194
await _csgAsync(
189195
'length',
190196
() async => (await Future.wait(
191197
(await storesAvailableAsync).map((e) => e.stats.storeLengthAsync),
192198
))
193199
.sum,
194200
),
195-
);
201+
) ??
202+
0;
196203

197204
/// Watch for changes in the current cache
198205
///

0 commit comments

Comments
 (0)