download_assets 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 53

download_assets #

This package download and uncompress to local storage all assets that are not included in your app. Some files, like images, sometimes, must not be included in your build.

Supported platforms #

  • iOS
  • Android

Methods #

  • startDownload - It start the assets download.
    • assetsUrl: Full url to zipped file
    • onProgress: It returns the download progress (optional)
    • onError: Called when any errors ocurr (optional)
    • onComplete: Called when the download is completed (optional)
  • clearAssets - Clear all downloaded assets from local storage.
  • assets Downloaded - Returns true if the assets were already downloaded, otherwise it' returns false.

Example #

You can find an example here: https://github.com/edjostenes/download_assets/tree/master/example

1.0.1 - May 18, 2020 #

  • First version.

1.0.2 - May 19, 2020 #

  • Added getter to local directory (assetsDir)
  • Added example file
  • Renamed progressCallback and errorCallback to onProgress and onError
  • Added onComplete callback

1.0.3 - May 20, 2020 #

  • Little adjustments

example/lib/main.dart

import 'dart:io';

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Download Assets Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Download Assets'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;

  MyHomePage({Key key, this.title}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  String message = "Press the download button to start the download";
  bool downloaded = false;

  @override
  void initState() {
    super.initState();
    DownloadAssetsController.init();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(message),
            if (downloaded)
              Container(
                width: 150,
                height: 150,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: FileImage(File("${DownloadAssetsController.assetsDir}/dart.jpeg")),
                    fit: BoxFit.fitWidth,
                  ),
                ),
              ),
            if (downloaded)
              Container(
                width: 150,
                height: 150,
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: FileImage(File("${DownloadAssetsController.assetsDir}/flutter.png")),
                    fit: BoxFit.fitWidth,
                  ),
                ),
              )
          ],
        ),
      ),
      floatingActionButton: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          FloatingActionButton(
            onPressed: _downloadAssets,
            tooltip: 'Increment',
            child: Icon(Icons.arrow_downward),
          ),
          SizedBox(width: 25,),
          FloatingActionButton(
            onPressed: _refresh,
            tooltip: 'Refresh',
            child: Icon(Icons.refresh),
          ),
        ],
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  Future _refresh() async {
    await DownloadAssetsController.clearAssets();
    await _downloadAssets();
  }

  Future _downloadAssets() async {
    bool assetsDownloaded = await DownloadAssetsController.assetsDirAlreadyExists();

    if (assetsDownloaded) {
      setState(() {
        message = "Click in refresh button to force download";
        print(message);
      });
      return;
    }

    try {
      await DownloadAssetsController.startDownload(
          assetsUrl: "https://github.com/edjostenes/download_assets/raw/master/assets.zip",
          onProgress: (progressValue) {
            downloaded = false;
            setState(() {
              message = "Downloading - ${progressValue.toStringAsFixed(2)}";
              print(message);
            });
          },
          onComplete: () {
            setState(() {
              message = "Download compeleted\nClick in refresh button to force download";
              downloaded = true;
            });
          },
          onError: (exception) {
            setState(() {
              downloaded = false;
              message = "Error: ${exception.toString()}";
            });
          }
      );
    } on DownloadAssetsException catch (e) {
      print(e.toString());
    }
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  download_assets: ^1.0.3

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:download_assets/download_assets.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
15
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
53
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform android

Because of import path [package:download_assets/download_assets.dart, package:download_assets/src/download_assets_controller.dart, package:path_provider/path_provider.dart, package:path_provider_linux/path_provider_linux.dart] that declares support for platforms: linux

Package does not support Flutter platform ios

Because of import path [package:download_assets/download_assets.dart, package:download_assets/src/download_assets_controller.dart, package:path_provider/path_provider.dart, package:path_provider_linux/path_provider_linux.dart] that declares support for platforms: linux

Package does not support Flutter platform macos

Because of import path [package:download_assets/download_assets.dart, package:download_assets/src/download_assets_controller.dart, package:path_provider/path_provider.dart, package:path_provider_linux/path_provider_linux.dart] that declares support for platforms: linux

Package does not support Flutter platform web

Because of import path [package:download_assets/download_assets.dart, package:download_assets/src/download_assets_controller.dart, package:path_provider/path_provider.dart] that declares support for platforms: android, ios, linux, macos

Package does not support Flutter platform windows

Because of import path [package:download_assets/download_assets.dart, package:download_assets/src/download_assets_controller.dart, package:path_provider/path_provider.dart] that declares support for platforms: android, ios, linux, macos

Package not compatible with SDK dart

because of import path [download_assets] that is in a package requiring null.

Health suggestions

Format lib/download_assets.dart.

Run flutter format to format lib/download_assets.dart.

Format lib/src/download_assets_controller.dart.

Run flutter format to format lib/src/download_assets_controller.dart.

Format lib/src/download_assets_exception.dart.

Run flutter format to format lib/src/download_assets_exception.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
archive ^2.0.13 2.0.13
dio ^3.0.9 3.0.9
flutter 0.0.0
path_provider ^1.6.8 1.6.11
Transitive dependencies
args 1.6.0
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
file 5.2.1
http_parser 3.1.4
intl 0.16.1
meta 1.1.8
path 1.7.0
path_provider_linux 0.0.1+2
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
platform 2.2.1
plugin_platform_interface 1.0.2
process 3.0.13
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8
xdg_directories 0.1.0
Dev dependencies
flutter_test