isar / isar/hive

Hive storage not persistent on Flutter web

Open
#587 4 comments 3 reactions 1 assignee Claimed by @simc View on GitHub
problem
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.