flutterx_preferences 2.0.0
flutterx_preferences: ^2.0.0 copied to clipboard
Persistent and session key-value storage exposed as a synchronous Map<String, String>, with typed accessors for bool, int, double, JSON and lists.
import 'package:flutter/material.dart';
import 'package:flutterx_preferences/flutterx_preferences.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Preferences.initialize();
runApp(const ExampleApp());
}
/// Counter whose value survives restarts.
class ExampleApp extends StatefulWidget {
/// Creates the example app.
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
final Preferences _preferences = Preferences.local('example');
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Flutterx Preferences',
home: Scaffold(
appBar: AppBar(title: const Text('Preferences example')),
body: Center(child: Text('Pressed ${_preferences.getInt('counter')} times')),
floatingActionButton: FloatingActionButton(
onPressed: () => setState(() => _preferences.setInt('counter', _preferences.getInt('counter') + 1)),
child: const Icon(Icons.add),
),
),
);
}