Skip to content

Commit

Permalink
Merge pull request #4 from tryVital/readme
Browse files Browse the repository at this point in the history
Added install section and version bump
  • Loading branch information
RuiAAPeres committed Aug 2, 2022
2 parents bb8c26e + a633d0a commit ca67b28
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 94 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.2.1

* HealthKit - split configure method into configureClient and configureHealthkit with auto sync, logging and background delivery options

## 0.2.0

* Support for HealthKit
Expand Down
9 changes: 7 additions & 2 deletions README.md
@@ -1,6 +1,10 @@
# vital_flutter

The official Flutter package for Vital API and HealthKit
The official Flutter package for Vital APIs allowing fitness apps linking with tryvital.io and with support for HealthKit.

## Installing

Package is available on [https://pub.dev](https://pub.dev/packages/vital_flutter/install).

## Getting Started

Expand Down Expand Up @@ -34,7 +38,8 @@ client.linkProvider(user, 'strava', 'vitalexample://callback');
2. To use HealthKit client you need to call configure first:

```dart
await client.healthkitServices.configure();
await client.healthkitServices.configureClient();
await client.healthkitServices.configureHealthkit(backgroundDeliveryEnabled: true);
```

3. Set User ID
Expand Down
3 changes: 2 additions & 1 deletion example/lib/vital_bloc.dart
Expand Up @@ -44,7 +44,8 @@ class VitalBloc {
}

void _connectHealthPlatform() async {
await client.healthkitServices.configure();
await client.healthkitServices.configureClient();
await client.healthkitServices.configureHealthkit(backgroundDeliveryEnabled: true);
}

void askForHealthResources() {
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Expand Up @@ -307,7 +307,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.0"
version: "0.2.1"
sdks:
dart: ">=2.17.0-206.0.dev <3.0.0"
flutter: ">=2.10.0"
27 changes: 23 additions & 4 deletions ios/Classes/SwiftVitalFlutterPlugin.swift
Expand Up @@ -26,8 +26,11 @@ public class SwiftVitalFlutterPlugin: NSObject, FlutterPlugin {
print("FlutterPlugin \(String(describing: call.method)) \(call.arguments ?? nil)")

switch call.method {
case "configure":
configure(call.arguments as! [String], result: result)
case "configureClient":
configureClient(call.arguments as! [String], result: result)
return
case "configureHealthkit":
configureHealthkit(call.arguments as! [Bool], result: result)
return
case "setUserId":
VitalClient.setUserId(UUID(uuidString: call.arguments as! String)!)
Expand Down Expand Up @@ -56,7 +59,7 @@ public class SwiftVitalFlutterPlugin: NSObject, FlutterPlugin {
details: nil))
}

private func configure(_ arguments: [String], result: @escaping FlutterResult){
private func configureClient(_ arguments: [String], result: @escaping FlutterResult){
let apiKey = arguments[0]
let region = arguments[1]
let environment = arguments[2]
Expand All @@ -65,7 +68,6 @@ public class SwiftVitalFlutterPlugin: NSObject, FlutterPlugin {
apiKey: apiKey,
environment: try resolveEnvironment(region: region, environment: environment)
)
VitalHealthKitClient.configure()
result(nil)
} catch VitalError.UnsupportedEnvironment(let errorMessage) {
result(encode(ErrorResult(code: "UnsupportedEnvironment", message: errorMessage)))
Expand All @@ -76,6 +78,23 @@ public class SwiftVitalFlutterPlugin: NSObject, FlutterPlugin {
}
}

private func configureHealthkit(_ arguments: [Bool], result: @escaping FlutterResult){
let autoSyncEnabled = arguments[0] as Bool
let backgroundDeliveryEnabled = arguments[1] as Bool
let logsEnabled = arguments[2] as Bool
do {
VitalHealthKitClient.configure(
.init(autoSyncEnabled: autoSyncEnabled,
backgroundDeliveryEnabled: backgroundDeliveryEnabled,
logsEnabled: logsEnabled
)
)
result(nil)
} catch {
result(encode(ErrorResult(code: "Unknown error")))
}
}

private func askForResources(resources: [String], result: @escaping FlutterResult){
Task {
do {
Expand Down
14 changes: 7 additions & 7 deletions lib/platform/data/sync_data.dart
Expand Up @@ -110,7 +110,7 @@ Object? fromArgument(HealthkitResource resource, String argument) {
}
}

@JsonSerializable()
@JsonSerializable(createToJson: false)
class ActivitySummary {
final DateTime date;
final List<QuantitySample> activeEnergyBurned;
Expand All @@ -133,7 +133,7 @@ class ActivitySummary {
factory ActivitySummary.fromJson(Map<String, dynamic> json) => _$ActivitySummaryFromJson(json);
}

@JsonSerializable()
@JsonSerializable(createToJson: false)
class BodySummary {
final List<QuantitySample> bodyMass;
final List<QuantitySample> bodyFatPercentage;
Expand All @@ -143,7 +143,7 @@ class BodySummary {
factory BodySummary.fromJson(Map<String, dynamic> json) => _$BodySummaryFromJson(json);
}

@JsonSerializable()
@JsonSerializable(createToJson: false)
class QuantitySample {
final String? id;
final double value;
Expand All @@ -166,7 +166,7 @@ class QuantitySample {
factory QuantitySample.fromJson(Map<String, dynamic> json) => _$QuantitySampleFromJson(json);
}

@JsonSerializable()
@JsonSerializable(createToJson: false)
class SleepSummary {
final String? id;
final DateTime startDate;
Expand Down Expand Up @@ -194,7 +194,7 @@ class SleepSummary {
factory SleepSummary.fromJson(Map<String, dynamic> json) => _$SleepSummaryFromJson(json);
}

@JsonSerializable()
@JsonSerializable(createToJson: false)
class WorkoutSummary {
final String? id;
final DateTime startDate;
Expand Down Expand Up @@ -222,7 +222,7 @@ class WorkoutSummary {
factory WorkoutSummary.fromJson(Map<String, dynamic> json) => _$WorkoutSummaryFromJson(json);
}

@JsonSerializable()
@JsonSerializable(createToJson: false)
class BloodPressureSample {
final QuantitySample systolic;
final QuantitySample diastolic;
Expand All @@ -244,7 +244,7 @@ enum BiologicalSex {
notSet,
}

@JsonSerializable()
@JsonSerializable(createToJson: false)
class ProfileSummary {
final BiologicalSex biologicalSex;
final DateTime? dateOfBirth;
Expand Down
69 changes: 0 additions & 69 deletions lib/platform/data/sync_data.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions lib/platform/healthkit_services.dart
Expand Up @@ -11,10 +11,10 @@ import 'package:vital_flutter/platform/healthkit_resource.dart';

class HealthkitServices {
var _statusSubscribed = false;
var _configured = false;
var _healthKitConfigured = false;
late final StreamController<SyncStatus> _streamController = StreamController(onListen: () async {
_statusSubscribed = true;
if (_configured) {
if (_healthKitConfigured) {
Fimber.d('Healthkit subscribeToStatus (stream)');
await _channel.invokeMethod('subscribeToStatus');
}
Expand Down Expand Up @@ -46,10 +46,19 @@ class HealthkitServices {
});
}

Future<void> configure() async {
Future<void> configureClient() async {
Fimber.d('Healthkit configure $_apiKey, $_region $_environment');
await _channel.invokeMethod('configure', [_apiKey, _region.name, _environment.name]);
_configured = true;
await _channel.invokeMethod('configureClient', [_apiKey, _region.name, _environment.name]);
}

Future<void> configureHealthkit({
bool autoSyncEnabled = false,
bool backgroundDeliveryEnabled = false,
bool logsEnabled = true,
}) async {
Fimber.d('Healthkit configureHealthkit $autoSyncEnabled, $backgroundDeliveryEnabled $logsEnabled');
await _channel.invokeMethod('configureHealthkit', [autoSyncEnabled, backgroundDeliveryEnabled, logsEnabled]);
_healthKitConfigured = true;
if (_statusSubscribed) {
Fimber.d('Healthkit subscribeToStatus (configure)');
await _channel.invokeMethod('subscribeToStatus');
Expand Down
3 changes: 0 additions & 3 deletions lib/vital_client.dart
Expand Up @@ -15,9 +15,6 @@ import 'package:vital_flutter/services/vitals_service.dart';
import 'package:vital_flutter/services/workout_service.dart';
import 'package:http/http.dart' as http;

import 'environment.dart';
import 'region.dart';

class VitalClient {
late final http.Client _httpClient;
late final String _baseUrl;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
@@ -1,6 +1,6 @@
name: vital_flutter
description: Official vital package for flutter.
version: 0.2.0
description: The official Flutter package for Vital APIs allowing fitness apps linking with tryvital.io and with support for HealthKit.
version: 0.2.1
homepage: https://tryvital.io/
repository: https://github.com/tryVital/vital-flutter

Expand Down

0 comments on commit ca67b28

Please sign in to comment.