Skip to content
pubscout

prefs

4.2.0, released 2 years ago by andrioussolutions.com

A static wrapper around shared_preferences for reading and writing app preferences.

WASM-ready
$ flutter pub add prefs
Source repository

What it does

It wraps the shared_preferences plugin to store and read key-value preferences across Android, iOS, Web, Windows, macOS, and Linux. It provides a static class interface to easily get and set values without needing an instance.

AI-written summary of version 4.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want a simpler static interface over shared_preferences
  • You need to store simple key-value data on the device

Skip it when

  • You need secure storage for sensitive data like passwords or tokens
  • You are looking for a robust type-safe ORM or NoSQL database

Strengths

  • Static function calls make it accessible anywhere in the app
  • Supports multiple platforms including Android, iOS, Web, Windows, macOS, and Linux

Weaknesses

  • Relies on shared_preferences which does not guarantee writes to disk
  • Not suitable for critical data storage

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
2

Initialize the class library using Prefs.init() or Prefs.initAsync() in your app's initState() and clean up with Prefs.dispose() in dispose().

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Prefs.init();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text('Prefs initialized'),
        ),
      ),
    );
  }
}

Alternatives

Packages that do the same job and could replace prefs.

Works with

Packages commonly used together with prefs: ones it builds on, ones built on it, and its own family.