2023-09-14 14:59:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
enum SelectableAspect { list, selected }
|
|
|
|
|
2024-11-03 19:16:01 +00:00
|
|
|
|
|
|
|
|
2023-09-14 14:59:16 +00:00
|
|
|
class SelectableInheritedModel<T> extends InheritedModel<SelectableAspect> {
|
|
|
|
const SelectableInheritedModel({
|
|
|
|
super.key,
|
|
|
|
required this.values,
|
|
|
|
required this.selected,
|
|
|
|
required super.child,
|
|
|
|
});
|
|
|
|
|
|
|
|
final List<T> values;
|
|
|
|
final T selected;
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool updateShouldNotify(SelectableInheritedModel oldWidget) => true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool updateShouldNotifyDependent(SelectableInheritedModel oldWidget, Set<SelectableAspect> dependencies) {
|
|
|
|
if (dependencies.contains(SelectableAspect.list)) {
|
|
|
|
return true;
|
|
|
|
} else if (dependencies.contains(SelectableAspect.selected)) {
|
|
|
|
return selected != oldWidget.selected;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|