xxxxxxxxxx
dependencies:
nb_utils: ^4.5.2
// for initializing
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initialize();
runApp(MyApp());
}
// adding key
return MaterialApp(
debugShowCheckedModeBanner: false,
navigatorKey: navigatorKey,
home: HomePage(),
);
// then just use
/// add a Double, int, string in SharedPref
await setValue("key", 20.0);
\
///to get
getBoolAsync("key");
/// Returns a Double if exists in SharedPref
getDoubleAsync("key");
/// Returns a Int if exists in SharedPref
getIntAsync("key");
/// Returns a String if exists in SharedPref
getStringAsync("key");
xxxxxxxxxx
dependencies:
shared_preferences: ^2.0.11
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('stringValue', "abc");
prefs.setInt('intValue', 123);
prefs.setDouble('doubleValue', 115.0);
prefs.setBool('boolValue', true);
xxxxxxxxxx
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: RaisedButton(
onPressed: _incrementCounter,
child: Text('Increment Counter'),
),
),
),
));
}
_incrementCounter() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
int counter = (prefs.getInt('counter') ?? 0) + 1;
print('Pressed $counter times.');
await prefs.setInt('counter', counter);
}