-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87189c7
commit 8f8d682
Showing
2 changed files
with
12 additions
and
61 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
packages/uni_app/lib/controller/local_storage/enabled_feature_controller.dart
This file was deleted.
Oops, something went wrong.
46 changes: 12 additions & 34 deletions
46
packages/uni_app/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 |
---|---|---|
@@ -1,46 +1,24 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:uni/controller/local_storage/enabled_feature_controller.dart'; | ||
import 'package:uni/model/feature_flags/generic_feature_flag.dart'; | ||
|
||
class ExperimentalFeatureWrapper extends StatefulWidget { | ||
class ExperimentalFeatureWrapper extends StatelessWidget { | ||
const ExperimentalFeatureWrapper({ | ||
required this.featureCode, | ||
required this.child, | ||
required this.featureFlag, | ||
required this.onEnabled, | ||
this.onDisabled = _defaultOnDisabled, | ||
super.key, | ||
}); | ||
|
||
final String featureCode; | ||
final Widget child; | ||
final GenericFeatureFlag featureFlag; | ||
final Widget Function(BuildContext) onEnabled; | ||
final Widget Function(BuildContext) onDisabled; | ||
|
||
@override | ||
State<StatefulWidget> createState() => ExperimentalFeatureWrapperState(); | ||
} | ||
|
||
class ExperimentalFeatureWrapperState | ||
extends State<ExperimentalFeatureWrapper> { | ||
late Future<SharedPreferences> _preferences; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_preferences = SharedPreferences.getInstance(); | ||
static Widget _defaultOnDisabled(BuildContext context) { | ||
return Container(); | ||
} | ||
|
||
@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(); | ||
}, | ||
); | ||
return featureFlag.isEnabled() ? onEnabled(context) : onDisabled(context); | ||
} | ||
} |