Hive storage not persistent on Flutter web
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Steps to reproduce**
I am using hive with flutter web, and after closing the project and starting it up again the stored data comes back as null.
After storing data with hive, stop flutter, close the browser, and start it up again.
**Code sample**
```
class _MyHomePageState extends State {
int counter;
bool loading = true;
var box;
@override
void initState() {
init();
super.initState();
}
void init() async {
await Hive.initFlutter();
var getBox = await Hive.openBox('testBox');
int oldval = getBox.get('counter');
setState(() {
box = getBox;
counter = oldval ?? 0;
loading = false;
});
}
@override
void dispose() {
box.close();
super.dispose();
}
void increment() async {
setState(() => counter += 1);
await box.put('counter', counter);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: loading ? CircularProgressIndicator() : Text('$counter'),
),
floatingActionButton: FloatingActionButton(
onPressed: increment,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
```
**Version**
- Platform: Windows, Web
- Flutter version: 1.26.0-17.5.pre (beta channel)
- Hive version: 1.4.4
- Hive_flutter version: 0.3.1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.