搜索插件、代码仓与 APP 分类

插件详情v4.0.0

flutter_login_vk

通过 VK.com 登录。轻松在您的应用程序中添加 VK 登录功能。包含用户个人资料信息。

AndroidiOS
近 30 天下载
181
喜欢数
54
Pub 分数
150

安装插件

flutter pub add flutter_login_vk

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可为移动应用程序实现无缝的 VK.com 登录集成。它通过处理 VK 的 OAuth 流程,简化了身份验证过程,使用户能够使用其 VK 账户登录。该包可获取用户的基本资料信息,如姓名、电子邮件和头像,便于个性化用户体验。专为 Android 和 iOS 设计,可轻松集成到现有的 Flutter 项目中,设置简单。适用于希望借助社交登录提升用户注册体验的应用。

适合场景

  • 社交登录集成
  • VK 用户入门
  • 个人资料数据检索
  • 移动应用身份验证
  • 简化登录流程
  • 跨平台社交登录

主要特点

  • VK OAuth2 集成
  • 用户个人资料数据访问
  • Android 和 iOS 支持
  • 轻松设置,使用 pub add
  • 最小化样板代码
  • 安全的令牌处理

适合对象

  • 需要 VK 登录的应用
  • 使用社交认证的项目
  • 面向俄语受众的开发者
  • 带有用户资料的移动应用
  • 希望快速实现认证的初创企业
  • Flutter 应用需要跨平台登录

使用建议

  • 需要 VK 应用注册
  • 需要正确配置重定向 URI
  • 依赖互联网连接
  • 可能需要额外权限
  • 仅限VK账户持有者
  • 遵守VK的服务条款

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_login_vk

pub package Analyze & Test innim lint

Flutter Plugin to login via VK.com.

Easily add VK login feature in your application. User profile information included.

SDK version

VK SDK version, used in plugin:

Minimum requirements

  • Flutter 3.38.0 and higher.
  • iOS 13.0 and higher.
  • Android 5.0 and newer (SDK 21). Minimum compileSdkVersion 31.

⚠️ If your project was create with Flutter pre 1.12 you should upgrade it to the Android embedding v2. See https://flutter.dev/go/android-project-migration

Getting Started

To use this plugin:

  1. add flutter_login_vk as a dependency in your pubspec.yaml file;
  2. create an app on VK.com
  3. setup android;
  4. setup ios;
  5. additional VK.com app setup;
  6. use plugin in application.

See documentation on VK.com for full information:

And here is instructions in Russian if it's your native language (русская версия).

App on VK.com

Create an app on VK.com https://vk.com/editapp?act=create

  1. Enter "Title".
  2. Select Standalone app as "Platform".
  3. Click "Connect app".

An application will be created. Now select tab "Settings" and copy "App ID" (referenced as [APP_ID] in this readme).

App settings for Android
  1. Set Package name for Android - your package name for Android application (attribute package in AndroidManifest.xml).

  2. Set Main activity for Android - your main activity class (with package). By default it would be com.yourcompany.yourapp.MainActivity.

  3. To fill up Signing certificate fingerprint for Android you should create SHA1 fingerprint as described in the documentation (without SHA1: prefix). Pay attention: you should remove all colons from the fingerprint string. Add fingerprints for debug and release certificates. Note: if your application uses Google Play App Signing than you should get certificate SHA-1 fingerprint from Google Play Console.

    ⚠️ Important! You should add fingerprints for every build variants. E.g. if you have CI/CD which build APK for testing with it's own certificate (it may be auto generated debug certificate or some another) than you should add it's fingerprint too.

  4. Click "Save".

App settings for iOS
  1. Add your Bundle Identifier - set App Bundle ID for iOS (you can find it in Xcode: Runner - Target Runner - General, section Identity, field Bundle Identifier).
  2. Also set App ID for iOS, it's you SKU (you can find it in App Store Connect: My Apps - {Your application} - App Store - App Information, section "General Information"). Mostly often is't the same as bundle ID.
  3. Click "Save".
Android

Edit AndroidManifest.xml (android/app/src/main/AndroidManifest.xml):

  1. Add the INTERNET permission in the root of <manifest>, if you haven't (probably you have):
<uses-permission android:name="android.permission.INTERNET" />
  1. Add an activity to the section application:
<activity android:name="com.vk.sdk.VKServiceActivity"
    android:label="ServiceActivity"
    android:theme="@style/VK.Transparent" />
  1. Add your VK application identifier to the resource file (e.g. strings.xml), replacing [APP_ID] with your application id:
<resources>
    <integer name="com_vk_sdk_AppId">[APP_ID]</integer>
</resources>
  1. Add rules -keep class com.vk.** { *; } in you proguard file (android/app/proguard-rules.pro).

See full AndroidManifest.xml in example.

iOS

Configure Info.plist (ios/Runner/Info.plist). You can edit it as a text file from your IDE, or you can open project (ios/Runner.xcworkspace) in Xcode.

  1. In Xcode right-click on Info.plist, and choose Open As Source Code.
  2. Copy and paste the following XML snippet into the body of your file (<dict>...</dict>), replacing [APP_ID] with your application id:
<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>vk[APP_ID]</string>
  </array>
  </dict>
</array>
  1. Also add to Info.plist body (<dict>...</dict>):
<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>vk</string> 
    <string>vk-share</string> 
    <string>vkauthorize</string> 
</array>
  1. Enter your VK application identifier.
<key>VKAppId</key>
<string>[APP_ID]</string>

See full Info.plist in example.

⚠️ NOTE. Check if you already have CFBundleURLTypes or LSApplicationQueriesSchemes keys in your Info.plist. If you have, you should merge their values, instead of adding a duplicate key.

If you want to use scope=nohttps, which we strongly do not recommend, you should also add NSAppTransportSecurity, see the documentation.

Additional VK.com app setup

Go to My Apps and click "Manage" on your app.

On tab "Information" you should:

  1. Enter "Description".
  2. Select a suitable "Category".
  3. Upload small icon "32x32 icon".
  4. Click "Save".
  5. Upload "Square banner" and "A square banner for catalog" - user can see it.

Setup other settings if you need it.

Than go to "Setting" tab and turn on application: change "App status" from Application off to Application on and visible to all.

Click "Save".

Usage in application

First, you should create an instance of VKLogin. Than, before any method call or checking accessToken you should initialize VK SDK:

final vk = VKLogin();
await vk.initSdk();

Now you can use the plugin.

Features:

  • log in via VK.com;
  • get access token;
  • get user profile;
  • get user email;
  • check if logged in;
  • log out.

Sample code:

import 'package:flutter_login_vk/flutter_login_vk.dart';

// Create an instance of VKLogin
final vk = VKLogin();

// Initialize
await vk.initSdk();

// Log in
final res = await vk.logIn(scope: [
  VKScope.email,
  VKScope.friends,
]);

// Check result
if (res.isValue) {
  // There is no error, but we don't know yet
  // if user logged in or not.
  // You should check isCanceled
  final VKLoginResult result = res.asValue!.value;

  if (result.isCanceled) {
    // User cancel log in
  } else {
    // Logged in

    // Send access token to server for validation and auth
    final VKAccessToken? accessToken = result.accessToken;
    if (accessToken != null) {
      print('Access token: ${accessToken.token}');

      // Get profile data
      final profileRes = await vk.getUserProfile();
      final profile = profileRes.asValue?.value;
      if (profile != null) {
        print('Hello, ${profile.firstName}! You ID: ${profile.userId}');
      }

      // Get email (since we request email permissions)
      final email = await vk.getUserEmail();
      print('And your email is $email');
    } else {
      print('Something goes wrong');
    }
  }
} else {
  // Log in failed
  final errorRes = res.asError!;
  print('Error while log in: ${errorRes.error}');
}
Initialization notes

When you call initSdk(), plugin try to restore previous session. If token has been expired - it will be refreshed.

Also, during restoring, log in screen may be shown to user (only if user was logged in).

In additional, you can pass to initSdk() required scope, and if current user session doesn't provide it - user will be logged out.

Also you can specify API version to use, but you shouldn't.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。