Skip to content

Commit

Permalink
Add log out feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sgusakovsky committed Jan 12, 2024
1 parent e120e13 commit 5326b35
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
9 changes: 9 additions & 0 deletions example/lib/title_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class _TitleScreenState extends State<TitleScreen> {
onPressed: _isSdkEnabled ? _onForceDisableSDK : null,
child: const Text('Force Disable SDK with upload'),
),
ElevatedButton(
onPressed: !_isSdkEnabled && _deviceId.isNotEmpty ? _onLogout : null,
child: const Text('Log out'),
),
_sizedBoxSpace,
ElevatedButton(
onPressed: () async {
Expand Down Expand Up @@ -253,6 +257,11 @@ class _TitleScreenState extends State<TitleScreen> {
setState(() {});
}

Future<void> _onLogout() async {
_tokenEditingController.text = '';
await _trackingApi.clearDeviceID();
}

Future<void> _onPermissionsSDK() async {
if (!_isAllRequiredPermissionsGranted) {
_trackingApi.showPermissionWizard(
Expand Down
33 changes: 32 additions & 1 deletion ios/Classes/SwiftTelematicsSDKPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe
getRTLDData(result)
case "getCurrentSpeed":
getCurrentSpeed(result)
case "getTracks":
getTracks(call, result)
default:
print("not implemented")
}
Expand Down Expand Up @@ -294,7 +296,36 @@ public class SwiftTelematicsSDKPlugin: NSObject, FlutterPlugin, RPLowPowerModeDe
self.channel?.invokeMethod("onRtldCollectedData", arguments: state)
}


// MARK: - Tracks
private func getTracks(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) {
let args = call.arguments as! [String: Any]
let offset = args["offset"] as! Int
let limit = args["limit"] as! Int
let startDate = args["startDate"] as? String
let endDate = args["endDate"] as? String

let utcISODateFormatter = ISO8601DateFormatter()

RPEntry.instance().api.getTracks(
UInt(offset),
limit: UInt(limit),
start: utcISODateFormatter.date(from: startDate ?? ""),
end: utcISODateFormatter.date(from: endDate ?? "")
) { response, error in
if let error {
result(FlutterError(code: FlutterPluginCode.failure,
message: error.localizedDescription,
details: nil)
)
return
}

guard let feed = response as? RPFeed else {
return
}

}
}

//MARK: - Track tags

Expand Down
4 changes: 2 additions & 2 deletions lib/src/tracking_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ class TrackingApi {

//TO DO - add getTracks function to SwiftTelematicsSDKPlugin
Future<Iterable<TrackProcessed>?> getTracks({
required UnsignedInt offset,
required UnsignedInt limit,
required int offset,
required int limit,
DateTime? startDate,
DateTime? endDate
}) => _channel.invokeMethod<Iterable<String>>('getTracks', {
Expand Down

0 comments on commit 5326b35

Please sign in to comment.