getFlag method
Gets the value of a feature flag.
flagName
The name of the feature flag.
vwoContext
The user context for evaluating the flag.
Returns a Future that resolves to a GetFlag object containing the flag value and other metadata.
Implementation
@override
Future<GetFlag> getFlag({
required String flagName,
required VWOContext vwoContext,
}) async {
try {
final dynamic result = await methodChannel.invokeMethod('getFlag', {
'flagName': flagName,
'userContext': vwoContext.toMap(),
});
// Explicitly cast the result to Map<String, dynamic> if possible
if (result is Map) {
// We need to cast every entry in the map to ensure the correct types
final Map<String, dynamic> resultMap = {};
result.forEach((key, value) {
if (key is String) {
resultMap[key] = value; // Ensure value is dynamic
}
});
return GetFlag.fromMap(resultMap);
} else {
throw Exception("Expected result type Map<String, dynamic> but got ${result.runtimeType}");
}
} catch (e) {
return Future.error(e);
}
}