mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 02:19:08 +02:00
Added examples for feature flags
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
enum Feature {
|
||||
logging(true),
|
||||
authentication(true),
|
||||
;
|
||||
|
||||
final bool enabledAtStartup;
|
||||
|
||||
+61
-4
@@ -102,6 +102,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
maxCrossAxisExtent: 300,
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
// Theme
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@@ -216,6 +217,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Arcane.log(
|
||||
"Setting ${Arcane.theme.currentThemeMode.name} theme color to ${themeColors[index]}",
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
color: themeColors[index],
|
||||
@@ -238,6 +243,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Authentication
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@@ -250,8 +257,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(isSignedIn ? "Sign out" : "Sign in"),
|
||||
onPressed: () async {
|
||||
onPressed: Feature.authentication.enabled
|
||||
? () async {
|
||||
if (isSignedIn) {
|
||||
await Arcane.auth.logOut(
|
||||
onLoggedOut: () async {
|
||||
@@ -269,7 +276,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
: null,
|
||||
child: Text(isSignedIn ? "Sign out" : "Sign in"),
|
||||
),
|
||||
Center(
|
||||
child: Text("Status: ${Arcane.auth.status.name}"),
|
||||
@@ -278,9 +287,50 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Feature flags
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
"Feature Flags",
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: Feature.values.length,
|
||||
itemBuilder: (context, i) {
|
||||
final Feature feature = Feature.values[i];
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(feature.name),
|
||||
Switch(
|
||||
value: feature.enabled,
|
||||
onChanged: (_) {
|
||||
feature.enabled
|
||||
? feature.disable()
|
||||
: feature.enable();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Logging
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SizedBox(
|
||||
@@ -299,6 +349,13 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
if (Feature.logging.disabled)
|
||||
Text(
|
||||
"Logging feature is disabled.",
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: latestLogs.length,
|
||||
@@ -320,7 +377,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
super.initState();
|
||||
_subscription = Arcane.logger.logStream.listen((message) {
|
||||
setState(() {
|
||||
latestLogs.insert(0, message);
|
||||
if (Feature.logging.enabled) latestLogs.insert(0, message);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user