Skip to content

Commit

Permalink
fix: eventType should be required positional param (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Apr 8, 2024
1 parent 7ba8f0c commit 1cb1f9b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 56 deletions.
2 changes: 1 addition & 1 deletion example/lib/event_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class _EventFormState extends State<EventForm> {

void onPress() {
AppState.of(context)
..analytics.track(BaseEvent(eventType: _controller.text))
..analytics.track(BaseEvent(_controller.text))
..setMessage('Event sent.');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/amplitude.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Amplitude {
/// (whichever comes first), as well as on app close.
///
/// ```
/// amplitude.track(BaseEvent(eventType: 'Button Clicked'))
/// amplitude.track(BaseEvent('Button Clicked'))
/// ```
Future<void> track(
BaseEvent event, [
Expand Down
93 changes: 47 additions & 46 deletions lib/events/base_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,51 @@ class BaseEvent extends EventOptions {
Map<String, dynamic>? groups;
Map<String, dynamic>? groupProperties;

BaseEvent({
String? userId,
String? deviceId,
int? timestamp,
int? eventId,
int? sessionId,
String? insertId,
double? locationLat,
double? locationLng,
String? appVersion,
String? versionName,
String? platform,
String? osName,
String? osVersion,
String? deviceBrand,
String? deviceManufacturer,
String? deviceModel,
String? carrier,
String? country,
String? region,
String? city,
String? dma,
String? idfa,
String? idfv,
String? adid,
String? appSetId,
String? androidId,
String? language,
String? library,
String? ip,
Plan? plan,
IngestionMetadata? ingestionMetadata,
double? revenue,
double? price,
int? quantity,
String? productId,
String? revenueType,
Map<String, dynamic>? extra,
String? partnerId,
required this.eventType,
this.eventProperties,
this.userProperties,
this.groups,
this.groupProperties,
}) : super(
BaseEvent(
this.eventType, {
String? userId,
String? deviceId,
int? timestamp,
int? eventId,
int? sessionId,
String? insertId,
double? locationLat,
double? locationLng,
String? appVersion,
String? versionName,
String? platform,
String? osName,
String? osVersion,
String? deviceBrand,
String? deviceManufacturer,
String? deviceModel,
String? carrier,
String? country,
String? region,
String? city,
String? dma,
String? idfa,
String? idfv,
String? adid,
String? appSetId,
String? androidId,
String? language,
String? library,
String? ip,
Plan? plan,
IngestionMetadata? ingestionMetadata,
double? revenue,
double? price,
int? quantity,
String? productId,
String? revenueType,
Map<String, dynamic>? extra,
String? partnerId,
this.eventProperties,
this.userProperties,
this.groups,
this.groupProperties,
}) : super(
userId: userId,
deviceId: deviceId,
timestamp: timestamp,
Expand Down Expand Up @@ -131,7 +131,8 @@ class BaseEvent extends EventOptions {
if (library != null) 'library': library,
if (ip != null) 'ip': ip,
if (plan != null) 'plan': plan?.toMap(),
if (ingestionMetadata != null) 'ingestion_metadata': ingestionMetadata?.toMap(),
if (ingestionMetadata != null)
'ingestion_metadata': ingestionMetadata?.toMap(),
if (revenue != null) 'revenue': revenue,
if (price != null) 'price': price,
if (quantity != null) 'quantity': quantity,
Expand Down
2 changes: 1 addition & 1 deletion lib/events/group_identify_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import '../constants.dart';
import 'base_event.dart';

class GroupIdentifyEvent extends BaseEvent {
GroupIdentifyEvent() : super(eventType: Constants.groupIdentifyEvent);
GroupIdentifyEvent() : super(Constants.groupIdentifyEvent);
}
2 changes: 1 addition & 1 deletion lib/events/identify_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import '../constants.dart';
import 'base_event.dart';

class IdentifyEvent extends BaseEvent {
IdentifyEvent() : super(eventType: Constants.identifyEvent);
IdentifyEvent() : super(Constants.identifyEvent);
}
2 changes: 1 addition & 1 deletion lib/events/revenue_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import '../constants.dart';
import 'base_event.dart';

class RevenueEvent extends BaseEvent {
RevenueEvent() : super(eventType: Constants.revenueEvent);
RevenueEvent() : super(Constants.revenueEvent);
}
2 changes: 1 addition & 1 deletion test/amplitude_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void main() {
// Pass it for FlutterLibraryPlugin
'library': '${Constants.packageName}/${Constants.packageVersion}'
};
final testEvent = BaseEvent(eventType: 'testEvent');
final testEvent = BaseEvent('testEvent');
final testEventMap = {
'event_type': 'testEvent',
'attempts': 0,
Expand Down
8 changes: 4 additions & 4 deletions test/events/base_event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main() {
group('BaseEvent', () {
test('Should init with default values', () {
final testEventType = 'test-event-type';
final event = BaseEvent(eventType: testEventType);
final event = BaseEvent(testEventType);

expect(event.eventType, testEventType);
expect(event.eventProperties, isNull);
Expand All @@ -30,7 +30,7 @@ void main() {
'test-group-property-key': 'test-group-property-value'
};
final event = BaseEvent(
eventType: testEventType,
testEventType,
eventProperties: testEventProperties,
userProperties: testUserProperties,
groups: testGroups,
Expand Down Expand Up @@ -86,6 +86,7 @@ void main() {
final partnerId = 'partner_id';

final event = BaseEvent(
eventType,
userId: userId,
deviceId: deviceId,
timestamp: timestamp,
Expand Down Expand Up @@ -124,7 +125,6 @@ void main() {
revenueType: revenueType,
extra: extra,
partnerId: partnerId,
eventType: eventType,
);

final expectedMap = {
Expand Down Expand Up @@ -179,7 +179,7 @@ void main() {
final deviceId = 'device_id';
final eventType = 'event_type';

final originalEvent = BaseEvent(userId: originalUserId, deviceId: deviceId, eventType: eventType);
final originalEvent = BaseEvent(eventType, userId: originalUserId, deviceId: deviceId);
final newOptions = EventOptions(userId: newUserId);

originalEvent.mergeEventOptions(newOptions);
Expand Down

0 comments on commit 1cb1f9b

Please sign in to comment.