boot_completed 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

boot_completed #

Flutter plugin to execute dart code on boot completed.

Getting Started #

See example source in repository.

A bunch of extra things need to be done to use this plugin:

  1. In your dart code, call boot_completed.setBootCompletedFunction(functionName)

    See main() in example/lib/main.dart

  1. On the android side, register org.thebus.boot_completed.BootCompletedPlugin as a broadcast receiver

    See example/android/app/src/main/AndroidManifest.xml

  1. On the android side, your application needs to subclass FlutterApplication, and implement PluginRegistry.PluginRegistrantCallback

    org.thebus.boot_completed.BootCompletedPlugin.setPluginRegistrantCallback(this) needs to be called,

    and PluginRegistrantCallback.registerWith should call GeneratedPluginRegistrant.registerWith()

    See example/android/app/src/main/kotlin/org/thebus/boot_completed_example/ExampleApplication.kt

    Don't forget to tell android to use your application subclass instead of FlutterApplication by modifying your AndroidManifest.xml

    See the application section in example/android/app/src/main/AndroidManifest.xml

1.1.0 #

Updated Kotlin to v1.3.50, Gradle to v3.5.3

1.0.0 #

flutter v1.7.8+hotfix.2, MethodCallHandler.onMethodCall suddenly has nonnull params

0.2.1+1 #

flutter format

0.2.1 #

add missing check in boot completed plugin to make sure the received intent is for boot completed

0.2.0 #

allow execution of the boot function to be put off by calling setDeferExecution(true)

this may or may not be useful if for instance you have other boot receivers and you want to execute them in a certain order

you will then have to call BootCompletedPlugin.handleBootCompleted yourself probably from within one of the other receivers' onReceive

0.1.1+1 #

ran flutter format on lib\boot_completed.dart

0.1.1 #

changed implementation of boot completed receiver back to the way that uses a method channel since it seems like hardcoding the dart function name only works in debug builds - with release builds, it's no longer functional

0.1.0+3 #

revised readmes a bit more, added link to github repo in pubspec added dartdoc comment confirmed compatibility with path_provider 1.0.0, changed dependency to ">=0.5.0+1 <2.0.0"

0.1.0+2 #

change http url to https

0.1.0+1 #

pub.dev analysis now finds the description is too long - shortened it

0.1.0 #

Update version number and a few non-functional things suggested by pub.dev analysis.

0.0.1 #

Initial version with working example.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:boot_completed/boot_completed.dart' as boot_completed;

import 'package:path_provider/path_provider.dart' as path_provider;
import 'dart:io';

void main() {
  runApp(MyApp());
  boot_completed.setBootCompletedFunction(incrementCounter);
}

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    showCounterValue();
  }

  int _counter;

  Future<void> showCounterValue() async {
    var counterValue = await getCounter();

    setState(() {
      _counter = counterValue;
    });
  }

  void doIncrementCounter() async {
    await incrementCounter();
    await showCounterValue();
  }

  void doResetCounter() async {
    await resetCounter();
    await showCounterValue();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Counter: $_counter'),
        ),
        floatingActionButton: Column(
          children: <Widget>[
            FloatingActionButton(
              onPressed: doResetCounter,
            ),
            FloatingActionButton(
              onPressed: doIncrementCounter,
            )
          ],
          mainAxisAlignment: MainAxisAlignment.end,
        ),
      ),
    );
  }
}

final COUNTER_FILE_PATH = "myCounter";

Future<String> getPrivateDocsPath() async {
  var myDocsPath =
      (await path_provider.getApplicationDocumentsDirectory()).path;

  if (!myDocsPath.endsWith("/")) {
    myDocsPath += "/";
  }

  return myDocsPath;
}

Future<File> writeStringAsPrivateFile(String someString, String fileName,
    {bool append = false}) async {
  var writeMode = FileMode.write;

  if (append) {
    writeMode = FileMode.append;
  }

  return File((await getPrivateDocsPath()) + fileName)
      .writeAsString(someString, mode: writeMode);
}

Future<String> readPrivateFileAsString(String fileName) async {
  return await File((await getPrivateDocsPath()) + fileName).readAsString();
}

Future<int> getCounter() async {
  var currentValue;

  try {
    currentValue = int.parse(await readPrivateFileAsString(COUNTER_FILE_PATH));
  } catch (e) {
    currentValue = 0;
  }

  return currentValue;
}

Future<void> setCounter(int newCounterValue) async {
  await writeStringAsPrivateFile(newCounterValue.toString(), COUNTER_FILE_PATH);
}

Future<void> incrementCounter() async {
  var currentValue = await getCounter();

  currentValue += 1;

  await setCounter(currentValue);
}

Future<void> resetCounter() async {
  await setCounter(0);
}

Use this package as a library

1. Depend on it

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


dependencies:
  boot_completed: ^1.1.0

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:boot_completed/boot_completed.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
62
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]
81
Learn more about scoring.

We analyzed this package on Jul 2, 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:boot_completed/boot_completed.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:boot_completed/boot_completed.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 linux

Because of import path [package:boot_completed/boot_completed.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:boot_completed/boot_completed.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:boot_completed/boot_completed.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:boot_completed/boot_completed.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
path_provider >=0.5.0+1 <2.0.0 1.6.11
Transitive dependencies
collection 1.14.12 1.14.13
file 5.2.1
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
typed_data 1.1.6 1.2.0
vector_math 2.0.8
xdg_directories 0.1.0
Dev dependencies
flutter_test