registerUtilChannelMethods function

void registerUtilChannelMethods()

注册工具 channel 方法

Implementation

void registerUtilChannelMethods () {
  DynamicChannel.register({
    'setTimeout': (params) {
      String timerId = Util.getString(params['timerId']);
      int duration = Util.getInt(params['duration']);
      if (timerId == null || duration == null) return;
      TimerForJs.register(timerId, duration, TimerType.timeout);
    },
    'setInterval': (params) {
      String timerId = Util.getString(params['timerId']);
      int duration = Util.getInt(params['duration']);
      if (timerId == null || duration == null) return;
      TimerForJs.register(timerId, duration, TimerType.interval);
    },
    'clearTimer': (params) {
      String timerId = Util.getString(params['timerId']);
      TimerForJs.remove(timerId);
    },
    'setBundleDir': (params) {
      String dir = Util.getString(params['bundleDir']);
      if (dir != null) Util.bundleDirectory = dir;
      else Util.onError(DynamicFlutterError('bundle dir is null'));
    },
    'setAppBarHeight': (params) {
      double appBarHeight = Util.getDouble(params['appBarHeight']) ?? kToolbarHeight;
      dynamicApp?.appBarHeight = appBarHeight;
    },
    'copy': (params) {
      Util.copyData(
        Util.getString(params['data']),
        Util.getBoolean(params['showSuccess'])
      );
    },
    'onError': (params) {
      String message = Util.getString(params['message']);
      String stack = Util.getString(params['stack']);
      String pageName = Util.getString(params['pageName']);
      String referPageName = Util.getString(params['referPageName']);
      Util.onError(DynamicFlutterError(
        message,
        trace: stack,
        type: DynamicFlutterErrorType.JS,
        pageName: pageName,
        referPageName: referPageName
      ));
    }
  });
}