xinhuamm_xycloud 1.1.4
xinhuamm_xycloud: ^1.1.4 copied to clipboard
新移云SDK插件
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:xinhuamm_xycloud/xinhuamm_xycloud.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _xinhuammXycloudPlugin = XinhuammXycloud();
@override
void initState() {
super.initState();
setCloudGlobalConfig();
setCloudMethodCallHandler();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('新移云SDK Flutter原生插件'),
actions: [
IconButton(
icon: const Icon(Icons.qr_code_scanner), // 图片按钮的图标
onPressed: () {
openScanPage();
},
),
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.all(6.0),
child: ElevatedButton(
onPressed: () {
// 按钮被点击时的操作
openCloudPage();
},
style: ElevatedButton.styleFrom(
primary: Colors.blue, // 按钮的背景颜色
onPrimary: Colors.white, // 文本颜色
padding: EdgeInsets.fromLTRB(16.0, 10, 16, 10), // 内边距
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0), // 圆角
),
),
child: Text(
'打开新移云页面', // 按钮文本
style: TextStyle(
fontSize: 18.0, // 字体大小
),
),
),
),
const Text('内嵌新移云页面'),
Expanded(
child: Container(
color: Colors.blue,
// 设置背景色
// child: getXYCloudFlutterWebView()
),
),
],
),
),
),
);
}
Widget getXYCloudFlutterWebView() {
const String viewType = 'XYCloudFlutterWebView';
const String url =
'https://xuancheng.market.xinhuamm.net/statics/cloud-application-o2o-user-h5/?isSpecialMall=1&hideTopView=1&nory=1';
// 'https://yc.market.xinhuamm.net/statics/cloud-application-o2o-user-h5?nory=1&service_flag=o2o_half_screen';
const Map<String, dynamic> creationParam = {'url': url};
const MessageCodec creationParamsCodec = StandardMessageCodec();
if (defaultTargetPlatform == TargetPlatform.android) {
return const AndroidView(
viewType: viewType,
creationParams: creationParam,
creationParamsCodec: creationParamsCodec,
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
return const UiKitView(
viewType: viewType,
creationParams: creationParam,
creationParamsCodec: creationParamsCodec,
);
}
return Container();
}
void handleScanResult(String scanResult) async {
bool handled = await _xinhuammXycloudPlugin.handleScanResult(scanResult);
if (handled) {
print("sdk内部已处理,外部无需处理");
} else {
print("sdk内部未处理,外部需处理");
}
}
void openScanPage() async {
String scanResult = await _xinhuammXycloudPlugin.openScanPage();
print("扫码结果:$scanResult");
}
void openCloudPage() {
_xinhuammXycloudPlugin.openCloudPage(
"https://xuancheng.market.xinhuamm.net/statics/cloud-application-o2o-user-h5/?isSpecialMall=1&hideTopView=1&nory=1"
// "https://yc.market.xinhuamm.net/statics/cloud-application-o2o-user-h5?nory=1"
);
}
void setCloudGlobalConfig() {
_xinhuammXycloudPlugin.setCloudGlobalConfig({
"weixinSchemeUrl": "微信支付协议",
"appUrlScheme": "支付宝支付协议",
"userAgent": "xinhuamm",
"themeColor": "#f38242",
"showNavigationBar": false,
"isDebug": true
});
}
void setCloudMethodCallHandler() {
_xinhuammXycloudPlugin.setCloudMethodCallHandler((call) {
if ("login" == call.method) {
print("打开登录页");
Completer<dynamic> completer = Completer<dynamic>();
// 打开登录页面,注释代码也请仔细查看
// openLoginPage((String userId) {
// // 回调函数,处理登录成功后的逻辑
// print("用户登录成功,userId: $userId");
// completer.complete({
// "userId": userId,
// });
// // 登录取消或登录失败后的逻辑也请回调执行completer,传空即可
// });
// 等待Completer完成,将其Future返回
return completer.future;
} else if ("getUserInfo" == call.method) {
// 获取用户标识,判断用户是否登录或切换用户
/* {
"userId":"用户标识",
} */
print("获取用户标识");
return Future.value({
"userId": "用户标识",
});
} else if ("getToken" == call.method) {
// 获取免登接口请求参数。返回:json字符串
/* {
"token":"用户token",
} */
print("获取免登信息");
return Future.value({
"token": "用户token",
});
} else if ("share" == call.method) {
// 调用分享功能,call中带有分享参数:
/* {
"title":"分享标题",
"description":"分享摘要",
"imageUrl":"分享图片",
"url":"分享链接",
} */
String title = call.arguments['title'];
String description = call.arguments['description'];
String imageUrl = call.arguments['imageUrl'];
String url = call.arguments['url'];
print("分享");
} else if ("openMini" == call.method) {
// 打开微信小程序,call中带有小程序信息:code&path
String code = call.arguments['code'];
String path = call.arguments['path'];
print("打开小程序");
}
return Future.value(null);
});
}
}