导包:
hive: ^2.0.6
hive_flutter: ^1.1.0
代码:(敲一遍,你会懂的)
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
Future<void> main() async {
await Hive.initFlutter();
runApp(const MaterialApp(
home: H(),
));
}
class H extends StatefulWidget {
const H({super.key});
@override
State<H> createState() => _HState();
}
class _HState extends State<H> {
List<int> records = [];
int index = 0;
@override
void initState() {
super.initState();
getData();
}
Future<void> getData() async {
var box = await Hive.openBox('demo');
var value = box.get("record");
if (value == null) {
print('啥也没拿到到');
} else {
print('拿到数据了');
records = value.cast<int>();
print(records);
}
}
Future<void> addData() async {
var box = await Hive.openBox('demo');

最低0.47元/天 解锁文章
1541

被折叠的 条评论
为什么被折叠?



