Skip to content

Commit

Permalink
Expose "setOffline" method (#142)
Browse files Browse the repository at this point in the history
* Expose "setOffline" method

* Fixing code style issues

---------

Co-authored-by: Nishith <[email protected]>
  • Loading branch information
nishiths23 and Nishith authored Jul 24, 2023
1 parent 5d2a586 commit 01c99e7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler {
result.success("setServerZone called..")
}

"setOffline" -> {
val client = Amplitude.getInstance(instanceName)
client.setOffline(json.getBoolean("offline"))

result.success("setOffline called..")
}

else -> {
result.notImplemented()
}
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/SwiftAmplitudeFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ import Amplitude
Amplitude.instance(withName: instanceName).setServerZone(ampServerZone, updateServerUrl: updateServerUrl)
result(true)

case "setOffline":
let offline = args["offline"] as! Bool
Amplitude.instance(withName: instanceName).setOffline(offline)
result(true)

default:
result(FlutterMethodNotImplemented)
}
Expand Down
9 changes: 9 additions & 0 deletions lib/amplitude.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,13 @@ class Amplitude extends _Amplitude {

return await _channel.invokeMethod('setServerZone', jsonEncode(properties));
}

/// Sets offline. If offline is true, then the SDK will not upload events to Amplitude servers;
/// however, it will still log events.
Future<void> setOffline(bool enabled) async {
Map<String, dynamic> properties = _baseProperties();
properties['offline'] = enabled;

return await _channel.invokeMethod('setOffline', jsonEncode(properties));
}
}
7 changes: 6 additions & 1 deletion lib/amplitude_web.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'dart:async';
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:js/js_util.dart' as js;

import 'web/amplitude_js.dart';
import 'dart:async';

class AmplitudeFlutterPlugin {
static void registerWith(Registrar registrar) {
Expand Down Expand Up @@ -177,6 +178,10 @@ class AmplitudeFlutterPlugin {
bool updateServerUrl = args['updateServerUrl'];
return amplitude.setServerZone(serverZone, updateServerUrl);
}
case "setOffline":
{
return false;
}
default:
throw PlatformException(
code: 'Unimplemented',
Expand Down
1 change: 1 addition & 0 deletions lib/web/amplitude_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Amplitude {
Function? opt_callback,
Function? opt_error_callback,
bool? outOfSession);
external bool setOffline(bool enabled);
external Options options;
}

Expand Down

0 comments on commit 01c99e7

Please sign in to comment.