Skip to content

Commit

Permalink
Add Flutter Shared Instance Documentation
Browse files Browse the repository at this point in the history
This documents the new create and get instance methods.
  • Loading branch information
anthonycastelli committed Jun 3, 2024
1 parent 4727230 commit ead94be
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/flutter/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit ead94be

Please sign in to comment.