Skip to content

Flutter API

1. Initialize applet

Before you can use the api provided by sdk, you must initialize sdk, the interface to initialize sdk is

dart
  ///
  ///
  /// initialize mop miniprogram engine.
  /// Initialize applet
  /// [sdkkey] is required. it can be getted from api.PhizClip.com
  /// [secret] is required. it can be getted from api.PhizClip.com
  /// [apiServer] is optional. the mop server address. default is https://mp.finogeek.com
  /// [apiPrefix] is optional. the mop server prefix. default is /api/v1/mop
  /// [cryptType] is optional. cryptType, should be MD5/SM
  /// [disablePermission] is optional.
  /// [encryptServerData] Whether to encrypt the server data, need server support
  /// [userId] user id
  /// [finStoreConfigs] Multiservice configuration
  /// [uiConfig] UI configuration
  /// [debug] Set debug mode to affect debugging and logging
  /// [customWebViewUserAgent] Set custom webview ua
  /// [appletIntervalUpdateLimit] Set applet batch update period
  /// [maxRunningApplet] Set the maximum number of running applets at the same time
  ///
  Future<Map> initialize(
    String sdkkey,
    String secret, {
    String? apiServer,
    String? apiPrefix,
    String? cryptType,
    bool encryptServerData = false,
    bool disablePermission = false,
    String? userId,
    bool debug = false,
    bool bindAppletWithMainProcess = false,
    List<FinStoreConfig>? finStoreConfigs,
    UIConfig? uiConfig,
    String? customWebViewUserAgent,
    int? appletIntervalUpdateLimit,
    int? maxRunningApplet,
  })

Usage examples:

dart
final res = await Mop.instance.initialize(
          '22LyZEib0gLTQdU3MUauARlLry7JL/2fRpscC9kpGZQA', '1c11d7252c53e0b6',
          apiServer: 'https://api.PhizClip.com', apiPrefix: '/api/v1/mop');

2. Open the applet

dart
  /// open the miniprogram [appId] from the  mop server.
  /// Open phizclip
  /// [appId] is required.
  /// [path] is miniprogram open path. example /pages/index/index
  /// [query] is miniprogram query parameters. example key1=value1&key2=value2
  /// [sequence] is miniprogram sequence. example 0,1.2.3,4,5...
  /// [apiServer] is optional. the mop server address. default is https://mp.finogeek.com
  /// [apiPrefix] is optional. the mop server prefix. default is /api/v1/mop
  /// [fingerprint] is optional. the mop sdk fingerprint. is nullable
  /// [cryptType] is optional. cryptType, should be MD5/SM
  Future<Map> openApplet(
    final String appId, {
    final String? path,
    final String? query,
    final int? sequence,
    final String? apiServer,
    final String? scene,
  })

3. Get information about the applet currently in use

The current applet information includes the fields appId,name,icon,description,version,thumbnail

dart
  ///
  ///  get current using applet
  ///  Get information about the applet currently in use
  ///  {appId,name,icon,description,version,thumbnail}
  ///
  ///
  Future<Map<String, dynamic>> currentApplet()

4.Close all currently open applets

dart
  ///
  /// close all running applets
  /// Close all currently open applets
  ///
  Future closeAllApplets()

5. Clear cache applet

Clear the cache of the applet, when opened again, it will download the applet again

dart
  ///
  /// clear applets cache
  /// Clear cache applet
  ///
  Future clearApplets()

6. Register applet event handling

When a specified event is triggered within the applet, the user will be notified, for example, if the applet is forwarded, the applet needs to get the user information and register the processor to make the corresponding response

dart
 ///
  /// register handler to provide custom info or behaviour
  /// Register applet event handling
  ///
  void registerAppletHandler(AppletHandler handler)

Structure of the processor

dart
abstract class AppletHandler {
  ///
  /// Forwarding applet
  ///
  ///
  ///
  void forwardApplet(Map<String, dynamic> appletInfo);

  ///
  ///Obtain user information
  ///  "userId"
  ///  "nickName"
  ///  "avatarUrl"
  ///  "jwt"
  ///  "accessToken"
  ///
  Future<Map<String, dynamic>> getUserInfo();

  /// Get custom menu
  Future<List<CustomMenu>> getCustomMenus(String appId);

  ///Customized menu click handling
  Future onCustomMenuClick(String appId, int menuId);
}

7. Register extension api

If our applet SDK API doesn't meet your needs, you can register a custom applet API and then call your own defined API from within the applet.

dart
///
/// register extension api
/// Register extension api
///
void registerExtensionApi(String name, ExtensionApiHandler handler) ···

ios needs to create the PhizClipConf.js file in the root of the applet, with the following configuration example

bash
module.exports = {
  extApi:[
    { //General Interaction API
      name: 'onCustomEvent', //Extended api name The api must be implemented on the Native side
      params: { //Extended api parameter format, required field
        url: ''
      }
    }
  ]
}

For more customized API configuration information, please refer to pz.loadExtApi

8. Register webview extension api

The custom api can also be used in the webview within the applet, simply by using the

dart
  ///
  /// register webview extension api
  /// Register webview extension api
  ///
  void addWebExtentionApi(String name, ExtensionApiHandler handler)

9. Native calls to js methods in webview

dart
  ///
  /// Native calls to js methods in webview
  /// [appId] Applet id
  /// [eventName] Method name
  /// [nativeViewId] webviewId
  /// [eventData] Parameters
  ///
  Future<void> callJS(String appId, String eventName, String nativeViewId,
      Map<String, dynamic> eventData)

10. Send events to applets natively

dart
  ///
  /// Native send event to applet
  /// [appId] applet id
  /// [eventData] event object
  Future<void> sendCustomEvent(
      String appId, Map<String, dynamic> eventData)

11. Close the applet

dart
  ///
  /// Close the applet The applet will exist in the memory
  ///
  Future<void> closeApplet(String appletId, bool animated)

12. End the applet

dart
  ///
  /// Ending the applet The applet will be cleared from memory
  ///
  Future<void> finishRunningApplet(String appletId, bool animated)

13. Set applet switching animation

dart
  ///
  /// Set the phizclip to switch animation Android
  ///
  Future setActivityTransitionAnim(Anim anim)

14. QR code to open the small program

dart
  ///
  /// Open the applet via QR code
  /// [qrcode] QR code content
  ///
  Future qrcodeOpenApplet(String qrcode)