-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ExperimentalFeatureWrapper; Light refactor
- Loading branch information
1 parent
ecdc2cd
commit 218b55e
Showing
9 changed files
with
93 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
uni/lib/view/common_widgets/experimental_feature_wrapper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:uni/controller/local_storage/enabled_feature_controller.dart'; | ||
|
||
class ExperimentalFeatureWrapper extends StatefulWidget { | ||
const ExperimentalFeatureWrapper({ | ||
required this.featureCode, | ||
required this.child, | ||
super.key, | ||
}); | ||
|
||
final String featureCode; | ||
final Widget child; | ||
|
||
@override | ||
State<StatefulWidget> createState() => ExperimentalFeatureWrapperState(); | ||
} | ||
|
||
class ExperimentalFeatureWrapperState | ||
extends State<ExperimentalFeatureWrapper> { | ||
late Future<SharedPreferences> _preferences; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_preferences = SharedPreferences.getInstance(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FutureBuilder( | ||
future: _preferences, | ||
builder: (context, snapshot) { | ||
if (!snapshot.hasData) { | ||
return Container(); | ||
} | ||
|
||
final enabledFeatureController = | ||
EnabledFeatureController(snapshot.data!); | ||
return enabledFeatureController.existsFeature(widget.featureCode) | ||
? widget.child | ||
: Container(); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
...view/settings/widgets/generic_switch.dart → ...widgets/feature_flags/feature_switch.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 13 additions & 10 deletions
23
uni/lib/view/settings/widgets/feature_flags/library_modules_switch.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
import 'package:uni/controller/local_storage/enabled_feature_controller.dart'; | ||
import 'package:uni/view/settings/widgets/generic_switch.dart'; | ||
import 'package:uni/view/settings/widgets/feature_flags/feature_switch.dart'; | ||
|
||
class LibraryModulesSwitch extends GenericSwitch { | ||
class LibraryModulesSwitch extends FeatureSwitch { | ||
const LibraryModulesSwitch({ | ||
required this.enabledFeatureController, | ||
required super.enabledFeatureController, | ||
super.key, | ||
}); | ||
|
||
final EnabledFeatureController enabledFeatureController; | ||
|
||
@override | ||
GenericSwitchState<GenericSwitch> createState() => | ||
FeatureSwitchState<FeatureSwitch> createState() => | ||
LibraryModulesSwitchState(); | ||
} | ||
|
||
class LibraryModulesSwitchState | ||
extends GenericSwitchState<LibraryModulesSwitch> { | ||
extends FeatureSwitchState<LibraryModulesSwitch> { | ||
static const String _featureCode = 'library_modules'; | ||
|
||
@override | ||
bool initializeValue() { | ||
return widget.enabledFeatureController.existsFeature('library_cards'); | ||
return widget.enabledFeatureController.existsFeature(_featureCode); | ||
} | ||
|
||
@override | ||
Future<void> storeValue({required bool value}) async { | ||
await widget.enabledFeatureController.addFeature('library_cards'); | ||
if (value) { | ||
await widget.enabledFeatureController.addFeature(_featureCode); | ||
} else { | ||
await widget.enabledFeatureController.removeFeature(_featureCode); | ||
} | ||
} | ||
} |