mmkv_storage 0.1.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • new65

mmkv_storage #

pub package

Wraps MMKV iOS and Android native library as Flutter Plugin

Getting Started #

This package is intended for faster iOS/Android local storage access

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.0+1 #

  • update README and description

0.1.0 #

  • MVP on iOS and Android

example/lib/main.dart

import 'dart:async';

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

import 'package:mmkv_storage/mmkv_storage.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _rootDir = 'Unknown';
  String _myString1;
  String _myString2;
  final _myController = TextEditingController();
  final String _keyString1 = "string1";
  final String _keyString2 = "string2";

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String rootDir;
    String mystring;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      rootDir = await MmkvStorage.getRootDir();
      mystring = await MmkvStorage.decodeString(_keyString1);

      await MmkvStorage.encodeBool("bool", true);
      bool b = await MmkvStorage.decodeBool("bool");
      print(b.toString());

      await MmkvStorage.encodeInt("int", 121212);
      int i = await MmkvStorage.decodeInt("int");
      print(i.toString());

      await MmkvStorage.encodeDouble("double", 1212.1212);
      double d = await MmkvStorage.decodeDouble("double");
      print(d.toString());

      // long is also int in dart ? failed on android
      // await MmkvStorage.encodeLong("long", 1212121212);
      // int l = await MmkvStorage.decodeLong("long");
      // print(l.toString());

      /// TODO handle bytes type on ios
      // await MmkvStorage.encodeUint8List(
      //     "uint8", Uint8List.fromList(List<int>.from([i, l])));
      // Uint8List ui8 = await MmkvStorage.decodeUint8List("uint8");
      // print(ui8.toString());
    } on PlatformException {
      rootDir = 'Failed to get';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _rootDir = rootDir;
      _myString1 = mystring;
    });
  }

  @override
  void dispose() {
    // Clean up the controller when the Widget is disposed
    _myController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        buttonColor: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: Text('MmkvStorage Plugin'),
        ),
        body: ListView(
          children: [
            Column(
              children: <Widget>[
                Text('Root Directory : $_rootDir\n'),
                Text('Decoded value key=$_keyString1 :$_myString1'),
                Text('Decoded value key=$_keyString2 :$_myString2'),
                TextField(
                  controller: _myController,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    RaisedButton(
                      onPressed: () {
                        MmkvStorage.encodeString(
                            _keyString1, _myController.text.toString());
                      },
                      child: Text(
                        'Encode1',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    ),
                    RaisedButton(
                      onPressed: () {
                        MmkvStorage.decodeString(_keyString1).then((value) {
                          setState(() {
                            _myString1 = value;
                          });
                        });
                      },
                      child: Text(
                        'Decode1',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    ),
                    RaisedButton(
                      onPressed: () {
                        setState(() {
                          _myString1 = null;
                        });
                      },
                      child: Text(
                        'Clear1',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    ),
                    RaisedButton(
                      onPressed: () async {
                        await MmkvStorage.removeValueForKey(_keyString1);
                        var str1 = await MmkvStorage.decodeString(_keyString1);
                        setState(() {
                          _myString1 = str1;
                        });
                      },
                      child: Text(
                        'Remove1',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    )
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    RaisedButton(
                      onPressed: () {
                        MmkvStorage.encodeString(
                            _keyString2, _myController.text.toString());
                      },
                      child: Text(
                        'Encode2',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    ),
                    RaisedButton(
                      onPressed: () {
                        MmkvStorage.decodeString(_keyString2).then((value) {
                          setState(() {
                            _myString2 = value;
                          });
                        });
                      },
                      child: Text(
                        'Decode2',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    ),
                    RaisedButton(
                      onPressed: () {
                        setState(() {
                          _myString2 = null;
                        });
                      },
                      child: Text(
                        'Clear2',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    ),
                    RaisedButton(
                      onPressed: () async {
                        await MmkvStorage.removeValueForKey(_keyString2);
                        var str2 = await MmkvStorage.decodeString(_keyString2);
                        setState(() {
                          _myString2 = str2;
                        });
                      },
                      child: Text(
                        'Remove2',
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                    )
                  ],
                ),
                RaisedButton(
                  onPressed: () async {
                    await MmkvStorage.removeAll();
                    var str1 = await MmkvStorage.decodeString(_keyString1);
                    var str2 = await MmkvStorage.decodeString(_keyString2);

                    setState(() {
                      _myString1 = str1;
                      _myString2 = str2;
                    });
                  },
                  child: Text(
                    'RemoveAll',
                    style: TextStyle(
                      color: Colors.white,
                    ),
                  ),
                ),
                Text("Encode<N>: Store value to cache N"),
                Text("Decode<N>: Decode value from cache N"),
                Text("Clear<N>: Clear decoded value N (not deleting cache)"),
                Text("Remove<N>: Delete cache N"),
                Text("RemoveAll: Delete all cache"),
              ],
            )
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  mmkv_storage: ^0.1.0+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:mmkv_storage/mmkv_storage.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
30
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]
65
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.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:mmkv_storage/mmkv_storage.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:mmkv_storage/mmkv_storage.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:mmkv_storage/mmkv_storage.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:mmkv_storage/mmkv_storage.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • mmkv_storage that is 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.2
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