Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Null safety (#16)
Browse files Browse the repository at this point in the history
* null safety migration

* update ver
  • Loading branch information
Jason Rai authored Apr 6, 2021
1 parent 0733682 commit cff05d9
Show file tree
Hide file tree
Showing 24 changed files with 156 additions and 175 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Changelog
## [0.11.0] Apr 6, 2021
- Null safety migration
- Many breaking changes in the API to simplify the codebase and reduce dependencies

## [0.10.0] - 2021-03-08
## [0.10.0] Mar 8, 2021
- **Android:** Stop logging of Snowplow success/failure message in the Console IF LogLevel is set to OFF

## [0.9.2] - 2020-07-06
## [0.9.2] Jul 6, 2020
### Added
- **Flutter:** formatting issues fixed by `flutter format`

## [0.9.1] - 2020-07-05
## [0.9.1] Jul 5, 2020
### Added
- **Flutter:** Example application credentials updated

## [0.9.0] - 2020-07-04
## [0.9.0] Jul 5, 2020
### Added
- **Flutter:** Tracker initialization, Subject setter and event tracking
- **Android:** Tracker, Emitter and Subject creation
Expand Down
38 changes: 15 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,21 @@ Initialize it then call the relevant tracking method:
```Dart
import 'package:snowplow_flutter_tracker/snowplow_flutter_tracker.dart';
/* Initialize it */
SnowplowFlutterTracker _tracker;
final emitter = EmitterBuilder('test-uri')
.setRequestSecurity(RequestSecurity.HTTPS)
.build();
final tracker =
TrackerBuilder(emitter, 'eventTracker', 'test-appId')
.setMobileContext(true)
.build();
_tracker = SnowplowFlutterTracker();
// Initialize it
final emitter = Emitter(uri: 'your-collector-endpoint-url');
final tracker = Tracker(
emitter: emitter,
namespace: 'your-namespace',
appId: 'your-appId',
);
var _tracker = SnowplowFlutterTracker();
_tracker.initialize(tracker);
/* Usage */
final eventJson = SelfDescribingJsonBuilder()
.setSchema('iglu:mobile/generic/jsonschema/1-0-0')
.setPayload(
<String, Object>{'name': 'test-name', 'parameters': 'test-parameters'}).build();
final selfDescribingEvent =
SelfDescribingBuilder().setEventData(eventJson).build();
_tracker.track(selfDescribingEvent);
// Usage
final selfDescribingJson = SelfDescribingJson(
schema: 'iglu:com.acme/event/jsonschema/1-0-0',
payload: <String, Object>{'message': 'hello world'},
);
final selfDescribing = SelfDescribing(selfDescribingJson);
_tracker.track(selfDescribing);
```
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
SnowplowFlutterTracker _tracker;
late SnowplowFlutterTracker _tracker;

@override
void initState() {
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "1.0.2"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -94,7 +94,7 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
version: "1.11.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -164,5 +164,5 @@ packages:
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.12.0"
8 changes: 3 additions & 5 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ publish_to: 'none'
version: 1.0.0

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
cupertino_icons: ^1.0.2

dev_dependencies:
flutter_test:
sdk: flutter

snowplow_flutter_tracker:
path: ../
pedantic: 1.9.0
pedantic: ^1.11.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
2 changes: 1 addition & 1 deletion example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
expect(
find.byWidgetPredicate(
(Widget widget) =>
widget is Text && widget.data.startsWith('Running on:'),
widget is Text && widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/emitter/emitter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Emitter {

/// Create an [Emitter]
Emitter({
@required this.uri,
required this.uri,
this.httpMethod = HttpMethod.post,
this.bufferOption = BufferOption.defaultGroup,
this.requestSecurity = RequestSecurity.http,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/abstract_event.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// [AbstractEvent] Base class of all the events.
abstract class AbstractEvent {
/// Converts the event object to JSON.
Map<String, Object> toMap() {
Map<String, Object?> toMap() {
return {};
}
}
10 changes: 5 additions & 5 deletions lib/src/events/consent_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import 'package:flutter/foundation.dart';
@immutable
class ConsentDocument {
/// [documentId] The document ID.
final String documentId;
final String? documentId;

/// [documentVersion] The version of the document.
final String documentVersion;
final String? documentVersion;

/// [documentName] Name of the consent document.
final String documentName;
final String? documentName;

/// [documentDescription] The consent document description.
final String documentDescription;
final String? documentDescription;

/// Create a [ConsentDocument]
ConsentDocument({
Expand All @@ -24,7 +24,7 @@ class ConsentDocument {
});

/// Converts the consent document object to JSON.
Map<String, Object> toMap() {
Map<String, Object?> toMap() {
return {
'documentId': documentId,
'documentVersion': documentVersion,
Expand Down
27 changes: 12 additions & 15 deletions lib/src/events/consent_granted.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,39 @@ class ConsentGranted implements AbstractEvent {
final String documentVersion;

/// [expiry] The associated consent document expiry.
final String expiry;
final String? expiry;

/// [documentName] The associated consent document name.
final String documentName;
final String? documentName;

/// [documentDescription] The associated consent document description.
final String documentDescription;
final String? documentDescription;

/// [consentDocuments] An array of associated consent documents.
final List<ConsentDocument> consentDocuments;

/// Create a [ConsentGranted] event
ConsentGranted({
@required this.documentId,
@required this.documentVersion,
required this.documentId,
required this.documentVersion,
this.expiry,
this.documentName,
this.documentDescription,
this.consentDocuments,
}) : assert(documentId != null && documentId.isNotEmpty,
'documentId cannot be null or empty'),
assert(documentVersion != null && documentVersion.isNotEmpty,
'documentVersion cannot be null or empty');
this.consentDocuments = const [],
}) : assert(documentId.isNotEmpty, 'documentId cannot be empty'),
assert(documentVersion.isNotEmpty, 'documentVersion cannot be empty');

@override
Map<String, Object> toMap() {
Map<String, Object?> toMap() {
return {
'expiry': expiry,
'documentId': documentId,
'documentVersion': documentVersion,
'documentName': documentName,
'documentDescription': documentDescription,
'consentDocuments':
consentDocuments.map((ConsentDocument consentDocument) {
return consentDocument.toMap();
}).toList(),
'consentDocuments': consentDocuments
.map((ConsentDocument consentDocument) => consentDocument.toMap())
.toList(),
};
}
}
21 changes: 10 additions & 11 deletions lib/src/events/consent_withdrawn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import 'consent_document.dart';
@immutable
class ConsentWithdrawn implements AbstractEvent {
/// [all] Whether all consent is to be withdrawn.
final bool all;
final bool? all;

/// [documentId] The document ID.
final String documentId;
final String? documentId;

/// [documentVersion] The document's version.
final String documentVersion;
final String? documentVersion;

/// [documentName] The name of the consent document.
final String documentName;
final String? documentName;

/// [documentDescription] The consent document description.
final String documentDescription;
final String? documentDescription;

/// [consentDocuments] An array of associated documents.
final List<ConsentDocument> consentDocuments;
Expand All @@ -31,21 +31,20 @@ class ConsentWithdrawn implements AbstractEvent {
this.documentVersion,
this.documentName,
this.documentDescription,
this.consentDocuments,
this.consentDocuments = const [],
});

@override
Map<String, Object> toMap() {
Map<String, Object?> toMap() {
return {
'all': all,
'documentId': documentId,
'documentVersion': documentVersion,
'documentName': documentName,
'documentDescription': documentDescription,
'consentDocuments':
consentDocuments.map((ConsentDocument consentDocument) {
return consentDocument.toMap();
}).toList(),
'consentDocuments': consentDocuments
.map((ConsentDocument consentDocument) => consentDocument.toMap())
.toList(),
};
}
}
38 changes: 17 additions & 21 deletions lib/src/events/ecommerce_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EcommerceTransaction implements AbstractEvent {
final double totalValue;

/// [affiliation] Transaction affiliation.
final String affiliation;
final String? affiliation;

/// [taxValue] Transaction tax value.
final double taxValue;
Expand All @@ -22,42 +22,37 @@ class EcommerceTransaction implements AbstractEvent {
final double shipping;

/// [city] Delivery address city.
final String city;
final String? city;

/// [state] Delivery address state.
final String state;
final String? state;

/// [country] Delivery address country.
final String country;
final String? country;

/// [currency] Transaction currency.
final String currency;
final String? currency;

/// [items] An array of items in the transaction.
final List<EcommerceTransactionItem> items;

/// Create a [EcommerceTransaction] event
EcommerceTransaction({
@required this.orderId,
@required this.totalValue,
required this.orderId,
required this.totalValue,
this.affiliation,
@required this.taxValue,
@required this.shipping,
required this.taxValue,
required this.shipping,
this.city,
this.state,
this.country,
this.currency,
@required this.items,
}) : assert(orderId != null && orderId.isNotEmpty,
'orderId cannot be null or empty'),
assert(totalValue != null, 'totalValue cannot be null'),
assert(taxValue != null, 'taxValue cannot be null'),
assert(shipping != null, 'shipping cannot be null'),
assert(
items != null && items.isNotEmpty, 'items cannot be null or empty');
required this.items,
}) : assert(orderId.isNotEmpty, 'orderId cannot be empty'),
assert(items.isNotEmpty, 'items cannot be empty');

@override
Map<String, Object> toMap() {
Map<String, Object?> toMap() {
return {
'orderId': orderId,
'totalValue': totalValue,
Expand All @@ -68,9 +63,10 @@ class EcommerceTransaction implements AbstractEvent {
'state': state,
'country': country,
'currency': currency,
'items': items.map((EcommerceTransactionItem ecommerceTransactionItem) {
return ecommerceTransactionItem.toMap();
}).toList(),
'items': items
.map((EcommerceTransactionItem ecommerceTransactionItem) =>
ecommerceTransactionItem.toMap())
.toList(),
};
}
}
Loading

0 comments on commit cff05d9

Please sign in to comment.