flutter_github_releases_service 0.4.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 58

flutter_github_releases_service #

Use github releases to update the app.

Note: This has only been tested on Android.

This library is developed on the flutter master branch #

install #

dependencies:
  flutter_github_releases_service:

Configure Application #

'android\app\src\main\AndroidManifest.xml' #

See also: flutter_downloader

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.example">

    <!-- new -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <!-- new -->

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application android:name="io.flutter.app.FlutterApplication" android:label="example" android:icon="@mipmap/ic_launcher">
        <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data android:name="flutterEmbedding" android:value="2" />
        
        <!-- new -->
        <provider android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider" android:authorities="${applicationId}.flutter_downloader.provider" android:exported="false" android:grantUriPermissions="true">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/>
        </provider>

        <provider android:name="androidx.work.impl.WorkManagerInitializer" android:authorities="${applicationId}.workmanager-init" android:enabled="false" android:exported="false" />

        <provider android:name="vn.hunghd.flutterdownloader.FlutterDownloaderInitializer" android:authorities="${applicationId}.flutter-downloader-init" android:exported="false">
            <!-- changes this number to configure the maximum number of concurrent tasks -->
            <meta-data android:name="vn.hunghd.flutterdownloader.MAX_CONCURRENT_TASKS" android:value="5" />
        </provider>
        <!-- new -->
        
    </application>
</manifest>

Usage example: #

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  GithubReleasesService grs = GithubReleasesService(
    owner: 'januwA',
    repo: 'flutter_anime_app',
  );
  @override
  void dispose() {
    grs.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: FutureBuilder(
          future: grs.initialized,
          builder: (c, snap) {
            if (snap.connectionState == ConnectionState.done) {
              return RaisedButton(
                onPressed: () async {
                  print('latestVersion: ' + await grs.latestVersion);
                  print('localVersion: ' + await grs.localVersion);
                  print(await grs.isNeedUpdate);

                  if (await grs.isNeedUpdate) {
                    try {
                      grs.downloadApk(
                        downloadUrl:
                            grs.latestSync.assets.first.browserDownloadUrl,
                        apkName: grs.latestSync.assets.first.name,
                      );
                    } catch (e) {
                      print('安装失败: $e');
                    }
                  }
                },
                child: Text('Test'),
              );
            }
            return SizedBox();
          },
        ),
      ),
    );
  }
}

[0.4.0] - 2019-10-19 #

  • 修复BUG,使用方式发生变化

[0.3.0] - 2019-10-19 #

  • 升级依赖,重大变更

[0.2.1] - 2019-9-24 #

  • 升级依赖

[0.2.0] - 2019-8-20 #

  • 优化代码
  • 增加sync属性调用

[0.1.0] - 2019-8-8 #

  • Use github releases to update the app.

example/lib/main.dart

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

void main() => runApp(MaterialApp(home: HomePage()));

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  GithubReleasesService grs = GithubReleasesService(
    owner: 'januwA',
    repo: 'flutter_anime_app',
  );
  @override
  void dispose() {
    grs.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: FutureBuilder(
          future: grs.initialized,
          builder: (c, snap) {
            if (snap.connectionState == ConnectionState.done) {
              return RaisedButton(
                onPressed: () async {
                  print('latestVersion: ' + await grs.latestVersion);
                  print('localVersion: ' + await grs.localVersion);
                  print(await grs.isNeedUpdate);

                  if (true) {
                    try {
                      grs.downloadApk(
                        downloadUrl:
                            grs.latestSync.assets.first.browserDownloadUrl,
                        apkName: grs.latestSync.assets.first.name,
                      );
                    } catch (e) {
                      print('Install Error: $e');
                    }
                  }
                },
                child: Text('Test'),
              );
            }
            return SizedBox();
          },
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_github_releases_service: ^0.4.2

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

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/dto/github_releases/serializers.dart.

Run flutter format to format lib/dto/github_releases/serializers.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (permission_handler).

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.2.2 <3.0.0
built_collection ^4.3.0 4.3.2
built_value ^7.0.0 7.0.9
flutter 0.0.0
flutter_downloader ^1.4.0 1.4.2
http ^0.12.0+4 0.12.0+4
install_plugin ^2.0.1 2.0.1
package_info ^0.4.0+13 0.4.0+16
path ^1.6.4 1.6.4
path_provider ^1.5.1 1.6.5
permission_handler ^4.2.0+hotfix.1 4.4.0+hotfix.4 5.0.0+hotfix.3
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
fixnum 0.10.11
http_parser 3.1.4
matcher 0.12.6
meta 1.1.8
path_provider_macos 0.0.4
path_provider_platform_interface 1.0.1
pedantic 1.9.0
permission_handler_platform_interface 1.0.0 2.0.0
platform 2.2.1
plugin_platform_interface 1.0.2
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
build_runner any
built_value_generator any
test any