unified_persistence 0.0.3 copy "unified_persistence: ^0.0.3" to clipboard
unified_persistence: ^0.0.3 copied to clipboard

Unified persistence for all platforms.

example/unified_persistence_example.dart

import 'package:unified_persistence/unified_persistence.dart';

class UserProfile {
  UserProfile({required this.name});

  final String name;

  Map<String, dynamic> toJson() => {'name': name};

  static UserProfile fromJson(Map<String, dynamic> json) {
    return UserProfile(name: json['name'] as String);
  }
}

Future<void> main() async {
  final persistor = MemoryPersistor<UserProfile>(
    serializer: JsonSerializer<UserProfile>(
      toJson: (value) => value.toJson(),
      fromJson: UserProfile.fromJson,
    ),
  );

  await persistor.persist(UserProfile(name: 'Alice'));
  final restored = await persistor.restore();

  if (restored?.name != 'Alice') {
    throw StateError('Failed to restore the persisted profile.');
  }
}
1
likes
150
points
11
downloads

Documentation

API reference

Publisher

verified publisherleanflutter.dev

Weekly Downloads

Unified persistence for all platforms.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

web

More

Packages that depend on unified_persistence