hive_dev_tools 0.0.1 copy "hive_dev_tools: ^0.0.1" to clipboard
hive_dev_tools: ^0.0.1 copied to clipboard

Enhances the development workflow by offering real-time previews of hive storage.

🐝 Hive DevTool for Dart DevTools #

A Flutter package that integrates Hive with Dart DevTools, allowing developers to conveniently inspect and visualize Hive boxes and cached data directly within their development workflow.

Screenshot of dart dev tools

Features #

  • View all active Hive boxes in Dart DevTools
  • Explore stored key-value pairs in real-time
  • Improve debugging efficiency for apps using Hive for local storage

Installation #

dev_dependencies:
  hive_dev_tools: 0.0.1

Create a file called hive_service.dart

Add the following code:

import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart'
if (dart.library.html) 'src/stub/path_provider.dart';

class HiveService {
  const HiveService._();

  static var boxData = <String, Map<dynamic, dynamic>>{};

  static Future<Map<String, Map<dynamic, dynamic>>> getBoxData() async {
    final boxData = <String, Map<dynamic, dynamic>>{};
    if (!kDebugMode) {
      return boxData;
    }

    final boxNames = await _getBoxNames();

    for (final boxName in boxNames) {
      try {
        final box = await Hive.openBox(boxName);
        boxData[boxName] = box.toMap();
      } catch (e) {
        debugPrint('Error opening or reading box "$boxName": $e');
      }
    }
    HiveService.boxData = boxData;
    return boxData;
  }

  static Future<List<String>> _getBoxNames() async {
    final appDir = await getApplicationDocumentsDirectory();

    final directory = Directory(appDir.path);
    final List<FileSystemEntity> entities = await directory.list().toList();

    final List<String> boxNames =
    entities
        .where((file) => file.path.endsWith('.hive'))
        .map((file) => file.path.split('/').last.split('.hive').first)
        .toList();

    return boxNames;
  }
}


Then add the following command after Hive.initFlutter().

void main() async {
  await Hive.initFlutter();
  await HiveService.getBoxData();
  
  runApp(ExampleApp());
}

Please look at the example app as an example.

πŸ“’ Contributions #

Contributions, issues, and feature requests are welcome!

πŸ“ License #

This project is licensed under the MIT License.

0
likes
50
points
38
downloads

Publisher

unverified uploader

Weekly Downloads

Enhances the development workflow by offering real-time previews of hive storage.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

devtools_app_shared, devtools_extensions, flutter, flutter_localization, flutter_screenutil, get_it, intl, path_provider, vm_service, widgetbook, widgetbook_annotation

More

Packages that depend on hive_dev_tools