package_replaced 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

package_replaced #

Allow Flutter to respond to Android MY_PACKAGE_REPLACED intent

To use this plugin, besides importing, you will also have to add PackageReplacedPlugin.setPluginRegistrantCallback() to the Android side of your app.

i.e. subclass FlutterApplication/implement PluginRegistry.PluginRegistrantCallback and call it in onCreate:

class OverrideApplication: FlutterApplication(), PluginRegistry.PluginRegistrantCallback{

    override fun onCreate() {
        super.onCreate()
        PackageReplacedPlugin.setPluginRegistrantCallback(this)
    }

    override fun registerWith(p0: PluginRegistry?) {
        GeneratedPluginRegistrant.registerWith(p0)
    }
}

and in your manifest,

<application android:name=".OverrideApplication">
    **other manifest stuff here**
</application>

1.1.1 #

Add application context reference in onReceive if it is not already set for some reason

1.1.0 #

Add function setDeferHandlerExecution

1.0.0+1 #

Flutter format

1.0.0 #

Baseline functionality (i.e. once PackageReplaced.setHandlerFunction has been called, MY_PACKAGE_REPLACED should trigger a callback to that function)

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';

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

void main() {
  runApp(MyApp());
  PackageReplaced.setHandlerFunction(handlePackageReplaced);
}

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

void handlePackageReplaced() async {
  await _incrementReplaceCount();
}

class _MyAppState extends State<MyApp> {
  int _replaceCount = 0;
  String _miscMessage = "";

  @override
  void initState() {
    super.initState();
    _showReplaceCount();
  }

  void _showReplaceCount() async {
    final replaceCount = await _getReplaceCount();

    setState(() {
      _replaceCount = replaceCount;
    });
  }

  void _artificalIncrement() async {
    await _incrementReplaceCount();
    _showReplaceCount();
  }

  void _artificalReset() async {
    await _setReplaceCount(0);
    _showReplaceCount();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('package_replaced plugin example app'),
          ),
          body: Center(
            child: Column(
              children: <Widget>[
                Text('Package replaced $_replaceCount time(s)'),
                Text(_miscMessage)
              ],
            ),
          ),
          floatingActionButton: Column(
            children: <Widget>[
              FloatingActionButton(
                child: Text("+"),
                onPressed: _artificalIncrement,
              ),
              FloatingActionButton(
                child: Text("0"),
                onPressed: _artificalReset,
              ),
            ],
            mainAxisAlignment: MainAxisAlignment.end,
          )),
    );
  }
}

Future<File> getCountFile() async {
  final myStorageDirectory =
      await path_provider.getApplicationDocumentsDirectory();

  var countFilePath = myStorageDirectory.path;

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

  countFilePath += "org.thebus.package_replaced_example.replaceCount";

  return File(countFilePath);
}

Future<int> _getReplaceCount() async {
  var retCount = 0;

  final countFile = await getCountFile();

  if (await countFile.exists()) {
    retCount = int.tryParse((await countFile.readAsString()));

    if (retCount == null) {
      retCount = 0;
    }
  }

  return retCount;
}

Future<void> _setReplaceCount(int newCountValue) async {
  final countFile = await getCountFile();

  if (!(await countFile.parent.exists())) {
    await countFile.parent.create(recursive: true);
  }

  await countFile.writeAsString(newCountValue.toString());
}

Future<void> _incrementReplaceCount() async {
  final currentReplaceCount = await _getReplaceCount();
  await _setReplaceCount(currentReplaceCount + 1);
}

Use this package as a library

1. Depend on it

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


dependencies:
  package_replaced: ^1.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:package_replaced/package_replaced.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
8
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]
54
Learn more about scoring.

We analyzed this package on Jul 9, 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 linux

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

Package does not support Flutter platform macos

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

Package does not support Flutter platform web

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

Package does not support Flutter platform windows

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

Package not compatible with SDK dart

because of import path [package_replaced] 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
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