Skip to content

Commit

Permalink
Add UI support for feature flag groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Process-ing committed Nov 11, 2024
1 parent 8f8d682 commit dca0002
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ List<GenericFeatureFlagInfo> featureFlagInfos = [
code: 'library_modules',
getName: (context) => S.of(context).library_modules,
),
FeatureFlagGroupInfo(
code: 'library',
getName: (context) => S.of(context).library_modules,
featureFlags: [
FeatureFlagInfo(
code: 'library_occupation',
getName: (context) => S.of(context).library_modules,
),
FeatureFlagInfo(
code: 'library_floors',
getName: (context) => S.of(context).library_modules,
),
],
),
];

class FeatureFlagTable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:uni/model/feature_flags/feature_flag.dart';
import 'package:uni/model/feature_flags/feature_flag_group.dart';
import 'package:uni/model/feature_flags/generic_feature_flag.dart';

class FeatureSwitchTile extends StatefulWidget {
Expand All @@ -25,12 +27,35 @@ class FeatureSwitchTileState extends State<FeatureSwitchTile> {

@override
Widget build(BuildContext context) {
return ListTile(
title: Text(widget.featureFlag.getName(context)),
trailing: Switch.adaptive(
value: widget.featureFlag.isEnabled(),
onChanged: _onChanged,
),
);
return widget.featureFlag is FeatureFlag
? ListTile(
title: Text(widget.featureFlag.getName(context)),
trailing: Switch.adaptive(
value: widget.featureFlag.isEnabled(),
onChanged: _onChanged,
),
)
: Column(
children: [
ListTile(
title: Text(
widget.featureFlag.getName(context),
),
trailing: Switch.adaptive(
value: widget.featureFlag.isEnabled(),
onChanged: _onChanged,
),
),
Padding(
padding: const EdgeInsets.only(left: 24),
child: Column(
children: (widget.featureFlag as FeatureFlagGroup)
.getFeatureFlags()
.map((featureFlag) => FeatureSwitchTile(featureFlag: featureFlag))
.toList(),
),
),
],
);
}
}

0 comments on commit dca0002

Please sign in to comment.