flutter_install_apk_silently 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new59

flutter_install_apk_silently #

A new Flutter plugin.

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.1.1 #

  • Installing without blocking UI.

0.1.0+1 #

  • Fixing documentation.

0.1.0 #

  • First Release.

example/lib/main.dart

import 'dart:io';

import 'package:dio/dio.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_install_apk_silently/flutter_install_apk_silently.dart';
import 'package:path_provider/path_provider.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _status = "idle";
  String _message = 'Please browse APK.';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              onPressed: () async {
                setState(() {
                  _status = "loading";
                  _message = "Waiting to be installed.";
                });

                var tempDir = await getTemporaryDirectory();
                String fullPath = tempDir.path +
                    "/app_${DateTime.now().millisecondsSinceEpoch}.apk";
                print('full path $fullPath');

                Dio dio = Dio();
                await download(dio, fullPath);

                File file = File(fullPath);

                Future.delayed(Duration(seconds: 1), () async {
                  FlutterInstallApkSilently.installAPK(file: file)
                      .then((isInstalled) {
                    if (isInstalled)
                      setState(() {
                        _status = "success";
                        _message = "The APK is installed successfully.";
                      });
                    else
                      setState(() {
                        _status = "failed";
                        _message = "The APK is installed failed.";
                      });
                  }).catchError((onError) => print(onError));
                });
              },
              child: Text("Download from Internet",
                  style: TextStyle(fontSize: 24.0)),
            ),
            RaisedButton(
              onPressed: () async {
                File file = await FilePicker.getFile(
                    type: FileType.custom, allowedExtensions: ['apk']);

                setState(() {
                  _status = "loading";
                  _message = "Waiting to be installed.";
                });
                Future.delayed(Duration(seconds: 1), () async {
                  FlutterInstallApkSilently.installAPK(file: file)
                      .then((isInstalled) {
                    if (isInstalled)
                      setState(() {
                        _status = "success";
                        _message = "The APK is installed successfully.";
                      });
                    else
                      setState(() {
                        _status = "failed";
                        _message = "The APK is installed failed.";
                      });
                  });
                });
              },
              child: Text("Browse APK", style: TextStyle(fontSize: 24.0)),
            ),
            (_status == "loading")
                ? Center(child: CircularProgressIndicator())
                : (_status == "success")
                    ? Center(
                        child:
                            Icon(Icons.check, color: Colors.green, size: 35.0))
                    : (_status == "failed")
                        ? Center(
                            child: Icon(Icons.clear,
                                color: Colors.red, size: 35.0))
                        : Container(),
            Text("$_message", style: TextStyle(fontSize: 24.0))
          ],
        ),
      ),
    );
  }

  Future download(Dio dio, String savePath) async {
    try {
      Response response = await dio.get(
        'apk url',
        //onReceiveProgress: showDownloadProgress,
        //Received data with List<int>
        options: Options(
            responseType: ResponseType.bytes,
            followRedirects: false,
            validateStatus: (status) {
              return status < 500;
            }),
      );

      File file = File(savePath);
      var raf = file.openSync(mode: FileMode.write);
      // response.data is List<int> type
      raf.writeFromSync(response.data);
      await raf.close();
    } catch (e) {
      print(e);
    }
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform ios

Because:

  • package:flutter_install_apk_silently/flutter_install_apk_silently.dart that declares support for platforms: android

Package does not support Flutter platform linux

Because:

  • package:flutter_install_apk_silently/flutter_install_apk_silently.dart that declares support for platforms: android

Package does not support Flutter platform macos

Because:

  • package:flutter_install_apk_silently/flutter_install_apk_silently.dart that declares support for platforms: android

Package does not support Flutter platform web

Because:

  • package:flutter_install_apk_silently/flutter_install_apk_silently.dart that declares support for platforms: android

Package does not support Flutter platform windows

Because:

  • package:flutter_install_apk_silently/flutter_install_apk_silently.dart that declares support for platforms: android

Package not compatible with SDK dart

Because:

  • flutter_install_apk_silently that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test