linkhive_flutter 1.0.0
linkhive_flutter: ^1.0.0 copied to clipboard
A Flutter plugin to connect with LinkHive SaaS for dynamic links.
LinkHive Flutter Plugin #
The linkhive_flutter
plugin enables Flutter applications to interact with LinkHive, a platform for managing and using dynamic links. With this plugin, you can create, update, retrieve, and delete dynamic links as well as handle deferred links. To get started, you will need to create an account on LinkHive Console and obtain your API credentials (Base URL, Project ID, Client ID).
To use this plugin, follow the steps below:
- Create an account: Go to LinkHive Console and sign up for an account.
- Create a new project: Once logged in, create a new project in the LinkHive Console.
- Obtain credentials: After creating your project, you will receive:
Base URL
for API endpointProject ID
(Unique identifier for your project)Client ID
(Unique identifier for your client)
To use this plugin, add linkhive_flutter
as a dependency in your pubspec.yaml
file:
dependencies:
linkhive_flutter: ^1.0.0
Example Usage #
Once you've set up the plugin and installed the dependencies, you can begin using the link_hive_flutter
package to interact with LinkHive's dynamic link API.
Connect to the LinkHive API #
Before you can interact with the API, you need to connect by providing your Base URL, Project ID, and Client ID (which can be obtained from the LinkHive Console).
import 'package:link_hive_flutter/link_hive_flutter.dart';
await LinkHiveClient.instance.connect(
baseUrl: 'YOUR_BASE_URL_HERE', // Replace with your LinkHive API base URL
projectId: 'YOUR_PROJECT_ID_HERE', // Replace with your project ID
clientId: 'YOUR_CLIENT_ID_HERE', // Replace with your client ID
);
Create a Dynamic Link #
Now, to create a dynamic link using the LinkHiveClient:
import 'package:link_hive_flutter/link_hive_flutter.dart';
final request = DynamicLinkRequest(
platformIds: {
'123e4567-e89b-12d3-a456-426614174000', // UUIDs as Set
'987e4567-e89b-12d3-a456-426614174001'
},
utm_medium: 'twitter',
);
// Create a new dynamic link via LinkHiveClient
final dynamicLink = await LinkHiveClient.instance.dynamicLinks.create(request);
print('Created dynamic link: ${dynamicLink.link}'
);
Update a Dynamic Link #
final updatedLink = await LinkHiveClient.instance.dynamicLinks.update(
'linkId', // Replace with actual link ID
request,
);
print('Updated dynamic link: ${updatedLink.link}');
Get a Dynamic Link by ID #
final dynamicLinkById = await LinkHiveClient.instance.dynamicLinks.getById('linkId');
print('Fetched dynamic link by ID: ${dynamicLinkById.link}');
Get a Dynamic Link by Short Code #
final dynamicLinkByShortCode = await LinkHiveClient.instance.dynamicLinks.getByShortCode('shortCode');
print('Fetched dynamic link by short code: ${dynamicLinkByShortCode.link}');
Delete a Dynamic Link #
await LinkHiveClient.instance.dynamicLinks.delete('linkId');
print('Dynamic link deleted.');
Get Deferred Link (After App Install) #
final deferredLink = await LinkHiveClient.instance.dynamicLinks.getDeferredLink();
if (deferredLink != null) {
print('Deferred link: ${deferredLink.link}');
} else {
print('No deferred link found');
}
Error Handling #
The LinkHiveClient.instance.dynamicLinks
methods throw exceptions on errors:
- NotFoundException: Thrown when a resource is not found (404).
- ApiException: Thrown for API-related errors with status codes other than 404.
- NetworkException: Thrown for general network-related errors.
Notes #
-
LinkHive Account: You must create an account at LinkHive Console to obtain your
baseUrl
,projectId
, andclientId
. -
Dio Setup:
Dio
is a powerful HTTP client used to make requests to the LinkHive server. Ensure that you have the necessary permissions for network requests on both Android and iOS. -
Platform-Specific Setup: Make sure to configure your Android and iOS projects for universal links according to the following guides:
-
iOS Universal Links: Follow the official Apple documentation to configure universal links for iOS.
-
Android App Links: Follow the official Android documentation to configure App Links for Android.
Also, ensure that your Flutter project has the required permissions and settings for deep linking, as outlined in the Flutter Plugin Documentation.
-
-
LinkHive Documentation: For detailed information about LinkHive, check the LinkHive Docs.