flutter_app_preferences 0.4.0 flutter_app_preferences: ^0.4.0 copied to clipboard
A simple package to manage app preferences and get notifications when something changes.
import 'package:example/app_preferences.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await AppPreferences.i.initialize();
runApp(
MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
useMaterial3: true,
),
home: const MyHomePage(),
),
);
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('App Preferences Example'),
),
body: ListenableBuilder(
listenable: AppPreferences.i.counter,
builder: (context, _) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'${AppPreferences.i.counter.value}',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => AppPreferences.i.counter.value += 1,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}