isar / isar/hive

[web] hive values reads from another tabs are out of date

Open
#1,063 0 comments 0 reactions 0 assignees View on GitHub
problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Steps to Reproduce**
- update a value from first tab (`box.put('darkMode', true)`)
- read the value from second tab (`box.get('darkMode')`)
- expected `true`, but it returns `false` even if the DB is up to date.

https://user-images.githubusercontent.com/5927329/186697903-091e7e86-6bfa-4db5-8d26-c78ff05433f1.mov

**Code sample**
```dart
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';

const testBox = 'darkModeTutorial';

void main() async {
await Hive.initFlutter();
await Hive.openBox(testBox);

runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return ValueListenableBuilder>(
valueListenable: Hive.box(testBox).listenable(),
builder: (context, box, widget) {
var darkMode = box.get('darkMode', defaultValue: false);
return MaterialApp(
themeMode: darkMode ? ThemeMode.dark : ThemeMode.light,
darkTheme: ThemeData.dark(),
home: Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Switch(
value: darkMode,
onChanged: (val) {
box.put('darkMode', !darkMode);
},
),
ElevatedButton(
onPressed: () =>
print(box.get('darkMode', defaultValue: false)),
child: const Text('Read'),
),
],
),
),
),
);
},
);
}
}
```

**Version**
- Platform: Web
- Flutter version: 3.0.1
- Hive version: 2.2.3

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided Flutter web sample with two browser tabs and the `main()` entry point, then reproduce the `box.put('darkMode', true)` and `box.get('darkMode')` sequence. Trace the web implementation used by the Hive box and identify where the second tab obtains its value. Done means the second tab reads `true` after the first tab updates the database, with coverage for the cross-tab case.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
databases, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.