flutter_map_tile_downloader 0.0.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

flutter_map_tile_downloader #

Tile download by drag draw area

Features #

Area selection by drag draw
Download multiple zoom levels
Show download progress
Download completed event
Custom Texts

Example image #

Usage #

Add flutter_map, dio and flutter_map_arcgis to your pubspec:

dependencies:
  flutter_map: any
  flutter_map_arcgis: any
  dio: any 
  permission_handler: any 
  flutter_range_slider: any 
  path_provider: any 
  shared_preferences: any 
  percent_indicator: any 

Usage example

  import 'package:flutter/material.dart';
  import 'dart:async';
  import 'package:flutter/services.dart';
  import 'package:flutter_map/flutter_map.dart';
  import 'package:flutter_map_tile_downloader/flutter_map_tile_downloader.dart';
  import 'package:latlong/latlong.dart';
  
  void main() => runApp(MyApp());
  
  class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() => _MyAppState();
  }
  
  class _MyAppState extends State<MyApp> {
  
    bool _tileSelecting = false;
    bool _offline = false;
  
    OfflineTile _off_line_tile = OfflineTile(
        minZoom:0,
        maxZoom:0,
        urlTemplate:"",
    );
  
    @override
    void initState()  {
      super.initState();
      getOfflineTile();
    }
    void getOfflineTile() async {
  
          OfflineTile off_line_tile =  await getOfflineTileData();
          setState(() {
            _off_line_tile = off_line_tile;
          });
  
    }
    void startTileSelect(bool value) async {
      setState(() {
        _tileSelecting = value;
      });
  
    }
    void onCompleted() async {
  
      getOfflineTile();
      setState(() {
        _tileSelecting : false;
      });
    }
  
    void showOffline() async {
        setState(() {
          _offline = !_offline;
        });
    }
  
    @override
    Widget build(BuildContext context)  {
  
  
      List<LayerOptions> layers = [];
  
      if (_offline && _off_line_tile.urlTemplate != null) {
        layers.add(
            TileLayerOptions(
              tileProvider: FileTileProvider(),
              maxZoom: _off_line_tile.maxZoom,
              urlTemplate: _off_line_tile.urlTemplate,
            )
        );
      } else {
        layers.add(
        TileLayerOptions(
          urlTemplate: 'http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
          subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
          tileProvider: CachedNetworkTileProvider(),
        )
        );
      }
  
      if(_tileSelecting){
        layers.add(
            TileDownloadLayerOptions(
              onComplete: onCompleted,
              urlTemplate: 'http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
              subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
              minZoom: 8,
              maxZoom: 12,
              downloadTxt: "Download",
              selectZoomLevelTxt: "Please select zoom levels"
            )
        );
      }
  
      return MaterialApp(
        home: Scaffold(
          appBar: AppBar(title: Text('Tile downloader exmample')),
          body: Padding(
            padding: EdgeInsets.all(8.0),
            child: Stack(
              children: [
                FlutterMap(
                  options: MapOptions(
                    center: LatLng(32.91081899999999, -92.734876),
                    zoom: 8.0,
                    minZoom: _offline && _off_line_tile.urlTemplate != null ? _off_line_tile.minZoom : 0,
                    maxZoom: _offline && _off_line_tile.urlTemplate != null ? _off_line_tile.maxZoom :18,
                    plugins: [
                      TileDownloaderPlugin()
                    ],
                  ),
                  layers: layers,
                ),
                Positioned(
                    bottom: 65,
                    right: 10,
                    child: RaisedButton(
                        onPressed: () {
                          startTileSelect(!_tileSelecting);
                        },
  
                        child: _tileSelecting
                            ? Text("Stop tile download")
                            : Text("Tile download")
                    )),
                Visibility(
                  child: Positioned(
                      bottom: 120,
                      right: 10,
                      child: RaisedButton(
                        onPressed: (_off_line_tile.urlTemplate != null)
                            ? () {
                          showOffline();
                        }
                            : null,
  
                        child: _offline
                            ? Text("Show online tile")
                            : Text("Show offine tile" ),
                      )),
                  visible: (_off_line_tile.urlTemplate != null),
                )
              ],
            ),
          ),
        ),
      );
    }
  }

Run the example #

See the example/ folder for a working example app.

required permission for Android

required permission for IOS

Storage

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_tile_downloader/flutter_map_tile_downloader.dart';


import 'package:latlong/latlong.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  bool _tileSelecting = false;
  bool _offline = false;

  OfflineTile _off_line_tile = OfflineTile(
      minZoom:0,
      maxZoom:0,
      urlTemplate:"",
  );

  @override
  void initState()  {
    super.initState();
    getOfflineTile();
  }
  void getOfflineTile() async {

        OfflineTile off_line_tile =  await getOfflineTileData();
        setState(() {
          _off_line_tile = off_line_tile;
        });

  }
  void startTileSelect(bool value) async {
    setState(() {
      _tileSelecting = value;
    });

  }
  void onCompleted() async {

    getOfflineTile();
    setState(() {
      _tileSelecting : false;
    });
  }

  void showOffline() async {
      setState(() {
        _offline = !_offline;
      });
  }

  @override
  Widget build(BuildContext context)  {


    List<LayerOptions> layers = [];

    if (_offline && _off_line_tile.urlTemplate != null) {
      layers.add(
          TileLayerOptions(
            tileProvider: FileTileProvider(),
            maxZoom: _off_line_tile.maxZoom,
            urlTemplate: _off_line_tile.urlTemplate,
          )
      );
    } else {
      layers.add(
      TileLayerOptions(
        urlTemplate: 'http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
        subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
        tileProvider: CachedNetworkTileProvider(),
      )
      );
    }

    if(_tileSelecting){
      layers.add(
          TileDownloadLayerOptions(
            onComplete: onCompleted,
            urlTemplate: 'http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
            subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
            minZoom: 8,
            maxZoom: 12,
            downloadTxt: "Download",
            selectZoomLevelTxt: "Please select zoom levels"
          )
      );
    }

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Tile downloader exmample')),
        body: Padding(
          padding: EdgeInsets.all(8.0),
          child: Stack(
            children: [
              FlutterMap(
                options: MapOptions(
                  center: LatLng(32.91081899999999, -92.734876),
                  zoom: 8.0,
                  minZoom: _offline && _off_line_tile.urlTemplate != null ? _off_line_tile.minZoom : 0,
                  maxZoom: _offline && _off_line_tile.urlTemplate != null ? _off_line_tile.maxZoom :18,
                  plugins: [
                    TileDownloaderPlugin()
                  ],
                ),
                layers: layers,
              ),
              Positioned(
                  bottom: 65,
                  right: 10,
                  child: RaisedButton(
                      onPressed: () {
                        startTileSelect(!_tileSelecting);
                      },

                      child: _tileSelecting
                          ? Text("Stop tile download")
                          : Text("Tile download")
                  )),
              Visibility(
                child: Positioned(
                    bottom: 120,
                    right: 10,
                    child: RaisedButton(
                      onPressed: (_off_line_tile.urlTemplate != null)
                          ? () {
                        showOffline();
                      }
                          : null,

                      child: _offline
                          ? Text("Show online tile")
                          : Text("Show offine tile" ),
                    )),
                visible: (_off_line_tile.urlTemplate != null),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_map_tile_downloader: ^0.0.8

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_map_tile_downloader/flutter_map_tile_downloader.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:flutter_map_tile_downloader/flutter_map_tile_downloader.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:flutter_map_tile_downloader/flutter_map_tile_downloader.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:flutter_map_tile_downloader/flutter_map_tile_downloader.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:flutter_map_tile_downloader/flutter_map_tile_downloader.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • flutter_map_tile_downloader that is a package requiring null.

Health suggestions

Fix lib/tileDownloader/tile_download_layer.dart. (-6.31 points)

Analysis of lib/tileDownloader/tile_download_layer.dart reported 13 hints, including:

line 108 col 37: The exception variable 'e' isn't used, so the 'catch' clause can be removed.

line 178 col 28: Avoid using braces in interpolation when not needed.

line 185 col 20: Avoid using braces in interpolation when not needed.

line 190 col 22: Avoid using braces in interpolation when not needed.

line 194 col 19: The value of the local variable 'savedTile' isn't used.

Maintenance issues and suggestions

Support latest dependencies. (-40 points)

The version constraint in pubspec.yaml does not support the latest published versions for 4 dependencies (flutter_map, path_provider, permission_handler, shared_preferences).

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
dio 3.0.9 3.0.9
flutter 0.0.0
flutter_map 0.8.2 0.8.2 0.10.1
flutter_range_slider 1.4.0 1.4.0
path_provider 1.6.5 1.6.5 1.6.11
percent_indicator ^2.1.1+1 2.1.5
permission_handler 4.4.0 4.4.0 5.0.1+1
shared_preferences 0.5.6+3 0.5.6+3 0.5.8
Transitive dependencies
ansicolor 1.0.2
async 2.4.2
cached_network_image 2.2.0+1 2.3.0-rc
charcode 1.1.3
clock 1.0.1
collection 1.14.12 1.14.13
console_log_handler 1.1.6
convert 2.1.1
crypto 2.1.5
file 5.2.1
flutter_cache_manager 1.4.1
flutter_image 3.0.0
flutter_web_plugins 0.0.0
http 0.12.1
http_parser 3.1.4
intl 0.16.1
latlong 0.6.1
logging 0.11.4
matcher 0.12.8
meta 1.1.8 1.2.2
path 1.7.0
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
pedantic 1.9.0 1.9.2
permission_handler_platform_interface 1.0.0 2.0.1
platform 2.2.1
plugin_platform_interface 1.0.2
positioned_tap_detector 1.0.3
quiver 2.1.3
rxdart 0.24.1
shared_preferences_macos 0.0.1+10
shared_preferences_platform_interface 1.0.4
shared_preferences_web 0.1.2+7
sky_engine 0.0.99
source_span 1.7.0
sqflite 1.3.1
sqflite_common 1.0.2+1
stack_trace 1.9.5
string_scanner 1.0.5
synchronized 2.2.0+1
term_glyph 1.1.0
transparent_image 1.0.0
tuple 1.0.3
typed_data 1.1.6 1.2.0
uuid 2.2.0
validate 1.7.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test