Learn how to use GetStorage in Flutter to store local data easily and persist user preferences or app state without complex setup. This lightweight, fast, and key-value storage solution is perfect for Flutter developers who want simplicity and efficiency.
Why Use GetStorage?
- Lightweight and fast
- No need to initialize SQLite or SharedPreferences manually
- Works great for storing themes, login states, or any small config
- Easy setup and usage
GetStorage is suitable for apps where data needs to be stored locally without complexity. You can also combine it with state management libraries like GetX for maximum productivity.
For more insights on GetX ecosystem, you can check this overview of GetX.

Step-by-Step Guide & Full Source Code
1. Add Dependency
# pubspec.yaml dependencies: get_storage: ^2.1.1 get: ^4.6.6
2. Initialize GetStorage (main.dart)
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; import 'home_page.dart'; void main() async { await GetStorage.init(); // Must be initialized before runApp runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return GetMaterialApp( title: 'GetStorage Demo', theme: ThemeData(primarySwatch: Colors.blue), home: const HomePage(), ); } }
3. Create a Controller to Handle Storage (storage_controller.dart)
import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; class StorageController extends GetxController { final box = GetStorage(); final data = ''.obs; @override void onInit() { super.onInit(); data.value = box.read('username') ?? ''; } void saveData(String username) { box.write('username', username); data.value = username; } void clearData() { box.remove('username'); data.value = ''; } }
4. Create UI to Use the Storage (home_page.dart)
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'storage_controller.dart'; class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) { final controller = Get.put(StorageController()); final usernameController = TextEditingController(); return Scaffold( appBar: AppBar(title: const Text('GetStorage Demo')), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ Obx(() => Text( 'Stored Username: ${controller.data}', style: const TextStyle(fontSize: 18), )), const SizedBox(height: 16), TextField( controller: usernameController, decoration: const InputDecoration(labelText: 'Enter Username'), ), const SizedBox(height: 16), ElevatedButton( onPressed: () { controller.saveData(usernameController.text); }, child: const Text('Save'), ), TextButton( onPressed: () { controller.clearData(); }, child: const Text('Clear'), ), ], ), ), ); } }