From ead94bea046d605dca677309d8762dc3f343ea9f Mon Sep 17 00:00:00 2001 From: Anthony Castelli Date: Mon, 3 Jun 2024 10:42:21 -0400 Subject: [PATCH] Add Flutter Shared Instance Documentation This documents the new create and get instance methods. --- docs/flutter/usage.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/flutter/usage.md b/docs/flutter/usage.md index 14a95df..d887892 100644 --- a/docs/flutter/usage.md +++ b/docs/flutter/usage.md @@ -46,3 +46,38 @@ appfit.identifyUser(null); # Cached Events We cache all event locally in the SDK, allowing us to retry failed events. If a device is experiencing network issues, we will retry events once the device is back online to help avoid event data loss. + +# Shared Instances + +Alternativly, we support using shared instances. This can be achieved by calling two methods. + +`createInstance` and `getInstance` + +## Creating a Shared Instance + +To create a shared instance that can be shared is as simple as using the static method on the `AppFit` class. + +```dart +// Create the configuration +final configuration = AppFitConfiguration(apiKey: 'API_KEY'); + +// Create the shared instance +AppFit.createInstance(configuration) +``` + +This will create an instance called `default`. Alternativly you can pass in a parameter `instanceName` if you are running multiple instances. + +Note: The `createInstance` will return the newly created instance if you need access to it right away for tracking purposes. + +### Access a Shared Instance + +When you need to access the shared instance to perform a tracking event, you can call the `getInstance` method. + +```dart +// Return an instance +AppFit.getInstance() +``` + +This will return an instance called `default`. Alternativly you can pass in a parameter `instanceName` if you are running multiple instances. + +Note: If you call this method before creating an instance, an exception will be thrown.