flutter_d_sdk 0.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 44

flutter_d_sdk #

接入方(APP)向授权方(APP)发起操作请求,如 游戏应用A 向 钱包应用B 发起登录、支付、获取个人信息请求等。

flow

Android接入配置(必要): #

  • AndroidManifest添加以下配置,并修改Scheme
   <activity
       android:name="org.dplatform.DSdkRouteActivity"
       android:configChanges="keyboardHidden|orientation|screenSize"
       android:exported="true"
       android:theme="@android:style/Theme.Translucent.NoTitleBar" >
       <intent-filter>
           <action android:name="android.intent.action.VIEW"/>
           <category android:name="android.intent.category.DEFAULT"/>
           <category android:name="android.intent.category.BROWSABLE"/>
           <data
              android:scheme="你的scheme"
              android:host="你的host"
               android:path="你的path"/>
           <data/>
       </intent-filter>
   </activity>

iOS接入配置(必要): #

  • Info.plist配置你的Scheme
<key>CFBundleURLTypes</key>
<array>
    <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLSchemes</key>
        <array>
            <string>你的scheme</string>
        </array>
    </dict>
</array>
  • Info.plist配置QueriesSchemes
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>授权方scheme</string>
</array>
  • AppDelegate.swift配置SDK回调
添加如下代码:
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if let controller = window.rootViewController as? FlutterViewController {
        FlutterMethodChannel(
            name: "flutter_d_sdk",
            binaryMessenger: controller.binaryMessenger
        ).invokeMethod(
            "resp",
            arguments: url.absoluteString.removingPercentEncoding
        )
    }
    return true
}

接入方发起授权请求: #

1, 创建SDK并指定当前操作类型

var dSdk = FlutterDSdk(action: "aciton-name");

注:
aciton-name 事件名称,由接入方和授权方协定。

2, 发起授权请求并获取返回值

var result = await dSdk.call(
    uriString: "scheme://a-platform/", 
    params: {
      'param1': 'value1',
      'param2': 'value2',
    },
);

注:
uriString[必填]:[授权方scheme]://平台标识,有授权方定义;
params[必填]:键值对参数,由双方协定;
downloadUrl[可选]:授权方下载页面,当授权方APP未安装时,跳转至此链接页面;
appKey[可选]:加密密钥(传null即可);
result:授权方返回信息,其类型由授权方决定。

0.0.1 #

  • TODO: Describe initial release.

0.0.2 #

  • Android和iOS统一通过scheme判断目标app是否安装

0.0.3 #

  • 功能完善

0.0.4 #


example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_d_sdk/flutter_d_sdk.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var token = 'Unknown';
  var pay = "Unknown";

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          children: <Widget>[
            Text('response: $token'),
            RaisedButton(
              child: Text('去登陆 Login'),
              onPressed: () {
                //
                FlutterDSdk(action: "login").call(
                  uriString: "dplatform://dplatform.org",
                  params: {
                    'channelID': '10000144',
                    'scheme': 'xyttylusdt',
                    'appName': 'Testapp',
                  },
                ).then((val) {
                  setState(() {
                    token = val;
                  });
                });
                //
              },
            ),
            Text('response: $pay'),
            RaisedButton(
              child: Text('去充值 Pay'),
              onPressed: () {
                //
                FlutterDSdk(action: "pay")
                    .call(uriString: "up://uptest/do")
                    .then((val) {
                  setState(() {
                    pay = val;
                  });
                });
                //
              },
            ),
          ],
        )),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_d_sdk: ^0.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_d_sdk/flutter_d_sdk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Health suggestions

Format lib/flutter_d_sdk.dart.

Run flutter format to format lib/flutter_d_sdk.dart.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
url_launcher ^5.2.7 5.4.10
Transitive dependencies
collection 1.14.12
flutter_web_plugins 0.0.0
meta 1.1.8
platform_detect 1.4.0
plugin_platform_interface 1.0.2
pub_semver 1.4.4
sky_engine 0.0.99
typed_data 1.1.6
url_launcher_macos 0.0.1+7
url_launcher_platform_interface 1.0.7
url_launcher_web 0.1.1+6
vector_math 2.0.8
Dev dependencies
flutter_test