diff --git a/packages/uni_app/lib/view/settings/widgets/feature_flags/feature_flags_dialog.dart b/packages/uni_app/lib/view/settings/widgets/feature_flags/feature_flags_dialog.dart index e44cf9203..c9aeecba4 100644 --- a/packages/uni_app/lib/view/settings/widgets/feature_flags/feature_flags_dialog.dart +++ b/packages/uni_app/lib/view/settings/widgets/feature_flags/feature_flags_dialog.dart @@ -4,23 +4,9 @@ import 'package:uni/controller/feature_flags/feature_flag_table.dart'; import 'package:uni/generated/l10n.dart'; import 'package:uni/view/settings/widgets/feature_flags/feature_switch_tile.dart'; -class FeatureFlagsDialog extends StatefulWidget { +class FeatureFlagsDialog extends StatelessWidget { const FeatureFlagsDialog({super.key}); - @override - FeatureFlagsDialogState createState() => FeatureFlagsDialogState(); -} - -class FeatureFlagsDialogState extends State { - @override - void initState() { - super.initState(); - } - - void refresh() { - setState(() {}); - } - @override Widget build(BuildContext context) { return AlertDialog( @@ -28,12 +14,7 @@ class FeatureFlagsDialogState extends State { content: Column( mainAxisSize: MainAxisSize.min, children: FeatureFlagTable.getFeatureFlags() - .map( - (featureFlag) => FeatureSwitchTile( - featureFlag: featureFlag, - refreshDialog: refresh, - ), - ) + .map((featureFlag) => FeatureSwitchTile(featureFlag: featureFlag)) .toList(), ), ); diff --git a/packages/uni_app/lib/view/settings/widgets/feature_flags/feature_switch_tile.dart b/packages/uni_app/lib/view/settings/widgets/feature_flags/feature_switch_tile.dart index e3fe19b58..7865e73a7 100644 --- a/packages/uni_app/lib/view/settings/widgets/feature_flags/feature_switch_tile.dart +++ b/packages/uni_app/lib/view/settings/widgets/feature_flags/feature_switch_tile.dart @@ -1,26 +1,35 @@ import 'package:flutter/material.dart'; import 'package:uni/model/feature_flags/generic_feature_flag.dart'; -class FeatureSwitchTile extends StatelessWidget { +class FeatureSwitchTile extends StatefulWidget { const FeatureSwitchTile({ required this.featureFlag, - required this.refreshDialog, super.key, }); final GenericFeatureFlag featureFlag; - final void Function() refreshDialog; + + @override + FeatureSwitchTileState createState() => FeatureSwitchTileState(); +} + +class FeatureSwitchTileState extends State { + void refresh() { + setState(() {}); + } + + Future _onChanged(bool value) async { + await widget.featureFlag.setEnabled(enabled: value); + refresh(); + } @override Widget build(BuildContext context) { return ListTile( - title: Text(featureFlag.getName(context)), + title: Text(widget.featureFlag.getName(context)), trailing: Switch.adaptive( - value: featureFlag.isEnabled(), - onChanged: (value) async { - await featureFlag.setEnabled(enabled: value); - refreshDialog(); - }, + value: widget.featureFlag.isEnabled(), + onChanged: _onChanged, ), ); }