prf 2.1.1 copy "prf: ^2.1.1" to clipboard
prf: ^2.1.1 copied to clipboard

Easily save and load values locally. Effortless local persistence with type safety and zero boilerplate. Just get, set, and go. Drop-in replacement for raw SharedPreferences.

example/example.dart

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Define variables (globally if you like)
  final username = PrfString('username');
  final highScore = PrfInt('high_score', defaultValue: 0);

  final currentUser = PrfJson<User>(
    'current_user',
    fromJson: (json) => User.fromJson(json),
    toJson: (user) => user.toJson(),
  );

  // Example usage
  await username.set('Alice');
  await highScore.set(1200);
  await currentUser.set(User(id: 1, name: 'Alice', email: 'alice@example.com'));

  //final savedName = await username.getOrFallback('Guest');
  //final score = await highScore.getOrFallback(0);
  //final user = await currentUser.get();
}

// Simple model for PrfJson demo
class User {
  final int id;
  final String name;
  final String email;

  User({
    required this.id,
    required this.name,
    required this.email,
  });

  factory User.fromJson(Map<String, dynamic> json) => User(
        id: json['id'] as int,
        name: json['name'] as String,
        email: json['email'] as String,
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'name': name,
        'email': email,
      };
}
11
likes
0
points
195
downloads

Publisher

verified publisherjozz.biz

Weekly Downloads

Easily save and load values locally. Effortless local persistence with type safety and zero boilerplate. Just get, set, and go. Drop-in replacement for raw SharedPreferences.

Repository (GitHub)
View/report issues

Topics

#shared-preferences #storage #state #persistence #local-storage

License

unknown (license)

Dependencies

flutter, shared_preferences, synchronized

More

Packages that depend on prf