Wipter SDK for Flutter
The Wipter SDK Flutter Plugin provides a wrapper for the Wipter SDK Android library, enabling Flutter apps to utilize the WipterSDK’s features, including managing OAuth authentication, state changes, and starting/stopping SDK functionality.
Installation
- Add the following to your pubspec.yaml file:
dependencies:
wipter_sdk: ^<latest version>
- Then run
flutter pub get
Android
Ensure your project is using Maven Central ad Jitpack.io are part of your dependencies' repositories. For example, with:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url = uri("https://jitpack.io")
}
}
}
Usage
- Import the library
import 'package:wipter_sdk/wipter_sdk.dart';
Initialization
To use the SDK, you must first call the setup method with the required parameters:
- clientId: Your OAuth client ID.
- clientSecret: Your OAuth client secret.
- autoStart (optional): If true, the SDK starts immediately after setup with default parameters (default is false).
Example:
await WipterSDK.setup(
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
autoStart: true,
);
Starting the SDK
The start method initializes the SDK and establishes the necessary WebSocket connections.
Parameters:
-
mode: Determines how the SDK operates:
- 'FOREGROUND_ONLY' (default): Connection is established only when the app is in the foreground.
- 'ALWAYS': Connection is maintained while the app is alive (foreground or background).
-
networks: Specifies the network type for connection:
- 'ONLY_UNMETERED_NETWORKS' (default): Uses Wi-Fi or unmetered connections only.
- 'ALL_NETWORKS': Allows metered connections like cellular networks.
Example:
await WipterSDK.start(
mode: 'ALWAYS',
networks: 'ALL_NETWORKS',
);
Stopping the SDK
The stop method stops the SDK and disconnects the WebSocket. Once stopped, the SDK cannot resume automatically.
await WipterSDK.stop();
Retrieving Device and Session IDs
The getDeviceId and getSessionId methods provide unique identifiers associated with the device and the current session, respectively.
String? deviceId = await WipterSDK.getDeviceId();
String? sessionId = await WipterSDK.getSessionId();
Listening to SDK State Changes
The SDK emits state changes through a stream. Use the stateStream getter to listen to these changes.
Possible states:
- Uninitialized: SDK is not yet initialized.
- Initializing: SDK is initializing.
- Initialized: SDK is initialized but not yet connected.
- Authenticating: SDK is authenticating.
- Authenticated: SDK has a valid session.
- Connecting: SDK is establishing a WebSocket connection.
- Running: SDK is fully connected and operational.
- Error: An error occurred in the SDK.
- Stopped: SDK is stopped or the connection is disconnected.
- Paused: SDK is paused due to unmet conditions (e.g., network availability).
WipterSDK.stateStream.listen(
(state) {
print('SDK State Changed: $state');
},
onError: (error) {
print('Error: $error');
},
);
Requirements
Android
- Minimum API Level: 24 (Android 7.0)
- Java Version: 17 or newer
Flutter
- Flutter SDK: 3.10 or newer