v6.0.0
localstorage
适用于 Flutter 的本地存储。React Native AsyncStorage 的替代方案。
382喜欢 1.3万近 30 天下载160Pub 分数
AndroidiOSWebmacOSWindowsLinux
📦 Flutter 的本地存储
以下为英文项目原文快照,最新内容请访问 GitHub。
LocalStorage for Flutter.
[!IMPORTANT]
LocalStorage is not intended to store large amounts or sensitive data.
flutter pub add localstorage
or add dependency to pubspec.yaml manually
dependencies:
localstorage: ^5.0.0
LocalStorage API documentation
import 'package:flutter/material.dart';
import 'package:localstorage/localstorage.dart';
late final ValueNotifier<int> notifier;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await initLocalStorage();
notifier = ValueNotifier(int.parse(localStorage.getItem('counter') ?? '0'));
notifier.addListener(() {
localStorage.setItem('counter', notifier.value.toString());
});
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ValueListenableBuilder<int>(
valueListenable: notifier,
builder: (context, value, child) {
return Text('Pressed $value times');
},
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
notifier.value++;
},
child: const Icon(Icons.add),
),
),
);
}
}
MIT
依赖清单 6 项
{"sdk":"flutter"}^1.9.1^2.1.5^1.1.1{"sdk":"flutter"}^5.0.0先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗