Databases and local storage
Domains:
Flutter
How do I access Shared Preferences?
In Android, you can store a small collection of key-value pairs using the SharedPreferences API.
In Flutter, access this functionality using the Shared_Preferences plugin. This plugin wraps the functionality of both Shared Preferences and NSUserDefaults (the iOS equivalent).
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.');
prefs.setInt('counter', counter);
}
How do I access SQLite in Flutter?
In Android, you use SQLite to store structured data that you can query using SQL.
In Flutter, access this functionality using the SQFlite plugin.