Why doesn't the Value Listenable Builder value in ListView change?
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Question**
I think the Value Listenable Builder widget in ListView should change. But that's not the case.
Can you tell me why you did that?
I'd really appreciate it if you could answer.
Please watch the implementation video.
https://user-images.githubusercontent.com/67625692/148695273-1eabef58-34cf-41d4-9977-c55ed76e54af.mov
**Code sample**
```dart
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hive_flutter/hive_flutter.dart';
void main() async {
await Hive.initFlutter();
Hive.openBox('HiveBox');
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
var box = Hive.box('HiveBox');
TextEditingController controller = TextEditingController();
ShapeBorder shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
side: const BorderSide(color: Colors.grey, width: 1),
);
void _firstKeyValueChange() {
box.put(0, 300);
toast('run _firstKeyValueChange()');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(10),
child: TextField(
controller: controller,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'Enter a value in "HiveBox"',
labelStyle: TextStyle(color: Colors.black),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 10, 10),
child: Align(
alignment: Alignment.centerRight,
child: ElevatedButton(
onPressed: () {
if (controller.value.text.isEmpty == true) {
toast('Please enter the value.');
} else {
box.add(controller.text);
toast('${controller.text} has been added in the "HiveBox".');
}
},
child: const Text('Enter'),
),
),
),
Row(
children: [
Flexible(
child: Column(
children: [
const Text('ValueListenableBuilder \nin ListView'),
ListView.builder(
shrinkWrap: true,
itemCount: Hive.box('HiveBox').keys.length,
itemBuilder: (context, index) {
var value = Hive.box('HiveBox').getAt(index);
var key = Hive.box('HiveBox').keyAt(index);
return ValueListenableBuilder(
valueListenable: Hive.box('HiveBox').listenable(),
builder: (context, box, widget) {
return Padding(
padding: const EdgeInsets.all(10),
child: Card(
shape: shape,
elevation: 0,
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [Text('key : $key'), Text('value : $value')],
),
),
),
);
});
}),
],
),
),
Flexible(
child: Column(
children: [
const Text('ListView \nin ValueListenableBuilder'),
ValueListenableBuilder(
valueListenable: box.listenable(),
builder: (context, box, widget) {
return ListView.builder(
shrinkWrap: true,
itemCount: Hive.box('HiveBox').keys.length,
itemBuilder: (context, index) {
var key = Hive.box('HiveBox').keyAt(index);
var value = Hive.box('HiveBox').getAt(index);
return Padding(
padding: const EdgeInsets.all(10),
child: Card(
shape: shape,
elevation: 0,
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [Text('key : $key'), Text('value : $value')],
),
),
),
);
});
},
),
],
)
),
],
)
],
),
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
tooltip: '_firstKeyValueChange',
onPressed: _firstKeyValueChange,
),
);
}
}
void toast(String msg) {
Fluttertoast.showToast(
msg: msg,
gravity: ToastGravity.BOTTOM,
fontSize: 16,
toastLength: Toast.LENGTH_SHORT,
textColor: Colors.white,
timeInSecForIosWeb: 1,
backgroundColor: Colors.grey,
);
}
```
**Version**
- Platform: iOS, Android, Mac, Windows, Linux, Web
- Flutter version: 2.8
- Hive version: 2.0.5
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue provides only an inline Dart reproduction and no repository file or test. Start by running it with Flutter 2.8 and Hive 2.0.5, compare the two ValueListenableBuilder placements, and define done as a maintainer-confirmed explanation or a scoped regression fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- database, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100