mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 10:29:06 +02:00
Fixes the notifier for feature flags and updates the example
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -147,6 +147,9 @@ class _ArcaneLoggingExampleState extends State<ArcaneLoggingExample> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return ValueListenableBuilder(
|
||||||
|
valueListenable: Arcane.features.notifier,
|
||||||
|
builder: (context, enabledFeatures, _) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
@@ -184,6 +187,8 @@ class _ArcaneLoggingExampleState extends State<ArcaneLoggingExample> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +205,9 @@ class ArcaneAuthExample extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return ValueListenableBuilder(
|
||||||
|
valueListenable: Arcane.features.notifier,
|
||||||
|
builder: (context, enabledFeatures, _) {
|
||||||
return Card(
|
return Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
@@ -242,6 +250,8 @@ class ArcaneAuthExample extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,6 +424,9 @@ class ArcaneFeatureFlagsExample extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return ValueListenableBuilder(
|
||||||
|
valueListenable: Arcane.features.notifier,
|
||||||
|
builder: (context, enabledFeatures, _) {
|
||||||
return Card(
|
return Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
@@ -451,6 +464,8 @@ class ArcaneFeatureFlagsExample extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ class ArcaneFeatureFlags extends ArcaneService {
|
|||||||
|
|
||||||
if (_enabledFeatures.contains(feature)) return I;
|
if (_enabledFeatures.contains(feature)) return I;
|
||||||
|
|
||||||
_enabledFeatures.add(feature);
|
_notifier.value = [..._enabledFeatures, feature];
|
||||||
_notifier.value.add(feature);
|
|
||||||
|
|
||||||
if (Arcane.logger.initialized) {
|
if (Arcane.logger.initialized) {
|
||||||
Arcane.logger.log(
|
Arcane.logger.log(
|
||||||
@@ -100,8 +99,7 @@ class ArcaneFeatureFlags extends ArcaneService {
|
|||||||
if (!I._initialized) _init();
|
if (!I._initialized) _init();
|
||||||
if (!_enabledFeatures.contains(feature)) return I;
|
if (!_enabledFeatures.contains(feature)) return I;
|
||||||
|
|
||||||
_enabledFeatures.remove(feature);
|
_notifier.value = [..._enabledFeatures]..removeWhere((i) => i == feature);
|
||||||
_notifier.value.remove(feature);
|
|
||||||
|
|
||||||
if (Arcane.logger.initialized) {
|
if (Arcane.logger.initialized) {
|
||||||
Arcane.logger.log(
|
Arcane.logger.log(
|
||||||
@@ -123,8 +121,9 @@ class ArcaneFeatureFlags extends ArcaneService {
|
|||||||
/// It is called automatically when enabling or disabling features if they haven't
|
/// It is called automatically when enabling or disabling features if they haven't
|
||||||
/// already been initialized.
|
/// already been initialized.
|
||||||
void _init() {
|
void _init() {
|
||||||
_enabledFeatures.clear();
|
_notifier.value = [];
|
||||||
_notifier.value.clear();
|
|
||||||
|
notifier.addListener(_listener);
|
||||||
|
|
||||||
I._initialized = true;
|
I._initialized = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -135,10 +134,15 @@ class ArcaneFeatureFlags extends ArcaneService {
|
|||||||
/// This method clears all enabled features, resets notification values,
|
/// This method clears all enabled features, resets notification values,
|
||||||
/// marks the flags as uninitialized, and notifies listeners of the changes.
|
/// marks the flags as uninitialized, and notifies listeners of the changes.
|
||||||
void reset() {
|
void reset() {
|
||||||
_enabledFeatures.clear();
|
_notifier.value = [];
|
||||||
_notifier.value.clear();
|
|
||||||
|
|
||||||
I._initialized = false;
|
I._initialized = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _listener() {
|
||||||
|
_enabledFeatures
|
||||||
|
..clear()
|
||||||
|
..addAll(notifier.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user