xinhuamm_xycloud 0.0.1
xinhuamm_xycloud: ^0.0.1 copied to clipboard
新移云SDK插件
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
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('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('新移云SDK Flutter原生插件'),
Container(
margin: 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, // 字体大小
),
),
),
),
],
),
),
),
);
}
void openCloudPage() {
_xinhuammXycloudPlugin.openCloudPage(
"https://xyqm.market.platform.xinhuaapp.com/statics/cloud-application-o2o-user-h5");
}
void setCloudGlobalConfig() {
_xinhuammXycloudPlugin.setCloudGlobalConfig({
"weixinSchemeUrl": "微信支付协议",
"appUrlScheme": "支付宝支付协议",
"userAgent": "xinhuamm",
"themeColor": "#f38242",
"showNavigationBar": false,
"isDebug": true
});
}
void setCloudMethodCallHandler() {
_xinhuammXycloudPlugin.setCloudMethodCallHandler((call) {
if ("login" == call.method) {
// 打开登录页面
print("打开登录页");
} else if ("getLoginParam" == call.method) {
// 获取免登接口请求参数。返回:json字符串
/* {
"userId":"用户标识",
"userPhone":"用户手机号",
"otherKey":"value",
} */
print("获取免登信息");
// return Future.value({
// "userId": "用户标识",
// "userPhone": "用户手机号",
// "otherKey": "value",
// });
} 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);
});
}
}