Flutter settings manager built on top of Shared Preferences

Overview

pub package pub package Buy Me A Coffee Donate

Settings Manager

  • Flutter settings store built on top of shared preferences.
  • Code Generator for supported types

Usage

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:settings_manager/settings_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';

part 'settings.g.dart';

class Settings = SettingsBase with _$Settings;

abstract class SettingsBase with SettingsStore {
  @BoolSetting(defaultValue: false)
  bool darkMode;

  @StringSetting(defaultValue: 'none')
  String userId;

  @IntSetting(defaultValue: 0)
  int counterValue;

  @DoubleSetting(defaultValue: 0)
  double radialValue;

  @StringListSetting(defaultValue: [])
  List<String> savedItems;
}

Example

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      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> {
  final _settings = Settings();

  @override
  void initState() {
    _settings.init().then((ready) {
      if (mounted) setState(() {});
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<int>(
        stream: _settings.counterValueStream,
        builder: (context, snapshot) {
          return Scaffold(
            appBar: AppBar(title: Text(widget.title)),
            body: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'You have pushed the button this many times:',
                  ),
                  Text(
                    '${snapshot.data}',
                    style: Theme.of(context).textTheme.headline4,
                  ),
                ],
              ),
            ),
            floatingActionButton: FloatingActionButton(
              onPressed: () => _settings.counterValue = snapshot.data + 1,
              tooltip: 'Increment',
              child: Icon(Icons.add),
            ),
          );
        });
  }
}
You might also like...

Kyber Mod Manager A Mod Manager build for Kyber.

Kyber Mod Manager A Mod Manager build for Kyber.

Kyber Mod Manager A Mod Manager build for Kyber. This app is not affiliated with Kyber or any of its creators. Key Features • Download • Screenshots •

Sep 25, 2022

Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework.

Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework.

Prism Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework. Prism brings you exclus

Dec 31, 2022

Basic todo mobile application built on top of the ETH blockchain with Flutter, Truffle and Ganache.

Basic todo mobile application built on top of the ETH blockchain with Flutter, Truffle and Ganache.

Todo-DAPP This project is a basic mobile Todo App build with Flutter. The backend consist in a Solidity contract running on the Ethereum Blockchain. C

Sep 28, 2022

Nimbostratus is a reactive data-fetching and client-side cache management library built on top of Cloud Firestore.

Nimbostratus 🌩 Nimbostratus is a reactive data-fetching and client-side cache management library built on top of Cloud Firestore. The Cloud Firestore

Dec 15, 2022

Flutter preferences management with crypto capabilities

crypted_preferences Flutter preferences management with crypto capabilities For now preferences are not crypted, I'm waiting for FFI to land :) But yo

Jan 14, 2020

A Flutter widget to create an iOS settings-table (static TableView).

A Flutter widget to create an iOS settings-table (static TableView).

flutter_cupertino_settings A Flutter widget to create an iOS settings-table (static TableView). import 'package:flutter_cupertino_settings/flutter_cup

Dec 28, 2022

An Ubuntu desktop settings app made with Flutter

An Ubuntu desktop settings app made with Flutter

unofficial Ubuntu Desktop Settings App made with Flutter - WIP TODO use real yaru icons - thanks to @Jupi007 improve layout implement settings search

Dec 15, 2022

A Flutter repo with a ready-to-go architecture containing flavors, bloc, device settings, json serialization and connectivity

A Flutter repo with a ready-to-go architecture containing flavors, bloc, device settings, json serialization and connectivity

Flutter Ready to Go A Flutter repo with a ready-to-go architecture containing flavors, bloc, device settings, json serialization and connectivity. Why

Nov 11, 2022
Comments
  • Figure out the protocol to be able to build UI easily

    Figure out the protocol to be able to build UI easily

    The idea is to have some sort of protocol which is required to be implemented in order to be able to generate UI with as little effort as possible

    Example:

    extension VisualRepro on bool {
      Widget toWidget() {
          return Toggle(value: this);
      }
    }
    
    // generated
    
    class SettingView extends StatelessWidget {
      @override
      build() {
         return this.value.toWidget();
      }
    }
    

    that's just a rough sketch and I'm not sure about the realistic way to implement this (and if this is even possible). It would have been easily doable if extensions were the legit way to implement interfaces, but they are not... Would love to hear your input/feedback/thoughts

    documentation enhancement 
    opened by lesnitsky 1
Owner
Rody Davis
Developer Advocate for @material-components at @Google
Rody Davis
Shared preferences typed - A type-safe wrapper around shared preferences, inspired by ts-localstorage

Typed Shared Preferences A type-safe wrapper around shared_preferences, inspired

Philipp Bauer 0 Jan 31, 2022
Flutter Settings Screen with Shared Preferences

Settings Screen with Shared Preferences A library that provides an easy solution to create settings screens with simple and compound options. Features

Barnabás BARTHA 66 Sep 27, 2022
Flutter-Shared-Preference - The goal is to learn how to use the shared preferences plugin to save important pieces of information to your device.

Recipe Finder The goal is to learn how to use the shared preferences plugin to save important pieces of information to your device. Final App UI Resou

Ashirbad Swain 1 Jan 1, 2022
Flutter theme demo using riverpod and shared preferences

flutter_theme_demo A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you start

Andree Yosua 0 Dec 27, 2021
🌀 Shared preferences with RxDart Stream observation

?? Shared preferences with RxDart Stream observation ⚡️ Reactive shared preferences for Flutter ??Reactive stream wrapper around SharedPreferences ?? Lightweight and easy-to-use ?? A reactive key-value store for Flutter projects. Like shared_preferences, but with Streams ?? Rx Shared Preferences for Flutter ?? rx_shared_preferences ?? rx_shared_preference ?? Reactive SharedPreferences for Flutter ?? A stream based wrapper over shared_preferences, allowing reactive key-value storage.

Petrus Nguyễn Thái Học 36 Nov 4, 2022
Shared Preferences ile ekran açılma sayacı uygulaması

sayac_uygulamasi A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

null 0 Dec 29, 2021
A package for encrypted shared preferences

Prefs Guard Prefs Guard is a data protection wrapper for local storage (Shared Prefs). supporting both IOS & Android. - Notice :- Use Same GuardType t

null 26 Jun 7, 2022
Settings Screen with Custom Shared Preference Interface

flutter_settings_screens This is a simple flutter plugin for easily creating app settings screens. The unique thing about this library is that it is n

Harshvardhan Joshi 149 Jan 4, 2023
This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset folder, and 100% Shared Code

This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset folder, and 100% Shared Code. Now with the ability to login with FaceID, TouchID, and Fingerprint Reader on Android.

Rody Davis 672 Jan 6, 2023
Daily-Task-Manager a daily task manager application project created in flutter

This is a daily task manager application project created in flutter. Install this application on Android - Install from Play Store

DVS 0 May 10, 2022