vkdart 2.3.1 copy "vkdart: ^2.3.1" to clipboard
vkdart: ^2.3.1 copied to clipboard

Package helps simplify working with the VK API. Completely wraps VK methods, has event support and much more.

VkDart #

Pub Version Pub Popularity Pub Points

The package helps to simplify the work with VK API.

A chat room to discuss how the package works - https://t.me/vk_dart

Features #

  1. Reliability. Package functionality is wrapped in unit tests.
  2. Supports events. Supports Callback API, Longpoll API
  3. Development. Functionality is becoming more and more every day!
  4. Easy to use. Very easy to use!
  5. Model support. There is a description of event, attachment and object models.

Usage #

Initialization:

import 'package:vkdart/vkdart.dart';

void main() async {
  final TOKEN = '';
  final GROUP_ID = 1;

  final myFetcher = Longpoll(GROUP_ID); // or Webhook (CallbackAPI).
  final vkdart = VkDart(TOKEN, fetcher: myFetcher);

  vkdart.start();
}
copied to clipboard

Using API:

await vkdart.request('groups.getById', {'group_id': 1}); // List<Map<String, dynamic>>
copied to clipboard

Events #

VkDart base class contains functions for processing VK API events. Some events are combined into a single handler, consider this example:

/// message_new, message_reply, message_reply.
vkdart.onMessage().listen((event) { ... });
copied to clipboard

In this case the events message_new, message_reply, message_edit will be processed in this listen. In order to filter the necessary events, you can modify Stream:

vkdart
        .onMessage()
        .where((event) => event.isNew && event.isChat)
        .listen((event) { ... });
copied to clipboard

Due to the fact that VK API is also updated, new events are added, there is a handler onUnsupportedEvent. If you have caught such an event, please report it to our chat.

vkdart.onUnsupportedEvent().listen((event) {
    print(
      'An unsupported event has arrived!\n'
      'It is necessary to inform the chat https://t.me/vk_dart\n\n'
      'Type of event ${event.eventType}\n'
      'Event Object: ${event.object}',
    );
});
copied to clipboard

Each event handler, has its own functions, fields and other useful features. All update models can be found on this page.

All event handlers can be found on this page.

Keyboard #

The package includes a keyboard builder:

import 'package:vkdart/util.dart' show VkDartKeyboard, VkDartKeyboardColor;

final keyboard = VkDartKeyboard(
    oneTime: true, // default value
    inline: false // default value
);
copied to clipboard

Warning! The keyboard grid has limitations:

  • For conventional keyboard size: 5 × 10, maximum number of keys: 40
  • For inline keyboard size: 5 × 6, maximum number of keys: 10

Text button:

keyboard.addButtonText('Hello world!', color: VkDartKeyboardColor.primary, payload: {'button': 'text'});
copied to clipboard

The payload will be available in message_new event, in the messagePayload property.

URL button:

keyboard.addButtonLink('mysite.com', 'My Site');
copied to clipboard

Location button:

keyboard.addButtonLocation(payload: {'button': 'location'});
copied to clipboard

The payload will be available in message_new event, in the messagePayload property.

Vk Pay button:

keyboard.addButtonVkPay("action=transfer-to-group&group_id=1&aid=10");
copied to clipboard

Open APP button:

keyboard.addButtonApp(6232540, -157525928, hash: "123", appName: 'LiveWidget');
copied to clipboard

Callback button:

keyboard.addButtonCallback(
    'Hello world!', 
    color: VkDartKeyboard.secondary, // default value
    payload: {'button': 'callback'}
);
copied to clipboard

The payload will be available in the message_event event, in the eventPayload property.

Move on to the next row:

keyboard
  ..addButtonText('1 row: Hello world!')
  ..nextRow()
  ..addButtonText('2 row: Hello world!');
copied to clipboard

Usage in the messages.send method:

vkdart.messages.send({
    'peer_id': PEER_ID,
    'message': 'Hello world!',
    'random_id': RANDOM_ID,
    'keyboard': keyboard.toJson()
});
copied to clipboard

Button Colors:

Field Description Color
VkDartKeyboardColor.primary Main Action Blue
VkDartKeyboardColor.secondary It's just a button White
VkDartKeyboardColor.negative Dangerous Action or Failure Red
VkDartKeyboardColor.positive "Agree," "Confirm." Green

Attachments #

There are two types of class:

final customAttachment = CustomAttachmentModel({
    'owner_id': 1,
    'id': 2,
    // 'access_key': 'ACCESS_KEY'
}, attachType: 'photo'); 
copied to clipboard

In VK there is a format of attachments, let's say to send it in private messages, for convenience the CustomAttachmentModel class has an overridden function toString(), which will return this format.

customAttachment.toString(); // photo1_2 and photo1_2_ACCESS_KEY (if access != null)
[customAttachment, customAttachment].join(',') // photo1_2,photo1_2
copied to clipboard

Suppose we have an attachment object in Map format, in order to convert it into the necessary model, we will use the fromSpecificModel constructor:

AttachmentModel.fromSpecificModel({
    'owner_id': 1,
    'id': 2
}, attachType: 'photo'); // PhotoAttachmentModel
copied to clipboard

Convert the attachment string to a model:

CustomAttachment.fromString('photo1_2'); // PhotoAttachmentModel
copied to clipboard

Future plans #

  • Release models of VK API objects. ✔
  • Release a class that makes keyboarding easier. ✔
  • Release features, for chatbot commands.

Bugs and feature requests #

Please send a bug report to issue tracker

6
likes
160
points
77
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.25 - 2025.04.09

Package helps simplify working with the VK API. Completely wraps VK methods, has event support and much more.

Repository (GitHub)
View/report issues

Topics

#vkontakte #vk #api #vk-api #http

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

http

More

Packages that depend on vkdart