Skip to content

Commit

Permalink
Fix invalid parsing on Android (#3)
Browse files Browse the repository at this point in the history
* Fix invalid parsing
* Upgrade to 2.0.0
  • Loading branch information
nickoto committed Apr 6, 2021
1 parent 59e1a29 commit 2b7893e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 92 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
@@ -1,4 +1,4 @@
## 1.1.0
## 2.0.0

* Migrate to nullsafety

Expand Down
13 changes: 6 additions & 7 deletions integration_test/lib/main.dart
Expand Up @@ -457,14 +457,13 @@ class _MyAppState extends State<MyApp> {
"Result expected to contain 'FlutterCodeBlockTest'");

var fcbt = result['FlutterCodeBlockTest']!;
assertFalse(fcbt.isInstantUpdate, "isInstantUpdate");
assertTrue(fcbt.instantUpdateName == null || fcbt.instantUpdateName.isEmpty,
"instantUpdateName is not empty");
assertEqual(1599869, fcbt.winningExperimentId, "winningExperimentId");
assertEqual('FlutterCodeBlockTest', fcbt.winningExperimentName,
var fcbtWinner = fcbt as ApptimizeWinnerInfo;

assertEqual(1599869, fcbtWinner.winningExperimentId, "winningExperimentId");
assertEqual('FlutterCodeBlockTest', fcbtWinner.winningExperimentName,
"winningExperimentName");
assertEqual(5259302, fcbt.winningVariantId, "winningVariantId");
assertEqual('Variant B', fcbt.winningVariantName, "winningVariantName");
assertEqual(5259302, fcbtWinner.winningVariantId, "winningVariantId");
assertEqual('Variant B', fcbtWinner.winningVariantName, "winningVariantName");
}

Future<void> testGetSetUserAttribute() async {
Expand Down
2 changes: 1 addition & 1 deletion ios/apptimize_flutter.podspec
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'apptimize_flutter'
s.version = '1.1.0'
s.version = '2.0.0'
s.summary = 'Apptimize SDK wrapper for iOS'
s.description = <<-DESC
Apptimize SDK wrapper for iOS.
Expand Down
184 changes: 102 additions & 82 deletions lib/apptimize_flutter.dart
Expand Up @@ -1500,39 +1500,11 @@ class ApptimizeMetaDataState {
this.isAvailable, this.isUpToDate, this.isRefreshing);
}

/// Information about a single winning A/B test or instant update this device
/// will display.
/// Base class for information about a single winning A/B test or instant update
/// this device will display.
///
/// See [ApptimizeInstantUpdate] or [ApptimizeWinnerInfo].
class ApptimizeInstantUpdateOrWinnerInfo {
/// The experiment is an instant update.
///
/// Returns `true` if this info represents an instant update, otherwise this
/// object represents a winning experiment.
final bool isInstantUpdate;

/// The experiment name of the winning experiment.
final String winningExperimentName;

/// The experiment id of the winning experiment.
final int winningExperimentId;

/// The name of the instant update.
final String instantUpdateName;

/// The id of the instant update.
final int instantUpdateId;

/// The name of the winning variant.
///
/// If this is a winner, then this is the name of the winning variant.
/// Otherwise it is `null`.
final String winningVariantName;

/// The id of the winning variant
///
/// If this is a winner, then this is the unique numeric id of the winning
/// variant. Otherwise it is `null`.
final int winningVariantId;

/// The date this device would start showing the winning variant or instant
/// update.
///
Expand All @@ -1550,16 +1522,10 @@ class ApptimizeInstantUpdateOrWinnerInfo {
final String anonymousUserId;

const ApptimizeInstantUpdateOrWinnerInfo(
this.isInstantUpdate,
this.winningExperimentName,
this.winningExperimentId,
this.instantUpdateName,
this.instantUpdateId,
this.winningVariantName,
this.winningVariantId,
this.startDate,
this.userId,
this.anonymousUserId);
DateTime startDate,
String? userId,
String anonymousUserId
) : startDate = startDate, userId = userId, anonymousUserId = anonymousUserId;

static ApptimizeInstantUpdateOrWinnerInfo? _fromMap(
Map<dynamic, dynamic> map) {
Expand All @@ -1582,42 +1548,6 @@ class ApptimizeInstantUpdateOrWinnerInfo {
name: Apptimize._logTag);
return null;
}
if (winningExperimentName == null) {
developer.log(
"Missing `winningExperimentName` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (winningExperimentId == null) {
developer.log(
"Missing `winningExperimentId` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (instantUpdateName == null) {
developer.log(
"Missing `instantUpdateName` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (instantUpdateId == null) {
developer.log(
"Missing `instantUpdateId` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (winningVariantName == null) {
developer.log(
"Missing `winningVariantName` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (winningVariantId == null) {
developer.log(
"Missing `winningVariantId` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (startDate == null) {
developer.log(
"Missing `startDate` in `ApptimizeInstantUpdateOrWinnerInfo` map",
Expand All @@ -1631,20 +1561,110 @@ class ApptimizeInstantUpdateOrWinnerInfo {
return null;
}

return new ApptimizeInstantUpdateOrWinnerInfo(
isInstantUpdate,
winningExperimentName,
winningExperimentId,
if (isInstantUpdate) {
if (instantUpdateName == null) {
developer.log(
"Missing `instantUpdateName` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (instantUpdateId == null) {
developer.log(
"Missing `instantUpdateId` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
return new ApptimizeInstantUpdate(
instantUpdateName,
instantUpdateId,
startDate,
userId,
anonymousUserId);
} else {
if (winningExperimentName == null) {
developer.log(
"Missing `winningExperimentName` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (winningExperimentId == null) {
developer.log(
"Missing `winningExperimentId` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (winningVariantName == null) {
developer.log(
"Missing `winningVariantName` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
if (winningVariantId == null) {
developer.log(
"Missing `winningVariantId` in `ApptimizeInstantUpdateOrWinnerInfo` map",
name: Apptimize._logTag);
return null;
}
return new ApptimizeWinnerInfo(
winningExperimentName,
winningExperimentId,
winningVariantName,
winningVariantId,
startDate,
userId,
anonymousUserId);
}
}
}

/// Information about a single winning A/B test this device will display.
class ApptimizeWinnerInfo extends ApptimizeInstantUpdateOrWinnerInfo {
/// The experiment name of the winning experiment.
final String winningExperimentName;

/// The experiment id of the winning experiment.
final int winningExperimentId;

/// The name of the winning variant.
///
/// If this is a winner, then this is the name of the winning variant.
/// Otherwise it is `null`.
final String winningVariantName;

/// The id of the winning variant
///
/// If this is a winner, then this is the unique numeric id of the winning
/// variant. Otherwise it is `null`.
final int winningVariantId;

const ApptimizeWinnerInfo(
this.winningExperimentName,
this.winningExperimentId,
this.winningVariantName,
this.winningVariantId,
DateTime startDate,
String? userId,
String anonymousUserId
) : super(startDate, userId, anonymousUserId);
}

/// Information about a single instant update this device will display.
class ApptimizeInstantUpdate extends ApptimizeInstantUpdateOrWinnerInfo {
/// The name of the instant update.
final String instantUpdateName;

/// The id of the instant update.
final int instantUpdateId;

const ApptimizeInstantUpdate(
this.instantUpdateName,
this.instantUpdateId,
DateTime startDate,
String? userId,
String anonymousUserId
) : super(startDate, userId, anonymousUserId);
}

/// This enumerated type is used to indicate why the user has been unenrolled
/// from a given experiment.
enum ApptimizeUnenrollmentReason {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: apptimize_flutter
description: Apptimize Library for AB testing Flutter applications.
version: 1.1.0
version: 2.0.0
homepage: https://www.apptimize.com
repository: https://github.com/urbanairship/apptimize-flutter/

Expand Down

0 comments on commit 2b7893e

Please sign in to comment.