mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 04:32:32 +00:00
chore: rewrite profile system interface
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lunasea/core/models/configuration/external_module.dart';
|
||||
import 'package:lunasea/core/models/configuration/indexer.dart';
|
||||
import 'package:lunasea/core/models/configuration/profile.dart';
|
||||
import 'package:lunasea/core/models/logs/log.dart';
|
||||
import 'package:lunasea/database/table.dart';
|
||||
import 'package:lunasea/system/logger.dart';
|
||||
import 'package:lunasea/vendor.dart';
|
||||
|
||||
@@ -51,10 +53,6 @@ enum LunaBox<T> {
|
||||
return _instance.delete(key);
|
||||
}
|
||||
|
||||
ValueListenable<Box<T>> listenable([List<dynamic>? keys]) {
|
||||
return _instance.listenable(keys: keys);
|
||||
}
|
||||
|
||||
Future<void> clear() async {
|
||||
_instance.keys.forEach((k) async => await _instance.delete(k));
|
||||
}
|
||||
@@ -62,6 +60,28 @@ enum LunaBox<T> {
|
||||
Future<Box<T>> _open() async {
|
||||
return Hive.openBox<T>(key);
|
||||
}
|
||||
|
||||
ValueListenable<Box<T>> listenable([List<dynamic>? keys]) {
|
||||
return _instance.listenable(keys: keys);
|
||||
}
|
||||
|
||||
ValueListenableBuilder watch({
|
||||
required Widget Function(BuildContext, Widget?) builder,
|
||||
List<dynamic>? selectKeys,
|
||||
List<LunaTableMixin>? selectItems,
|
||||
Key? key,
|
||||
Widget? child,
|
||||
}) {
|
||||
final items = selectItems?.map((item) => item.key).toList();
|
||||
final keys = [...?selectKeys, ...?items];
|
||||
|
||||
return ValueListenableBuilder(
|
||||
key: key,
|
||||
valueListenable: listenable(keys.isNotEmpty ? keys : null),
|
||||
builder: (context, _, widget) => builder(context, widget),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension LunaBoxExtension on LunaBox {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:lunasea/core/models/configuration/profile.dart';
|
||||
import 'package:lunasea/core/system/profile.dart';
|
||||
import 'package:lunasea/database/box.dart';
|
||||
import 'package:lunasea/database/table.dart';
|
||||
import 'package:lunasea/database/tables/lunasea.dart';
|
||||
import 'package:lunasea/system/platform.dart';
|
||||
import 'package:lunasea/system/profile.dart';
|
||||
import 'package:lunasea/vendor.dart';
|
||||
|
||||
class LunaDatabase {
|
||||
|
||||
@@ -90,15 +90,15 @@ mixin LunaTableMixin<T> on Enum {
|
||||
return update(value);
|
||||
}
|
||||
|
||||
ValueListenableBuilder listen({
|
||||
ValueListenableBuilder watch({
|
||||
required Widget Function(BuildContext, Widget?) builder,
|
||||
Key? key,
|
||||
Widget? child,
|
||||
}) {
|
||||
return ValueListenableBuilder(
|
||||
return box.watch(
|
||||
key: key,
|
||||
valueListenable: box.listenable([this.key]),
|
||||
builder: (context, _, widget) => builder(context, widget),
|
||||
selectItems: [this],
|
||||
builder: (context, widget) => builder(context, widget),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user