Reputation: 45
As part of a ValueListenableBuilder that sets up for a Listview that needs to update when a new entry is added to the db. I'm new to flutter but every tutorial I found says this should work but its says "The method 'listenable' isn't defined for the type 'Box'." Any help or ideas on where im going wrong is a massive help.
(only a section of code as the whole widget is pretty big)
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:hive/hive.dart';
Widget foodbar(context) => ValueListenableBuilder(
valueListenable: Hive.box<dynamic>('food').listenable(),
builder: (
context,
foodbox,
_,
) {
return ListView.builder(
itemCount: foodbox.length,
itemBuilder: (BuildContext context, int index) {
final food = foodbox.getAt(index) as FoodMod;
return;
(pubspec.yaml)
flutter:
sdk: flutter
hive: 1.4.1+1
hive_flutter: ^0.3.0+2
path_provider: ^1.3.0
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
hive_generator: ^0.8.2
build_runner:
Upvotes: 1
Views: 2684
Reputation: 257
You need to import
import 'package:hive_flutter/hive_flutter.dart';
Upvotes: 4