Skip to content

Commit 1d98c86

Browse files
authored
Version 3 (JaffaKetchup#11)
* 1/3 Progress? * Finished adding circle and rectangle and basic refactoring and comment addition * Finished Regions API Migration * Addition of background download * Example fixed * Moved to @OverRide API instead on Extension Methods * Create FUNDING.yml * Added requestIgnoreBatteryOptimizations() * Add Package Analyzer Action * Ready for prerelease 3.0.0-dev.1 * Improved some code comments and docs Renamed some files to more accurately fit purpose * Update issue templates (JaffaKetchup#13) * Better Documentation * Ready for release v3 * Change to v3 in pubspec.yaml
1 parent 689414c commit 1d98c86

19 files changed

+1826
-381
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ko_fi: JaffaKetchup
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---
22
name: Bug Report
33
about: Create a bug report to help us improve
4-
title: ''
4+
title: "[BUG]"
55
labels: bug
66
assignees: JaffaKetchup
77

88
---
99

10-
**Bug description**
10+
**What is the bug?**
1111
A clear and concise description of what the bug is.
1212

13-
**Expected behavior**
14-
A clear and concise description of what you expected to happen.
13+
**What do you expect to happen?**
14+
A clear and concise description of what you expected to happen, compared to what actually happened, in detail.
1515

1616
**Reproduction**
17-
Steps to reproduce the behavior:
17+
Steps to reproduce the behaviour:
1818
1. Go to '...'
1919
2. Click on '....'
2020
3. Scroll down to '....'
2121
4. See error
2222

2323
**Screenshots and recordings**
24-
If applicable, add screenshots to help explain your problem.
24+
To help us solve this issue quicker, attach screenshots and recordings if you can.
2525

2626
**Additional context**
2727
Add any other context about the problem here. Does the issue only happen on certain platforms, for example?
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Question/Help
3+
about: Ask for clarification or get help for a certain feature
4+
title: "[QUESTION]"
5+
labels: question
6+
assignees: JaffaKetchup
7+
8+
---
9+
10+
**What is the main problem?**
11+
A clear and concise description of what the problem is. Eg. How do I use this function?
12+
13+
**Give more detail about what you need help with or what your question is**
14+
Eg. How do I use this function to do this thing that I'm trying to do
15+
16+
**Is there a potential for this question to turn into a feature request?**
17+
If you're question can't be answered easily, do you want an inbuilt way to do what you want? How necessary is this to you (will it disrupt your whole app, or is it just a quality of life feature)?

.github/workflows/main.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run Dart Package Analyzer
2+
on: [push, pull_request, workflow_dispatch]
3+
4+
jobs:
5+
6+
package-analysis:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- uses: axel-op/dart-package-analyzer@v3
14+
id: analysis
15+
with:
16+
githubToken: ${{ secrets.GITHUB_TOKEN }}
17+
18+
- name: Check Scores
19+
env:
20+
TOTAL: ${{ steps.analysis.outputs.total }}
21+
TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
22+
run: |
23+
PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
24+
if (( $PERCENTAGE < 50 ))
25+
then
26+
echo Total score percentage below 50 percent. Improve the score!
27+
exit 1
28+
fi

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Changelog
22

3+
## [3.0.0] - 2021/07/04
4+
5+
* Last quick fixes
6+
* Publish to pub.dev
7+
* Use AlarmManager for background tasks to resolve issues
8+
9+
## [3.0.0-dev.2] - 2021/07/01
10+
11+
* Move to more appropriate date system for changelog
12+
* Rewritten documentation
13+
* Improved examples
14+
* Improved easy shape chooser
15+
16+
## [3.0.0-dev.1] - 30/06/2021
17+
18+
* Huge refactoring to make methods easier to use and more flexible
19+
* Addition of circle region
20+
* Refactoring of square region
21+
* Removal of tuple from main methods
22+
* Addition of ability to exclude pure sea tiles
23+
* Addition of multiple caching tables
24+
* Performance improvements
25+
* Add donation method
26+
* Add GitHub actions
27+
* Added easy shape chooser
28+
329
## [2.0.2] - 04/06/2021
430

531
* Publish to pub.dev

README.md

Lines changed: 94 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,138 @@
11
# flutter_map_tile_caching
22

3-
A plugin for the [`flutter_map`](https://pub.dev/packages/flutter_map) library. Adds full tile caching functionality and methods to download areas of tiles.
3+
A plugin for the [`flutter_map`](https://pub.dev/packages/flutter_map) library to provide an easy way to cache tiles and download map regions for offline use.
44

55
[![Pub](https://img.shields.io/pub/v/flutter_map_tile_caching.svg)](https://pub.dev/packages/flutter_map_tile_caching) [![likes](https://badges.bar/flutter_map_tile_caching/likes)](https://pub.dev/packages/flutter_map_tile_caching/score) [![pub points](https://badges.bar/flutter_map_tile_caching/pub%20points)](https://pub.dev/packages/flutter_map_tile_caching/score)
66
[![GitHub stars](https://img.shields.io/github/stars/JaffaKetchup/flutter_map_tile_caching.svg?style=social&label=Stars)](https://GitHub.com/JaffaKetchup/flutter_map_tile_caching/stargazers/) [![GitHub issues](https://img.shields.io/github/issues/JaffaKetchup/flutter_map_tile_caching.svg?style=social&label=Issues)](https://GitHub.com/JaffaKetchup/flutter_map_tile_caching/issues/) [![GitHub PRs](https://img.shields.io/github/issues-pr/JaffaKetchup/flutter_map_tile_caching.svg?style=social&label=Pull%20Requests)](https://GitHub.com/JaffaKetchup/flutter_map_tile_caching/pulls/)
77

8-
## Example
9-
10-
To view the example, copy the `main.dart` file inside the `example` directory, and run it inside your own new project. You'll need to add this package (see below) and `flutter_map` to your dependencies.
8+
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/N4N151INN)
119

1210
## Installation
1311

14-
To install this plugin, add the below code snippet to your `pubspec.yaml` file:
12+
To install this plugin, use the normal installation method:
1513

16-
```yaml
17-
flutter_map_tile_caching:
14+
```shell
15+
> flutter pub add flutter_map_tile_caching
1816
```
1917

20-
followed by `^`, then the most recent available pub.dev version (without the 'v') (currently [![Pub](https://img.shields.io/pub/v/flutter_map_tile_caching.svg)](https://pub.dev/packages/flutter_map_tile_caching)).
21-
If you urgently need the most recent version of this package that hasn't been published to pub.dev yet, use this code snippet instead (please note that this method is not recommended):
18+
If you urgently need the most recent version of this package that hasn't been published to pub.dev yet, use this code snippet instead in your pubspec.yaml (please note that this method is not recommended):
2219

2320
```yaml
2421
flutter_map_tile_caching:
2522
git:
2623
url: https://github.com/JaffaKetchup/flutter_map_tile_caching
2724
```
2825
29-
## Usage
30-
31-
Use it like any other package. You'll have access to all the things listed below.
26+
After installing the package, import it into the neccessary files in your project:
3227
3328
```dart
3429
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
3530
```
3631

37-
### New Tile Provider
32+
### Android
33+
34+
A few more steps are required on Android due to the background download functionality, unfortunately even if you do not intend to use the functionality. This is due to the way the dependency used to perform background downloading works.
35+
For these steps please go here: [background_fetch Installation Instructions For Android](https://github.com/transistorsoft/flutter_background_fetch/blob/master/help/INSTALL-ANDROID.md).
36+
37+
### iOS
38+
39+
A few more steps are required on iOS due to the background download functionality, even though this functionality is unfortunately currently blocked on iOS. This is due to the way the dependency used to perform background downloading works.
40+
For these steps please go here: [background_fetch Installation Instructions For iOS](https://github.com/transistorsoft/flutter_background_fetch/blob/master/help/INSTALL-IOS.md).
41+
You should not need to follow the instructions for `BackgroundFetch.scheduleTask`, but do so if you recieve build errors - the custom task identifiers asked for in the last step is exactly 'backgroundTileDownload'.
42+
Please note that this library has not been tested on iOS devices, so issues may arize. Please leave an issue if they do, and I'll try my best to debug and solve them.
43+
44+
## Example
45+
46+
To view the example project, just clone the .zip file in the example folder and unzip it to a local directory. You should be able to run it instantly on Android - iOS will require extra setup. Beware, this solution may be older than the latest example.
47+
48+
For the latest example, but no other code or build settings, just clone the main.dart file in the example folder to a local project, and import this library and `flutter_map` in the pubspec.yaml file.
49+
50+
Alternatively, if you just want to see how it works in real life, you can run the example app on an Android device by installing the APK file found in the 'example' directory.
51+
52+
## Functionality
53+
54+
This library provides 3 main functionalities and 4 main APIs:
55+
56+
- Automatic Tile Caching (`TileProvider` API & Caches API)
57+
- Region Downloading (`TileProvider` API, Regions API, Downloading API & Caches API)
58+
- Easy Shape Chooser (Regions API)
59+
60+
These all work together to give you all you need to implement fully offline maps in your Flutter app.
61+
62+
## [API Details](https://pub.dev/documentation/flutter_map_tile_caching/latest/flutter_map_tile_caching/flutter_map_tile_caching-library.html)
63+
64+
You can see every class, method, extension and enumerable in the [Dart auto generated docs (dartdoc)](https://pub.dev/documentation/flutter_map_tile_caching/latest/flutter_map_tile_caching/flutter_map_tile_caching-library.html). This contains everything available and a description on how to use them. You can also check the example for how all of these things fit together. However, for simplicity for new users to this project, the main/most useful/most common parts are below, and these can be looked up in the docs using the search functionality:
65+
66+
#### `StorageCachingTileProvider()`
67+
68+
Use this as the tile provider for your `FlutterMap()` to automatically cache tiles as your users pan (aka. browse) over them. Use the same 'instance' throughout your script to avoid duplicate conflicts.
69+
Read more about the caching behaviour below.
70+
71+
#### `downloadRegion()` and it's background counterpart
72+
73+
Use this to download large areas of a map before the user visits somewhere (for example before a hike in the wilderness).
74+
A region can currently be a rectangular region or a circular region. More types are planned for the future.
75+
Read more about the caching behaviour below.
76+
77+
#### Easy Shape Chooser
78+
79+
Use this as a 'layer' on your map to allow the user an easy way to select an area for downloading. Use the same 'instance' throughout your script to avoid duplicate conflicts.
80+
A region can currently be a rectangular region or a circular region. More types are planned for the future.
81+
This will be worked on in the future to bring better functionality.
82+
83+
### Migrate to v3 from v2
84+
85+
Unfortunately, because so much has changed, the best way to migrate is to rewrite the appropriate areas of your project with the new features.
86+
I've tried to make v3 super easy to understand and use, even with all the new functionality, so I hope you don't find this too hard.
87+
I cannot foresee another update as big as this any time in the future, so hopefully future major releases shouldn't need 'migrating' as such. I'm always planning functionality however!
88+
89+
## Offline/Caching Behaviour
90+
91+
Because this is an offline first package, it may act a little differently to how you expect. Both areas that interact with caching are detailed below:
92+
93+
### Whilst Browsing
94+
95+
'Browsing' in this library means panning, zooming and rotating through the map.
3896

39-
This plugin adds the new tile provider: `StorageCachingTileProvider(...)`.
40-
This takes the optional `cachedValidDuration` `Duration` argument which defaults to a duration of 31 days.
97+
When a new tile is browsed, and the user is online, the tile will be fetched from the server and cached with a record of when it's expiry date is (dictated by the `cachedValidDuration` on the tile provider).
98+
If this tile is browsed again, and the user is online, the tile will still be taken from cache, even if the user is online, unless the tile has expired, in which case it will be refetched and cached again. This is known as 'cache-first' caching.
99+
If this tile is browsed again, but the user is not online, the tile will be taken from cache, even if the tile has expired. The network request will still be made, however, and it will fail silently.
100+
If the user is not online, and the tile has not been cached yet, the request will fail with an error to the console, but the app will carry on working as normal.
41101

42-
When new tiles are loaded, this tile provider will cache them in a database cache. When these tiles are requested again, the tile will be taken from cache if it is younger than it's `cachedValidDuration`, otherwise the tile will be requested again. However, if the request fails (eg. there is no Internet connection), the tile should still be taken from cache.
102+
### When Downloading Regions
43103

44-
### New Classes, Methods & Functions
104+
Whilst using the `downloadRegion()` function (or it's background counterpart (see below)), every tile in the region will always be cached, even if the tile has been cached before but it hasn't expired.
105+
Every tile downloaded will then act like it has been browsed (see above).
45106

46-
This plugin adds the new classes: `StorageCachingTileProvider` & `TileStorageCachingManager`.
107+
## Background Region Downloading
47108

48-
#### `StorageCachingTileProvider`
109+
Instead of downloading in the foreground (on the main thread), there is an option on Android to start a download in the background.
49110

50-
You can call `loadTiles(...)` on `StorageCachingTileProvider(...)`, and pass in the appropriate bounds and min/max zoom levels. This will download and precache all the tiles in the specified area for all the specified zoom levels. It can be listened to for a `Tuple3<int, int, int>`, with the number of downloaded tiles, number of errored tiles (eg. tiles that couldn't be downloaded due to lack of Internet connection), and the total number of tiles to be downloaded, in that order. The `maxCachedTilesAmount` can be cached at once, which defaults to 20000.
111+
This has several major advantages including better core app performace, ability to continue whilst the user is interacting with other app components, and (potential) ability to continue even whilst the user is in other apps or the device is locked.
51112

52-
You can call `approximateTileAmount(...)` on `StorageCachingTileProvider`, and pass in the appropriate bounds and min/max zoom levels. This will return an `int` which is the approximate number of tiles within the specified area.
113+
The background download functionality is buggy and does not function as expected all the time on platforms other than Android, so that functionality has been disabled on all platforms except Android. This might change in the future, but there is no gurantee.
53114

54-
#### `TileStorageCachingManager`
115+
To have full background functionality including not being throttled by the system and being guaranteed to run even if the app is 'minimized', request the ignore battery optimizations permission by calling `requestIgnoreBatteryOptimizations()` before starting a background task. This will display a system interruption prompt to the user to allow or deny the permission. The background task will still run if the permission is denied, but only if the user is in the app - elsewhere, downloading is not guaranteed to be running.
55116

56-
You can call `cacheDbSize` on `TileStorageCachingManager`. This will return a `Future<int>` which is the size of the caching database in bytes. Divide by 1049000 to get the number of megabytes.
117+
## Limitations, Accuracy & Testing
57118

58-
You can call `cachedTilesAmount` on `TileStorageCachingManager`. This will return a `Future<int>` which is the total number of tiles currently cached.
119+
This package does not support the web platform (due to the usage of `dart:io` and the `sqflite` package).
59120

60-
You can call `maxCachedTilesAmount` on `TileStorageCachingManager`. This will return a `Future<int>` which is the maximum number of tiles allowed to be cached at any one time.
121+
The circle region functions get less accurate the larger the radius of the circle. To prevent interruptive errors, the values of the calculation have been clamped to a valid minimum and maximum, but this causes side effects. To prevent these side effects, only use circles smaller than the average size of a European country, and be cautious when using circles around extremes (the equator, the longitudes of 180 or -180, and the latiudes of -90 or 90). If selecting a large region or working around the aformentioned extremes, use rectangular regions instead. A fix for this may appear in the future
61122

62-
You can call `kDefaultMaxTileAmount` on `TileStorageCachingManager`. This will return an `int` which is the default maximum number of tiles allowed to be cached at any one time. This might differ to `maxCachedTilesAmount` if `changeMaxTileAmount(...)` has ever been called.
123+
This package has only been tested on Android devices (one real Android 8, one Android 8 emulator, and one Android 11 emulator).
63124

64-
You can call `changeMaxTileAmount(...)` on `TileStorageCachingManager`, and pass in the new max tile amount to change `maxCachedTilesAmount`.
125+
## Supporting Me
65126

66-
You can call `cleanCache()` on `TileStorageCachingManager`. This will clear all the cached tiles from the database forever, without warning.
127+
A donation through my Ko-Fi page would be infinitly appriciated:
128+
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/N4N151INN)
67129

68-
## Limitations
130+
but, if you can't or won't, a star on GitHub and a like on pub.dev would also go a long way!
69131

70-
This package does not support the web platform (due to the usage of `dart:io`) and the code has not been tested on desktop platforms.
132+
Every donation gives me fuel to continue my open-source projects and lets me know that I'm doing a good job.
71133

72134
## Credits
73135

74-
This code was originally created by [bugDim88](https://github.com/bugDim88), and improved upon by multiple people. You can see the original pull request here: [pull request #564 on fleaflet/flutter_map](https://github.com/fleaflet/flutter_map/pull/564). JaffaKetchup seperated the code into this external package on behalf of [bugDim88](https://github.com/bugDim88) & other contributors to keep the base package small. All credit therefore goes to [bugDim88](https://github.com/bugDim88) and the other contributors.
136+
The basis of this library was originally coded by [bugDim88](https://github.com/bugDim88), and improved upon by multiple people. You can see the original pull request here: [pull request #564 on fleaflet/flutter_map](https://github.com/fleaflet/flutter_map/pull/564).
75137

76-
If this package is beneficial to you, please leave a star on GitHub and a like on pub.dev!
138+
Since v2 here, other contributors have also been involved, who can be seen in GitHub. The only old part remaining that that coder coded is the database manager script (with all the SQL in it), but the aforementioned main coder still inspired the rest of this project and is therefore the 'founder'. Thanks to you, bugDim88!
18.9 MB
Binary file not shown.
2.23 MB
Binary file not shown.

0 commit comments

Comments
 (0)