shared_preferences_monitor 1.0.1+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

Package created to make it easy to see the state of the shared preferences of your app. I always find myself in a hard spot when trying to see the current state of my preferences. This package come to manage your preferences in an easy way.

How to use #

void main() async {
  await SharedPreferencesMonitor.init();
  SharedPreferencesMonitor.setKey(GlobalKey<NavigatorState>());
  runApp(MyApp());
}

To use it you only have to init the monitor calling the SharedPreferencesMonitor.init() method and set a global key to the monitor so it can handle navigation.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      navigatorKey: SharedPreferencesMonitor.getKey(),
      title: 'Flutter Shared Preferences Monitor',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

And the last step to configure is to pass the monitor key to the material app navigatorKey: SharedPreferencesMonitor.getKey() and you are ready to go.

Navigating to the monitor page is easy, just call:

SharedPreferencesMonitor.showPage();

The monitor looks like this:

monitor

You can add new preferences or delete them.

You can at anytime call SharedPreferencesMonitor.getKeyValueInfo() and it will return a Map with your keys and values of the current state of the shared preferences.

{pref2: 2, pref1: 1, pref4: 4, pref3: 3}

Important #

The mainly idea of the package is to be used ONLY on development. You will never want your users messing up their preferences.

Todo #

  • [ ] Tests

Features and Bugs #

Please sugest new features and report bugs on issue tracker.

[1.0.1+1] #

  • Updating documentation and dependencies

[1.0.1] #

  • Fix broken monitor image

[1.0.0] #

  • First release

example/lib/main.dart

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SharedPreferencesMonitor.init();
  SharedPreferencesMonitor.sharedPreferences.setInt('pref1', 1);
  SharedPreferencesMonitor.sharedPreferences.setInt('pref2', 2);
  SharedPreferencesMonitor.sharedPreferences.setInt('pref3', 3);
  SharedPreferencesMonitor.sharedPreferences.setInt('pref4', 4);
  print(SharedPreferencesMonitor.getKeyValueInfo());
  SharedPreferencesMonitor.setKey(GlobalKey<NavigatorState>());
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      navigatorKey: SharedPreferencesMonitor.getKey(),
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.list),
            onPressed: () => SharedPreferencesMonitor.showPage(),
          )
        ],
      ),
      body: Container(
        child: Center(
          child: Text('Click on appbar icon to see the preferences'),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


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

We analyzed this package on Mar 31, 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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
shared_preferences ^0.5.6+2 0.5.6+3
Transitive dependencies
collection 1.14.11 1.14.12
flutter_web_plugins 0.0.0
meta 1.1.8
shared_preferences_macos 0.0.1+6
shared_preferences_platform_interface 1.0.3
shared_preferences_web 0.1.2+4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test