flutter_android_downloader 0.0.2+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

Flutter Android Downloader #

Pub

flutter_android_downloader 一个调用安卓系统下载管理器的插件

添加依赖 #

dependencies:
  flutter_android_downloader: ^0.0.2

创建下载 #

int downloadId = FlutterAndroidDownloader.download("url", "path", "fileName");

参数说明

  • url: 下载地址

  • path: 下载路径,目前只能保存在SD卡目下,比如保存到SD卡A根目录就填写/A

  • fileName: 保存的文件名称

监听下载完成回调信息 #

FlutterAndroidDownloader.listen((data) {
  print("success $data");
  // to do something
});
/// 打印信息: success {media_type: application/vnd.android.package-archive, local_uri: file:///storage/emulated/0/ABC/qq.apk, total_size: 80899231, title: qq.apk, uri: https://qd.myapp.com/myapp/qqteam/AndroidQQ/mobileqq_android.apk, status: 8}

具体返回参数信息参考 DownloadManager API

完成使用的示例 #

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

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

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: IconButton(
            icon: Icon(Icons.file_download),
            onPressed: () {
              download();
            },
          ),
        ),
      ),
    );
  }

  void initState() {
    super.initState();
    FlutterAndroidDownloader.listen((data) {
      print("success $data");
      // to do something
    });
  }

  void download() async {
    int id = await FlutterAndroidDownloader.download(
        "https://qd.myapp.com/myapp/qqteam/AndroidQQ/mobileqq_android.apk",
        "/ABC",
        "qq.apk");
    print("ID => $id");

    /// to do something
  }
}

0.0.2+1 #

  • fix bug

0.0.2 #

  • Added download completion callback information

0.0.1+2 #

  • update README.md.

0.0.1 #

  • initial release.

example/lib/main.dart

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

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

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: IconButton(
            icon: Icon(Icons.file_download),
            onPressed: () {
              download();
            },
          ),
        ),
      ),
    );
  }

  void initState() {
    super.initState();
    FlutterAndroidDownloader.listen((data) {
      print("success $data");
      // to do something
    });
  }

  void download() async {
    int id = await FlutterAndroidDownloader.download(
        "https://qd.myapp.com/myapp/qqteam/AndroidQQ/mobileqq_android.apk",
        "/ABC",
        "qq.apk");
    print("ID => $id");

    /// to do something
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_android_downloader: ^0.0.2+1

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

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Health suggestions

Fix lib/flutter_android_downloader.dart. (-0.50 points)

Analysis of lib/flutter_android_downloader.dart reported 1 hint:

line 9 col 29: Cancel instances of dart.async.StreamSubscription.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Maintenance suggestions

The package description is too short. (-13 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.

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
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test