HiveFlutterKit
📣 For comprehensive documentation, please visit our new documentation site: https://sag333ar.github.io/HiveFlutterKit/
Aioha
All-In-One Hive Authentication
Introduction
- Aioha (All-In-One Hive Authentication) - Now HiveFlutterKit is an API that provides a common interface for working with different Hive login providers.
- This allows easier integration of Hive login and transacting on the network with fewer code.
- For Javascript package usage, https://aioha.dev/docs
HiveFlutterKit
- HiveFlutterKit is a Flutter package that provides a common interface for working with different Hive login providers. It also provides dhive package usage.
- This allows easier integration of Hive login and transacting on the network with fewer code.
- For Flutter package usage, https://pub.dev/packages/aioha
- For more information about the HiveFlutterKit API, please visit the HiveFlutterKit API documentation.
- For more information about the HiveFlutterKit, please visit the HiveFlutterKit documentation.
Setup for Android, iOS, and Web
flutter pub add provider
Update main function as follows:
import 'package:HiveFlutterKit/aioha_core.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(
MultiProvider(
providers: [
Provider<HiveFlutterKitPlatform>.value(
value: HiveFlutterKitPlatform.instance,
),
],
child: const MyApp(),
),
);
}
Extra Setup for Using HiveFlutterKit in web-app
Open web/index.html and add the following script tag to the body section:
<body>
<script src="flutter_bootstrap.js" async></script>
<script src="packages/HiveFlutterKit/web/hiveflutterkit.js" type="application/javascript" defer></script>
</body>
Usage Guide
import 'package:hive_flutter_kit/hive_flutter_kit_platform_interface.dart';
import 'package:provider/provider.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late HiveFlutterKitPlatform hfKit;
@override
void didChangeDependencies() {
super.didChangeDependencies();
hfKit = Provider.of<HiveFlutterKitPlatform>(context, listen: false);
}
void _loginWithHiveKeychain() async {
try {
// following line uses hfKit
final result = await hfKit.plugin.loginWithKeychain(
_usernameController.text,
'some-text-to-be-signed', // if we send empty string, it will be auto-generated
);
} catch (e) {
}
}
}
API Reference
This section provides documentation for the public methods available in the HiveFlutterKitPlatform
class.
loginWithKeychain(String username, String proof)
- Description: Initiates a login process using Hive Keychain.
- Parameters:
username
(String): The Hive username.proof
(String): A string to be signed by the Keychain to prove identity. If an empty string is provided, it might be auto-generated by the underlying implementation.
- Returns:
Future<LoginModel>
: A future that resolves to aLoginModel
object containing login status and data.
loginWithHiveAuth(String username, String proof)
- Description: Initiates a login process using HiveAuth.
- Parameters:
username
(String): The Hive username.proof
(String): A string to be signed by HiveAuth.
- Returns:
Future<LoginModel>
: A future that resolves to aLoginModel
object.
loginWithPlaintextKey(String username, String postingKey, String proof)
- Description: Initiates a login process using a plaintext posting key. Note: This method should be used with extreme caution due to the security risks of handling plaintext private keys.
- Parameters:
username
(String): The Hive username.postingKey
(String): The plaintext posting key.proof
(String): A string for the proof of transaction.
- Returns:
Future<LoginModel>
: A future that resolves to aLoginModel
object.
getCurrentUser()
- Description: Retrieves the username of the currently logged-in user.
- Parameters: None.
- Returns:
Future<String>
: A future that resolves to the username of the current user.
getQrString()
- Description: Generates a QR code string, typically used for HiveAuth login flows.
- Parameters: None.
- Returns:
Future<String>
: A future that resolves to the QR code string.
logout()
- Description: Logs out the current user.
- Parameters: None.
- Returns:
Future<String>
: A future that resolves to a status message indicating the outcome of the logout process.
singleVote(String author, String permlink, int weight)
- Description: Casts a vote on a Hive post or comment.
- Parameters:
author
(String): The author of the post/comment.permlink
(String): The permlink of the post/comment.weight
(int): The voting weight (e.g., 10000 for 100% vote, -10000 for 100% downvote).
- Returns:
Future<String>
: A future that resolves to a confirmation or error message.
comment(String parentAuthor, String parentPermlink, String permlink, String title, String body, Map<String, dynamic> jsonMetadata)
- Description: Publishes a comment or post on the Hive blockchain.
- Parameters:
parentAuthor
(String): The author of the parent post (empty for a new post).parentPermlink
(String): The permlink of the parent post (empty for a new post).permlink
(String): The unique permlink for this new comment/post.title
(String): The title of the comment/post.body
(String): The main content of the comment/post.jsonMetadata
(Map<String, dynamic>): A map containing metadata (tags, app info, etc.).
- Returns:
Future<String>
: A future that resolves to a confirmation or error message.
commentWithOptions(String parentAuthor, String parentPermlink, String permlink, String title, String body, String jsonMetadata, String options)
- Description: Publishes a comment or post with additional options (e.g., beneficiaries, burn_account).
- Parameters:
parentAuthor
(String): The author of the parent post.parentPermlink
(String): The permlink of the parent post.permlink
(String): The unique permlink for this comment/post.title
(String): The title of the comment/post.body
(String): The main content of the comment/post.jsonMetadata
(String): A JSON string containing metadata.options
(String): A JSON string containing comment options.
- Returns:
Future<String>
: A future that resolves to a confirmation or error message.
deleteComment(String permlink)
- Description: Deletes a previously published comment or post.
- Parameters:
permlink
(String): The permlink of the comment/post to be deleted.
- Returns:
Future<String>
: A future that resolves to a confirmation or error message.
reblog(String author, String permlink, bool reblogFlag)
- Description: Reblogs or un-reblogs a post.
- Parameters:
author
(String): The author of the post to reblog.permlink
(String): The permlink of the post to reblog.reblogFlag
(bool):true
to reblog,false
to un-reblog (if previously reblogged).
- Returns:
Future<String>
: A future that resolves to a confirmation or error message.
follow(String author, bool followFlag)
- Description: Follows or unfollows a Hive user.
- Parameters:
author
(String): The username of the user to follow/unfollow.followFlag
(bool):true
to follow,false
to unfollow.
- Returns:
Future<String>
: A future that resolves to a confirmation or error message.
claimRewards()
- Description: Claims pending rewards for the logged-in user.
- Parameters: None.
- Returns:
Future<String>
: A future that resolves to a confirmation or error message, possibly including details of claimed rewards.
signMessage(String message, String keyType)
- Description: Signs an arbitrary message with the user's specified key type.
- Parameters:
message
(String): The message to be signed.keyType
(String): The type of key to use for signing (e.g., "posting", "active").
- Returns:
Future<String>
: A future that resolves to the signed message or an error.
switchUser(String userId)
- Description: Switches the active user if multiple accounts are managed by AIOHA.
- Parameters:
userId
(String): The username of the account to switch to.
- Returns:
Future<bool>
: A future that resolves totrue
if the switch was successful,false
otherwise.
getOtherLogins()
- Description: Retrieves a list of other usernames for accounts that have been previously logged into and are managed by AIOHA.
- Parameters: None.
- Returns:
Future<List<String>>
: A future that resolves to a list of usernames.
removeOtherLogin(String userId)
- Description: Removes a previously logged-in user from the list of managed accounts.
- Parameters:
userId
(String): The username to remove.
- Returns:
Future<String>
: A future that resolves to a status message.
addAccountAuthority(String account, String keyType, int weight)
- Description: Grants authority to another account for a specific key type (e.g., posting authority).
- Parameters:
account
(String): The account to grant authority to.keyType
(String): The type of key authority to grant (e.g., "posting").weight
(int): The weight of the authority.
- Returns:
Future<String>
: A future that resolves to a confirmation or error message.
removeAccountAuthority(String account, String keyType)
- Description: Revokes authority previously granted to another account for a specific key type.
- Parameters:
account
(String): The account from which to revoke authority.keyType
(String): The type of key authority to revoke.
- Returns:
Future<String>
: A future that resolves to a confirmation or error message.
getPlatformVersion()
- Description: Retrieves the platform version on which the Flutter app is running. This is typically for debugging or platform-specific logic.
- Parameters: None.
- Returns:
Future<String?>
: A future that resolves to a string representing the platform version, ornull
if it cannot be determined.
getChainProperties()
- Description: Fetches dynamic global properties of the Hive blockchain.
- Parameters: None.
- Returns:
Future<ChainProperties>
: A future that resolves to aChainProperties
object containing various blockchain parameters.
getDiscussions(String by, {required int limit, String tag = '', String? startAuthor, String? startPermlink, String? observer})
- Description: Fetches a list of discussions (posts/comments) based on various criteria (e.g., trending, hot, new).
- Parameters:
by
(String): The sorting method (e.g., "trending", "hot", "created", "feed").limit
(required int): The maximum number of discussions to fetch.tag
(String, optional): Filter discussions by this tag. Defaults to empty.startAuthor
(String?, optional): For pagination, the author of the last post from the previous fetch.startPermlink
(String?, optional): For pagination, the permlink of the last post from the previous fetch.observer
(String?, optional): The username of the observer, to personalize results (e.g., for muted content).
- Returns:
Future<List<Discussion>>
: A future that resolves to a list ofDiscussion
objects.
getAccounts(List<String> usernames)
- Description: Retrieves detailed information for a list of Hive accounts.
- Parameters:
usernames
(List
- Returns:
Future<List<Account>>
: A future that resolves to a list ofAccount
objects.
getVotingPower(String username)
- Description: Fetches the current voting power for a specified user.
- Parameters:
username
(String): The Hive username.
- Returns:
Future<VotingPower>
: A future that resolves to aVotingPower
object.
getResourceCredits(String username)
- Description: Fetches the current resource credits (RC) for a specified user.
- Parameters:
username
(String): The Hive username.
- Returns:
Future<ResourceCredits>
: A future that resolves to aResourceCredits
object.
getAccountPosts(String username, String by, {required int limit, String? startAuthor, String? startPermlink, String? observer})
- Description: Fetches a list of posts made by a specific account, sorted by a chosen method.
- Parameters:
username
(String): The username whose posts are to be fetched.by
(String): The sorting criteria (e.g., "blog", "feed", "posts").limit
(required int): The maximum number of posts to fetch.startAuthor
(String?, optional): For pagination, the author of the last post from the previous fetch (should be the same asusername
).startPermlink
(String?, optional): For pagination, the permlink of the last post from the previous fetch.observer
(String?, optional): The username of the observer.
- Returns:
Future<List<Discussion>>
: A future that resolves to a list ofDiscussion
objects representing the account's posts.
hasThreespeakInAccountAuths(String username)
- Description: Checks if the 'threespeak' account has been granted posting authority by the specified user. This is relevant for integrations with the 3Speak video platform.
- Parameters:
username
(String): The Hive username to check.
- Returns:
Future<bool>
: A future that resolves totrue
if 'threespeak' has posting authority,false
otherwise.
getListOfCommunities(String? query, {int limit = 20, String? last, String? observer})
- Description: Fetches a list of Hive communities. Can be used to search for communities or list them.
- Parameters:
query
(String?): A search query to filter communities by name or title.null
or empty to list communities without a specific query.limit
(int, optional): The maximum number of communities to fetch. Defaults to 20.last
(String?, optional): For pagination, the name of the last community from the previous fetch.observer
(String?, optional): The username of the observer.
- Returns:
Future<List<CommunityItem>>
: A future that resolves to a list ofCommunityItem
objects.
getCommentsList(String author, String permlink)
- Description: Fetches the list of comments for a specific post.
- Parameters:
author
(String): The author of the parent post.permlink
(String): The permlink of the parent post.
- Returns:
Future<List<Discussion>>
: A future that resolves to a list ofDiscussion
objects representing the comments.
uploadImage({required Uint8List imageBytes, required String fileName, required String token, required String uploadUrlSever})
- Description: Uploads an image to a specified server.
- Parameters:
imageBytes
(required Uint8List): The byte data of the image.fileName
(required String): The name of the file (e.g., "image.jpg").token
(required String): An authentication token or signed message required by the upload server.uploadUrlSever
(required String): The base URL of the image upload server.
- Returns:
Future<String>
: A future that resolves to the URL of the uploaded image. - Throws:
Exception
if the upload fails or the server returns an error.
pickImageWithMaxSize(int maxDimension, String uploadUrlSever)
- Description: Allows the user to pick an image from the gallery, checks its dimensions, signs a message (presumably for authentication with the upload server), and then uploads it using
uploadImage
. - Parameters:
maxDimension
(int): The maximum allowed width or height for the image.uploadUrlSever
(String): The base URL of the image upload server.
- Returns:
Future<String>
: A future that resolves to the URL of the uploaded image. - Throws:
Exception
if no image is selected, if image decoding fails, if the image is too large, or if signing/uploading fails.
signAndBroadcastTx(dynamic operationRequest, String keyType)
- Description: Signs and broadcasts a generic Hive transaction. This is a flexible method for operations not explicitly covered by other methods.
- Parameters:
operationRequest
(dynamic): The operation or list of operations to be signed and broadcasted. The structure depends on the specific Hive operation.keyType
(String): The type of key to use for signing (e.g., "posting", "active").
- Returns:
Future<dynamic>
: A future that resolves to the result of the broadcast, which could be a transaction ID or an error object.