栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Flutter 将友盟最新的null safe的SDK转为非null safe

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flutter 将友盟最新的null safe的SDK转为非null safe

 按友盟的要求,为了合规检查必须将SDK必须升到最新版。但是友盟的最新SDK是null safe的,

但公司的项目还是非null safe的。为了接入最新的友盟的SDK,就把友盟的SDK改成非null safe的了。

友盟SDK的dart代码很少,两分钟就能改完。

1、把pubspec.yaml中的sdk的版本改到2.7.0,如下:

environment:

sdk: '>=2.7.0 <3.0.0'

flutter: ">=1.10.0"

2、把所有错误中的"?"和"!"去掉,没有错误就可以了。

改后的代码如下:

import 'dart:async';

import 'package:flutter/services.dart';

class UmengCommonSdk {
  static const MethodChannel _channel =
      const MethodChannel('umeng_common_sdk');

  static Future get platformVersion async {
    final String version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  static Future initCommon(String androidAppkey, String iosAppkey, String channel) async {
    List params = [androidAppkey, iosAppkey ,channel];
    final dynamic result =  await _channel.invokeMethod('initCommon', params);
    return result;
  }

  static void onEvent(String event, Map properties) {
    List args = [event,properties];
    _channel.invokeMethod('onEvent', args);
  }

  static void onProfileSignIn (String userID) {
    List args = [userID];
    _channel.invokeMethod('onProfileSignIn', args);
  }

  static void onProfileSignOff () {
    _channel.invokeMethod('onProfileSignOff');
  }

  static void setPageCollectionModeManual() {
    _channel.invokeMethod('setPageCollectionModeManual');
  }

  static void onPageStart(String viewName) {
    List args = [viewName];
    _channel.invokeMethod('onPageStart', args);
  }

  static void onPageEnd(String viewName) {
    List args = [viewName];
    _channel.invokeMethod('onPageEnd', args);
  }

  static void setPageCollectionModeAuto() {
    _channel.invokeMethod('setPageCollectionModeAuto');
  }

  static void reportError(String error) {
    List args = [error];
    _channel.invokeMethod('reportError', args);
  }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/681570.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号