-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from alippo-com/fix/lateinit-of-featureDataModel
fix: late initialization error of the featureDataModel.
- Loading branch information
Showing
20 changed files
with
305 additions
and
168 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
import 'package:growthbook_sdk_flutter/growthbook_sdk_flutter.dart'; | ||
|
||
typedef FeatureFetchSuccessCallBack = void Function( | ||
FeaturedDataModel featuredDataModel, | ||
); | ||
|
||
abstract class FeaturesFlowDelegate { | ||
void featuresFetchedSuccessfully(GBFeatures gbFeatures); | ||
void featuresFetchFailed(GBError? error); | ||
} | ||
|
||
class FeatureDataSource { | ||
FeatureDataSource( | ||
{required this.context, required this.client, required this.onError}); | ||
FeatureDataSource({ | ||
required this.context, | ||
required this.client, | ||
}); | ||
final GBContext context; | ||
final BaseClient client; | ||
final OnError onError; | ||
|
||
Future<FeaturedDataModel> fetchFeatures() async { | ||
Future<void> fetchFeatures( | ||
FeatureFetchSuccessCallBack onSuccess, OnError onError) async { | ||
final api = context.hostURL! + Constant.featurePath + context.apiKey!; | ||
await client.consumeGetRequest(api, onSuccess, onError); | ||
setUpModel(); | ||
return model; | ||
} | ||
|
||
late FeaturedDataModel model; | ||
late Map<String, dynamic> data; | ||
|
||
/// Assign response to local variable [data] | ||
void onSuccess(response) { | ||
data = response; | ||
} | ||
|
||
/// Initialize [model] from the [data] | ||
void setUpModel() { | ||
model = FeaturedDataModel.fromJson(data); | ||
await client.consumeGetRequest( | ||
api, | ||
(response) => onSuccess( | ||
FeaturedDataModel.fromJson(response), | ||
), | ||
onError, | ||
); | ||
} | ||
} |
Oops, something went wrong.