Saving Data in Flutter

Jan 31 2024 · Dart 3, Flutter 3.10, Visual Studio Code

Part 2: Use SharedPreferences & Secure Storage

09. Using flutter_secure_storage

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 08. Challenge: Add a Field Next episode: 10. Use path & path_provider

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Storing locally user credentials or other sensitive data is a rather common task for apps. While SharedPreferences is ideal to store simple data, it’s certainly not the right tool to store sensitive data, as data is not encrypted.

final storage = FlutterSecureStorage(); 
await storage.write(key: 'your_key', value: 'your_value'); 
String value = await storage.read(key: 'your_key'); 
await storage.delete(key: 'your_key'); 
Flutter pub add flutter_secure_storage 
final FlutterSecureStorage _secureStorage = const FlutterSecureStorage(); 
final calories = await _secureStorage.read(key: _caloriesKey) ?? ‘2000’; 
return int.parse(calories); 
final showFileSize = await _secureStorage.read(key: _showFileSizeKey)  
  ?? 'true'; 
return bool.parse(showFileSize); 
final showDate =await _secureStorage.read(key: _showDateKey) ?? 'true'; 
    return bool.parse(showDate); 
Future deleteSettings() async { 
  await _secureStorage.delete(key: _listNameKey); 
  await _secureStorage.delete(key: _caloriesKey); 
  await _secureStorage.delete(key: _showFileSizeKey); 
}