Unverified 提交 71564dad authored 作者: Alex Li's avatar Alex Li

🎨 Clean dart code formats

上级 07e02e08
......@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Copyright [2020] [OpenFlutter]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......
......@@ -3,24 +3,26 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
import 'auth_by_qr_code_page.dart';
import 'launch_mini_program_page.dart';
import 'pay_page.dart';
import 'send_auth.dart';
import 'share_image_page.dart';
import 'share_mini_program.dart';
import 'share_music.dart';
import 'share_text.dart';
import 'share_video_page.dart';
import 'share_web_page.dart';
import 'sign_auto_deduct_page.dart';
import 'subscribe_message_page.dart';
import 'pages/auth_by_qr_code_page.dart';
import 'pages/launch_mini_program_page.dart';
import 'pages/pay_page.dart';
import 'pages/send_auth_page.dart';
import 'pages/share_image_page.dart';
import 'pages/share_mini_program_page.dart';
import 'pages/share_music_page.dart';
import 'pages/share_text_page.dart';
import 'pages/share_video_page.dart';
import 'pages/share_web_page.dart';
import 'pages/sign_auto_deduct_page.dart';
import 'pages/subscribe_message_page.dart';
void main() => runApp(new MyApp());
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => new _MyAppState();
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
......@@ -32,12 +34,13 @@ class _MyAppState extends State<MyApp> {
_initFluwx() async {
await registerWxApi(
appId: "wxd930ea5d5a258f4f",
doOnAndroid: true,
doOnIOS: true,
universalLink: "https://your.univerallink.com/link/");
appId: 'wxd930ea5d5a258f4f',
doOnAndroid: true,
doOnIOS: true,
universalLink: 'https://your.univerallink.com/link/',
);
var result = await isWeChatInstalled;
print("is installed $result");
print('is installed $result');
}
// Platform messages are asynchronous, so we initialize in an async method.
......@@ -45,26 +48,25 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
routes: <String, WidgetBuilder>{
"shareText": (context) => ShareTextPage(),
"shareImage": (context) => ShareImagePage(),
"shareWebPage": (context) => ShareWebPagePage(),
"shareMusic": (context) => ShareMusicPage(),
"shareVideo": (context) => ShareVideoPage(),
"sendAuth": (context) => SendAuthPage(),
"shareMiniProgram": (context) => ShareMiniProgramPage(),
"pay": (context) => PayPage(),
"launchMiniProgram": (context) => LaunchMiniProgramPage(),
"subscribeMessage": (ctx) => SubscribeMessagePage(),
"AuthByQRCode": (ctx) => AuthByQRCodePage(),
'shareText': (context) => ShareTextPage(),
'shareImage': (context) => ShareImagePage(),
'shareWebPage': (context) => ShareWebPagePage(),
'shareMusic': (context) => ShareMusicPage(),
'shareVideo': (context) => ShareVideoPage(),
'sendAuth': (context) => SendAuthPage(),
'shareMiniProgram': (context) => ShareMiniProgramPage(),
'pay': (context) => PayPage(),
'launchMiniProgram': (context) => LaunchMiniProgramPage(),
'subscribeMessage': (ctx) => SubscribeMessagePage(),
'AuthByQRCode': (ctx) => AuthByQRCodePage(),
'AutoDeduct': (ctx) => SignAutoDeductPage(),
},
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: ShareSelectorPage()),
home: Scaffold(
appBar: AppBar(title: const Text('Plugin example app')),
body: ShareSelectorPage(),
),
);
}
}
......@@ -73,120 +75,134 @@ class ShareSelectorPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: new ListView(
child: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () async {
String? extMsg = await getExtMsg();
print("extMsg:$extMsg\n");
},
child: const Text("Get ExtMessage")),
child: OutlinedButton(
onPressed: () async {
String? extMsg = await getExtMsg();
print('extMsg:$extMsg\n');
},
child: const Text('Get ExtMessage'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("shareText");
},
child: const Text("share text")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('shareText');
},
child: const Text('share text'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("shareImage");
},
child: const Text("share image")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('shareImage');
},
child: const Text('share image'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("shareWebPage");
},
child: const Text("share webpage")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('shareWebPage');
},
child: const Text('share webpage'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("shareMusic");
},
child: const Text("share music")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('shareMusic');
},
child: const Text('share music'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("shareVideo");
},
child: const Text("share video")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('shareVideo');
},
child: const Text('share video'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("shareMiniProgram");
},
child: const Text("share mini program")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('shareMiniProgram');
},
child: const Text('share mini program'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("sendAuth");
},
child: const Text("send auth")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('sendAuth');
},
child: const Text('send auth'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("pay");
},
child: const Text("pay")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('pay');
},
child: const Text('pay'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("launchMiniProgram");
},
child: const Text("Launch MiniProgram")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('launchMiniProgram');
},
child: const Text('Launch MiniProgram'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("subscribeMessage");
},
child: const Text("SubscribeMessage")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('subscribeMessage');
},
child: const Text('SubscribeMessage'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("AuthByQRCode");
},
child: const Text("AuthByQRCode")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('AuthByQRCode');
},
child: const Text('AuthByQRCode'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed("AutoDeduct");
},
child: const Text("SignAuto-deduct")),
child: OutlinedButton(
onPressed: () {
Navigator.of(context).pushNamed('AutoDeduct');
},
child: const Text('SignAuto-deduct'),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new OutlinedButton(
onPressed: () {
openWeChatApp();
},
child: const Text("Open WeChat App")),
child: OutlinedButton(
onPressed: () {
openWeChatApp();
},
child: const Text('Open WeChat App'),
),
),
],
),
......
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
class AuthByQRCodePage extends StatefulWidget {
const AuthByQRCodePage({Key? key}) : super(key: key);
@override
_AuthByQRCodePageState createState() => _AuthByQRCodePageState();
}
class _AuthByQRCodePageState extends State<AuthByQRCodePage> {
String _status = "status";
String _status = 'status';
Uint8List? _image;
@override
......@@ -18,7 +19,7 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> {
// fluwx.onAuthByQRCodeFinished.listen((data) {
// setState(() {
// _status = "errorCode=>${data.errorCode}\nauthCode=>${data.authCode}";
// _status = 'errorCode=>${data.errorCode}\nauthCode=>${data.authCode}';
// });
// });
// fluwx.onAuthGotQRCode.listen((image) {
......@@ -29,7 +30,7 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> {
//
// fluwx.onQRCodeScanned.listen((scanned) {
// setState(() {
// _status = "scanned";
// _status = 'scanned';
// });
// });
}
......@@ -38,20 +39,20 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("AuthByQRCode"),
title: Text('AuthByQRCode'),
),
body: Column(
children: <Widget>[
RaisedButton(
ElevatedButton(
onPressed: () {
// fluwx.authByQRCode(
// appId: "wxd930ea5d5a258f4f",
// scope: "noncestr",
// nonceStr: "nonceStr",
// timeStamp: "1417508194",
// signature: "429eaaa13fd71efbc3fd344d0a9a9126835e7303");
// appId: 'wxd930ea5d5a258f4f',
// scope: 'noncestr',
// nonceStr: 'nonceStr',
// timeStamp: '1417508194',
// signature: '429eaaa13fd71efbc3fd344d0a9a9126835e7303');
},
child: Text("AUTH NOW"),
child: Text('AUTH NOW'),
),
Text(_status),
_qrCode()
......
......@@ -2,12 +2,14 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
class LaunchMiniProgramPage extends StatefulWidget {
const LaunchMiniProgramPage({Key? key}) : super(key: key);
@override
_LaunchMiniProgramPageState createState() => _LaunchMiniProgramPageState();
}
class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> {
String? _result = "无";
String? _result = '无';
@override
void initState() {
......@@ -16,7 +18,7 @@ class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> {
if (res is WeChatLaunchMiniProgramResponse) {
if (mounted) {
setState(() {
_result = "isSuccessful:${res.isSuccessful}";
_result = 'isSuccessful:${res.isSuccessful}';
});
}
}
......@@ -33,18 +35,18 @@ class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Launch MiniProgrom"),
title: const Text('Launch MiniProgrom'),
),
body: Column(
children: <Widget>[
OutlineButton(
OutlinedButton(
onPressed: () {
launchWeChatMiniProgram(username: "gh_d43f693ca31f");
launchWeChatMiniProgram(username: 'gh_d43f693ca31f');
},
child: const Text("Launch MiniProgrom"),
child: const Text('Launch MiniProgrom'),
),
const Text("响应结果;"),
Text("$_result")
const Text('响应结果;'),
Text('$_result')
],
),
);
......
......@@ -5,14 +5,15 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
class PayPage extends StatefulWidget {
const PayPage({Key? key}) : super(key: key);
@override
_PayPageState createState() => _PayPageState();
}
class _PayPageState extends State<PayPage> {
String _url = "https://wxpay.wxutil.com/pub_v2/app/app_pay.php";
String _result = "无";
String _url = 'https://wxpay.wxutil.com/pub_v2/app/app_pay.php';
String _result = '无';
@override
void initState() {
......@@ -20,13 +21,13 @@ class _PayPageState extends State<PayPage> {
fluwx.weChatResponseEventHandler.listen((res) {
if (res is fluwx.WeChatPaymentResponse) {
setState(() {
_result = "pay :${res.isSuccessful}";
_result = 'pay :${res.isSuccessful}';
});
}
});
// fluwx.responseFromPayment.listen((data) {
// setState(() {
// _result = "${data.errCode}";
// _result = '${data.errCode}';
// });
// });
}
......@@ -34,12 +35,10 @@ class _PayPageState extends State<PayPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("pay"),
),
appBar: AppBar(title: const Text('pay')),
body: Column(
children: <Widget>[
OutlineButton(
OutlinedButton(
onPressed: () async {
var h = H.HttpClient();
h.badCertificateCallback = (cert, String host, int port) {
......@@ -50,7 +49,7 @@ class _PayPageState extends State<PayPage> {
var data = await Utf8Decoder().bind(response).join();
Map<String, dynamic> result = json.decode(data);
print(result['appid']);
print(result["timestamp"]);
print(result['timestamp']);
fluwx
.payWithWeChat(
appId: result['appid'].toString(),
......@@ -62,12 +61,12 @@ class _PayPageState extends State<PayPage> {
sign: result['sign'].toString(),
)
.then((data) {
print("---》$data");
print('---》$data');
});
},
child: const Text("pay"),
child: const Text('pay'),
),
const Text("响应结果;"),
const Text('响应结果;'),
Text(_result)
],
),
......
......@@ -2,12 +2,14 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
class SendAuthPage extends StatefulWidget {
const SendAuthPage({Key? key}) : super(key: key);
@override
_SendAuthPageState createState() => _SendAuthPageState();
}
class _SendAuthPageState extends State<SendAuthPage> {
String? _result = "无";
String? _result = '无';
@override
void initState() {
......@@ -15,7 +17,7 @@ class _SendAuthPageState extends State<SendAuthPage> {
fluwx.weChatResponseEventHandler.distinct((a, b) => a == b).listen((res) {
if (res is fluwx.WeChatAuthResponse) {
setState(() {
_result = "state :${res.state} \n code:${res.code}";
_result = 'state :${res.state} \n code:${res.code}';
});
}
});
......@@ -30,22 +32,22 @@ class _SendAuthPageState extends State<SendAuthPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Send Auth"),
),
appBar: AppBar(title: const Text('Send Auth')),
body: Column(
children: <Widget>[
OutlineButton(
OutlinedButton(
onPressed: () {
fluwx
.sendWeChatAuth(
scope: "snsapi_userinfo", state: "wechat_sdk_demo_test")
scope: 'snsapi_userinfo',
state: 'wechat_sdk_demo_test',
)
.then((data) {});
},
child: const Text("send auth"),
child: const Text('send auth'),
),
const Text("响应结果;"),
Text("$_result")
const Text('响应结果;'),
Text('$_result')
],
),
);
......
......@@ -2,17 +2,15 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
class ShareImagePage extends StatefulWidget {
const ShareImagePage({Key? key}) : super(key: key);
@override
_ShareImagePageState createState() => _ShareImagePageState();
}
class _ShareImagePageState extends State<ShareImagePage> {
WeChatScene scene = WeChatScene.SESSION;
String _imagePath =
// "http://img-download.pchome.net/download/1k1/3a/3e/ofskcd-s1a.jpg"
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534614311230&di=b17a892b366b5d002f52abcce7c4eea0&imgtype=0&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png";
String _response = "";
String _response = '';
WeChatImage? source;
WeChatImage? thumbnail;
......@@ -23,7 +21,7 @@ class _ShareImagePageState extends State<ShareImagePage> {
weChatResponseEventHandler.listen((res) {
if (res is WeChatShareResponse) {
setState(() {
_response = "state :${res.isSuccessful}";
_response = 'state :${res.isSuccessful}';
});
}
});
......@@ -31,16 +29,14 @@ class _ShareImagePageState extends State<ShareImagePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
appBar: AppBar(
title: const Text("shareImage"),
title: const Text('shareImage'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.share,
color: Colors.white,
),
onPressed: _shareImage)
icon: Icon(Icons.share, color: Colors.white),
onPressed: _shareImage,
),
],
),
body: Padding(
......@@ -48,56 +44,66 @@ class _ShareImagePageState extends State<ShareImagePage> {
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(labelText: "图片地址(仅限网络)"),
decoration: InputDecoration(labelText: '图片地址(仅限网络)'),
controller: TextEditingController(
text:
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534614311230&di=b17a892b366b5d002f52abcce7c4eea0&imgtype=0&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png"),
text: 'https://timgsa.baidu.com/timg'
'?image'
'&quality=80'
'&size=b9999_10000'
'&sec=1534614311230'
'&di=b17a892b366b5d002f52abcce7c4eea0'
'&imgtype=0'
'&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png',
),
onChanged: (value) {
source = WeChatImage.network(value);
},
keyboardType: TextInputType.multiline,
),
TextField(
decoration: InputDecoration(labelText: "缩略地址"),
controller: TextEditingController(text: "//images/logo.png"),
decoration: InputDecoration(labelText: '缩略地址'),
controller: TextEditingController(text: '//images/logo.png'),
onChanged: (value) {
thumbnail = WeChatImage.asset(value);
},
),
new Row(
Row(
children: <Widget>[
const Text("分享至"),
const Text('分享至'),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("会话")
Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('会话')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("朋友圈")
Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('朋友圈')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("收藏")
Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('收藏')
],
)
],
......
......@@ -8,78 +8,77 @@ class ShareMiniProgramPage extends StatefulWidget {
class _ShareMiniProgramPageState extends State<ShareMiniProgramPage> {
WeChatScene scene = WeChatScene.SESSION;
String _webPageUrl = "http://www.qq.com";
String _thumbnail =
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534614311230&di=b17a892b366b5d002f52abcce7c4eea0&imgtype=0&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png";
String _title = "Fluwx";
String _userName = "gh_d43f693ca31f";
String _path = "/pages/media";
String _description = "Fluwx";
@override
void initState() {
super.initState();
}
String _webPageUrl = 'http://www.qq.com';
String _thumbnail = 'https://timgsa.baidu.com/timg'
'?image'
'&quality=80'
'&size=b9999_10000'
'&sec=1534614311230'
'&di=b17a892b366b5d002f52abcce7c4eea0'
'&imgtype=0'
'&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png';
String _title = 'Fluwx';
String _userName = 'gh_d43f693ca31f';
String _path = '/pages/media';
String _description = 'Fluwx';
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
appBar: AppBar(
title: const Text("ShareMiniProgram"),
title: const Text('ShareMiniProgram'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.share,
color: Colors.white,
),
onPressed: _share)
icon: Icon(Icons.share, color: Colors.white),
onPressed: _share,
),
],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: new ListView(
child: ListView(
children: <Widget>[
new TextField(
controller: TextEditingController(text: "http://www.qq.com"),
TextField(
controller: TextEditingController(text: 'http://www.qq.com'),
onChanged: (str) {
_webPageUrl = str;
},
decoration: InputDecoration(labelText: "web page url"),
decoration: InputDecoration(labelText: 'web page url'),
),
new TextField(
controller: TextEditingController(text: "gh_d43f693ca31f"),
TextField(
controller: TextEditingController(text: 'gh_d43f693ca31f'),
onChanged: (str) {
_userName = str;
},
decoration: InputDecoration(labelText: "user name"),
decoration: InputDecoration(labelText: 'user name'),
),
new TextField(
controller: TextEditingController(text: "/pages/media"),
TextField(
controller: TextEditingController(text: '/pages/media'),
onChanged: (str) {
_path = str;
},
decoration: InputDecoration(labelText: "user name"),
decoration: InputDecoration(labelText: 'user name'),
),
new TextField(
controller: TextEditingController(text: "Fluwx"),
TextField(
controller: TextEditingController(text: 'Fluwx'),
onChanged: (str) {
_title = str;
},
decoration: InputDecoration(labelText: "title"),
decoration: InputDecoration(labelText: 'title'),
),
new TextField(
controller: TextEditingController(text: "Fluwx"),
TextField(
controller: TextEditingController(text: 'Fluwx'),
onChanged: (str) {
_description = str;
},
decoration: InputDecoration(labelText: "description"),
decoration: InputDecoration(labelText: 'description'),
),
new TextField(
controller: TextEditingController(text: "images/logo.png"),
TextField(
controller: TextEditingController(text: 'images/logo.png'),
onChanged: (str) {
_thumbnail = str;
},
decoration: InputDecoration(labelText: "thumbnail"),
decoration: InputDecoration(labelText: 'thumbnail'),
),
],
),
......@@ -88,13 +87,14 @@ class _ShareMiniProgramPageState extends State<ShareMiniProgramPage> {
}
void _share() {
var model = new WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
userName: _userName,
title: _title,
path: _path,
description: _description,
thumbnail: WeChatImage.network(_thumbnail));
var model = WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
userName: _userName,
title: _title,
path: _path,
description: _description,
thumbnail: WeChatImage.network(_thumbnail),
);
shareToWeChat(model);
}
}
......@@ -2,118 +2,118 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
class ShareMusicPage extends StatefulWidget {
const ShareMusicPage({Key? key}) : super(key: key);
@override
_ShareMusicPageState createState() => _ShareMusicPageState();
}
class _ShareMusicPageState extends State<ShareMusicPage> {
String _musicUrl =
"http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3";
String _musicLowBandUrl = "http://www.qq.com";
String _title = "Beyond";
String _description = "A Popular Rock Band From China";
String _thumnail = "images/logo.png";
'http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3';
String _musicLowBandUrl = 'http://www.qq.com';
String _title = 'Beyond';
String _description = 'A Popular Rock Band From China';
String _thumnail = 'images/logo.png';
WeChatScene scene = WeChatScene.SESSION;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
appBar: AppBar(
title: const Text("ShareMusicPage"),
title: const Text('ShareMusicPage'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.share,
color: Colors.white,
),
onPressed: _share)
icon: Icon(Icons.share, color: Colors.white),
onPressed: _share,
),
],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: new Column(
child: Column(
children: <Widget>[
new TextField(
TextField(
controller: TextEditingController(
text:
"http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3"),
text: 'http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/'
'0042515_05.ANDY.mp3',
),
onChanged: (str) {
_musicUrl = str;
},
decoration: InputDecoration(labelText: "music url"),
decoration: InputDecoration(labelText: 'music url'),
),
new TextField(
controller: TextEditingController(text: "http://www.qq.com"),
TextField(
controller: TextEditingController(text: 'http://www.qq.com'),
onChanged: (str) {
_musicLowBandUrl = str;
},
decoration: InputDecoration(labelText: "music low band url"),
decoration: InputDecoration(labelText: 'music low band url'),
),
new TextField(
controller: TextEditingController(text: "Beyond"),
TextField(
controller: TextEditingController(text: 'Beyond'),
onChanged: (str) {
_title = str;
},
decoration: InputDecoration(labelText: "title"),
decoration: InputDecoration(labelText: 'title'),
),
new TextField(
controller:
TextEditingController(text: "A Popular Rock Band From China"),
TextField(
controller: TextEditingController(
text: 'A Popular Rock Band From China',
),
onChanged: (str) {
_description = str;
},
decoration: InputDecoration(labelText: "description"),
decoration: InputDecoration(labelText: 'description'),
),
new TextField(
controller: TextEditingController(text: "images/logo.png"),
TextField(
controller: TextEditingController(text: 'images/logo.png'),
onChanged: (str) {
_thumnail = str;
},
decoration: InputDecoration(labelText: "thumbnail"),
decoration: InputDecoration(labelText: 'thumbnail'),
),
new Row(
Row(
children: <Widget>[
const Text("分享至"),
const Text('分享至'),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("会话")
Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('会话')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("朋友圈")
Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('朋友圈')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("收藏")
Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('收藏')
],
)
),
],
)
),
],
),
),
......@@ -122,12 +122,13 @@ class _ShareMusicPageState extends State<ShareMusicPage> {
void _share() {
var model = WeChatShareMusicModel(
title: _title,
description: _description,
musicUrl: _musicUrl,
scene: scene,
musicLowBandUrl: _musicLowBandUrl,
thumbnail: WeChatImage.network(_thumnail));
title: _title,
description: _description,
musicUrl: _musicUrl,
scene: scene,
musicLowBandUrl: _musicLowBandUrl,
thumbnail: WeChatImage.network(_thumnail),
);
shareToWeChat(model);
}
......
......@@ -7,77 +7,73 @@ class ShareTextPage extends StatefulWidget {
}
class _ShareTextPageState extends State<ShareTextPage> {
String _text = "share text from fluwx";
String _text = 'share text from fluwx';
WeChatScene scene = WeChatScene.SESSION;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
appBar: AppBar(
title: const Text("ShareText"),
title: const Text('ShareText'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.share,
color: Colors.white,
),
onPressed: _shareText)
icon: Icon(Icons.share, color: Colors.white),
onPressed: _shareText,
),
],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: new Column(
child: Column(
children: <Widget>[
new TextField(
controller: TextEditingController(text: "share text from fluwx"),
TextField(
controller: TextEditingController(text: 'share text from fluwx'),
onChanged: (str) {
_text = str;
},
decoration: InputDecoration(labelText: "TextToShare"),
decoration: InputDecoration(labelText: 'TextToShare'),
),
new Row(
Row(
children: <Widget>[
const Text("分享至"),
const Text('分享至'),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("会话")
Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('会话')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("朋友圈")
Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('朋友圈')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("收藏")
Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('收藏')
],
)
),
],
)
),
],
),
),
......@@ -86,10 +82,8 @@ class _ShareTextPageState extends State<ShareTextPage> {
void _shareText() {
shareToWeChat(WeChatShareTextModel(_text, scene: scene)).then((data) {
print("-->$data");
print('-->$data');
});
// sendAuth(WeChatSendAuthModel(scope: "snsapi_userinfo",state: "wechat_sdk_demo_test"));
}
void handleRadioValueChanged(WeChatScene scene) {
......
......@@ -2,117 +2,116 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
class ShareVideoPage extends StatefulWidget {
const ShareVideoPage({Key? key}) : super(key: key);
@override
_ShareMusicPageState createState() => _ShareMusicPageState();
}
class _ShareMusicPageState extends State<ShareVideoPage> {
String _videoUrl = "http://www.qq.com";
String _videoLowBandUrl = "http://www.qq.com";
String _title = "Beyond";
String _description = "A Popular Rock Band From China";
String _thumnail = "images/logo.png";
String _videoUrl = 'http://www.qq.com';
String _videoLowBandUrl = 'http://www.qq.com';
String _title = 'Beyond';
String _description = 'A Popular Rock Band From China';
String _thumnail = 'images/logo.png';
WeChatScene scene = WeChatScene.SESSION;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
appBar: AppBar(
title: const Text("ShareVideoPage"),
title: const Text('ShareVideoPage'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.share,
color: Colors.white,
),
onPressed: _share)
icon: Icon(Icons.share, color: Colors.white),
onPressed: _share,
),
],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: new Column(
child: Column(
children: <Widget>[
new TextField(
TextField(
controller: TextEditingController(
text:
"http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3"),
text: 'http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/'
'0042515_05.ANDY.mp3',
),
onChanged: (str) {
_videoUrl = str;
},
decoration: InputDecoration(labelText: "video url"),
decoration: InputDecoration(labelText: 'video url'),
),
new TextField(
controller: TextEditingController(text: "http://www.qq.com"),
TextField(
controller: TextEditingController(text: 'http://www.qq.com'),
onChanged: (str) {
_videoLowBandUrl = str;
},
decoration: InputDecoration(labelText: "video low band url"),
decoration: InputDecoration(labelText: 'video low band url'),
),
new TextField(
controller: TextEditingController(text: "Beyond"),
TextField(
controller: TextEditingController(text: 'Beyond'),
onChanged: (str) {
_title = str;
},
decoration: InputDecoration(labelText: "title"),
decoration: InputDecoration(labelText: 'title'),
),
new TextField(
TextField(
controller:
TextEditingController(text: "A Popular Rock Band From China"),
TextEditingController(text: 'A Popular Rock Band From China'),
onChanged: (str) {
_description = str;
},
decoration: InputDecoration(labelText: "description"),
decoration: InputDecoration(labelText: 'description'),
),
new TextField(
controller: TextEditingController(text: "images/logo.png"),
TextField(
controller: TextEditingController(text: 'images/logo.png'),
onChanged: (str) {
_thumnail = str;
},
decoration: InputDecoration(labelText: "thumbnail"),
decoration: InputDecoration(labelText: 'thumbnail'),
),
new Row(
Row(
children: <Widget>[
const Text("分享至"),
const Text('分享至'),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("会话")
Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('会话')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("朋友圈")
Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('朋友圈')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("收藏")
Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('收藏')
],
)
),
],
)
),
],
),
),
......@@ -120,13 +119,14 @@ class _ShareMusicPageState extends State<ShareVideoPage> {
}
void _share() {
var model = new WeChatShareVideoModel(
videoUrl: _videoUrl,
videoLowBandUrl: _videoLowBandUrl,
thumbnail: WeChatImage.network(_thumnail),
description: _description,
scene: this.scene,
title: _title);
var model = WeChatShareVideoModel(
videoUrl: _videoUrl,
videoLowBandUrl: _videoLowBandUrl,
thumbnail: WeChatImage.network(_thumnail),
description: _description,
scene: this.scene,
title: _title,
);
shareToWeChat(model);
}
......
......@@ -2,97 +2,94 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
class ShareWebPagePage extends StatefulWidget {
const ShareWebPagePage({Key? key}) : super(key: key);
@override
ShareWebPagePageState createState() {
return new ShareWebPagePageState();
}
ShareWebPagePageState createState() => ShareWebPagePageState();
}
class ShareWebPagePageState extends State<ShareWebPagePage> {
String _url = "share text from fluwx";
String _title = "Fluwx";
String _thumnail = "images/logo.png";
String _url = 'share text from fluwx';
String _title = 'Fluwx';
String _thumnail = 'images/logo.png';
WeChatScene scene = WeChatScene.SESSION;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
appBar: AppBar(
title: const Text("ShareWebPage"),
title: const Text('ShareWebPage'),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.share,
color: Colors.white,
),
onPressed: _share)
icon: Icon(Icons.share, color: Colors.white),
onPressed: _share,
),
],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: new Column(
child: Column(
children: <Widget>[
new TextField(
TextField(
controller: TextEditingController(
text: "https://github.com/JarvanMo/fluwx"),
text: 'https://github.com/JarvanMo/fluwx',
),
onChanged: (str) {
_url = str;
},
decoration: InputDecoration(labelText: "web page"),
decoration: InputDecoration(labelText: 'web page'),
),
new TextField(
controller: TextEditingController(text: "Fluwx"),
TextField(
controller: TextEditingController(text: 'Fluwx'),
onChanged: (str) {
_title = str;
},
decoration: InputDecoration(labelText: "thumbnail"),
decoration: InputDecoration(labelText: 'thumbnail'),
),
new TextField(
controller: TextEditingController(text: "images/logo.png"),
TextField(
controller: TextEditingController(text: 'images/logo.png'),
onChanged: (str) {
_thumnail = str;
},
decoration: InputDecoration(labelText: "thumbnail"),
decoration: InputDecoration(labelText: 'thumbnail'),
),
new Row(
Row(
children: <Widget>[
const Text("分享至"),
const Text('分享至'),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("会话")
Radio<WeChatScene>(
value: WeChatScene.SESSION,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('会话')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("朋友圈")
Radio<WeChatScene>(
value: WeChatScene.TIMELINE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('朋友圈')
],
),
Row(
children: <Widget>[
new Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
}),
const Text("收藏")
Radio<WeChatScene>(
value: WeChatScene.FAVORITE,
groupValue: scene,
onChanged: (v) {
if (v != null) handleRadioValueChanged(v);
},
),
const Text('收藏')
],
)
],
......
......@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
class SignAutoDeductPage extends StatefulWidget {
const SignAutoDeductPage({Key? key}) : super(key: key);
@override
_SignAutoDeductPageState createState() => _SignAutoDeductPageState();
}
......@@ -10,24 +12,24 @@ class SignAutoDeductPage extends StatefulWidget {
/// see wechat [document](https://pay.weixin.qq.com/wiki/doc/api/pap.php?chapter=18_5&index=2)
class _SignAutoDeductPageState extends State<SignAutoDeductPage> {
TextEditingController appId =
TextEditingController(text: "wx316f9c82e99ac105");
TextEditingController mchId = TextEditingController(text: "");
TextEditingController planId = TextEditingController(text: "");
TextEditingController contractCode = TextEditingController(text: "");
TextEditingController requestSerial = TextEditingController(text: "");
TextEditingController(text: 'wx316f9c82e99ac105');
TextEditingController mchId = TextEditingController(text: '');
TextEditingController planId = TextEditingController(text: '');
TextEditingController contractCode = TextEditingController(text: '');
TextEditingController requestSerial = TextEditingController(text: '');
TextEditingController contractDisplayAccount =
TextEditingController(text: "");
TextEditingController notifyUrl = TextEditingController(text: "");
TextEditingController version = TextEditingController(text: "1.0");
TextEditingController sign = TextEditingController(text: "");
TextEditingController timestamp = TextEditingController(text: "");
TextEditingController returnApp = TextEditingController(text: "3");
TextEditingController(text: '');
TextEditingController notifyUrl = TextEditingController(text: '');
TextEditingController version = TextEditingController(text: '1.0');
TextEditingController sign = TextEditingController(text: '');
TextEditingController timestamp = TextEditingController(text: '');
TextEditingController returnApp = TextEditingController(text: '3');
@override
void initState() {
super.initState();
weChatResponseEventHandler.listen((resp) {
print("resp = ${resp.isSuccessful}");
print('resp = ${resp.isSuccessful}');
});
}
......@@ -57,21 +59,50 @@ class _SignAutoDeductPageState extends State<SignAutoDeductPage> {
body: Container(
child: ListView(
children: <Widget>[
_buildTextField(title: "appId", textEditController: appId),
_buildTextField(title: "mchId", textEditController: mchId),
_buildTextField(title: "planId", textEditController: planId),
_buildTextField(
title: "contractCode", textEditController: contractCode),
title: 'appId',
textEditController: appId,
),
_buildTextField(
title: 'mchId',
textEditController: mchId,
),
_buildTextField(
title: 'planId',
textEditController: planId,
),
_buildTextField(
title: 'contractCode',
textEditController: contractCode,
),
_buildTextField(
title: 'requestSerial',
textEditController: requestSerial,
),
_buildTextField(
title: 'contractDisplayAccount',
textEditController: contractDisplayAccount,
),
_buildTextField(
title: 'notifyUrl',
textEditController: notifyUrl,
),
_buildTextField(
title: "requestSerial", textEditController: requestSerial),
title: 'version',
textEditController: version,
),
_buildTextField(
title: 'sign',
textEditController: sign,
),
_buildTextField(
title: "contractDisplayAccount",
textEditController: contractDisplayAccount),
_buildTextField(title: "notifyUrl", textEditController: notifyUrl),
_buildTextField(title: "version", textEditController: version),
_buildTextField(title: "sign", textEditController: sign),
_buildTextField(title: "timestamp", textEditController: timestamp),
_buildTextField(title: "returnApp", textEditController: returnApp),
title: 'timestamp',
textEditController: timestamp,
),
_buildTextField(
title: 'returnApp',
textEditController: returnApp,
),
CupertinoButton(
child: Text('request once sign auto-deduct message'),
onPressed: _signAutoDeduct,
......@@ -87,25 +118,24 @@ class _SignAutoDeductPageState extends State<SignAutoDeductPage> {
TextEditingController? textEditController,
}) {
return TextField(
decoration: InputDecoration(
labelText: title,
),
decoration: InputDecoration(labelText: title),
controller: textEditController,
);
}
void _signAutoDeduct() {
autoDeDuctWeChat(
appId: appId.text ,
mchId: mchId.text,
planId: planId.text ,
contractCode: contractCode.text,
requestSerial: requestSerial.text,
contractDisplayAccount: contractDisplayAccount.text,
notifyUrl: notifyUrl.text,
version: version.text,
sign: sign.text,
timestamp: timestamp.text,
returnApp: '3');
appId: appId.text,
mchId: mchId.text,
planId: planId.text,
contractCode: contractCode.text,
requestSerial: requestSerial.text,
contractDisplayAccount: contractDisplayAccount.text,
notifyUrl: notifyUrl.text,
version: version.text,
sign: sign.text,
timestamp: timestamp.text,
returnApp: '3',
);
}
}
......@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart';
class SubscribeMessagePage extends StatefulWidget {
const SubscribeMessagePage({Key? key}) : super(key: key);
@override
_SubscribeMessagePageState createState() => _SubscribeMessagePageState();
}
......@@ -9,17 +11,17 @@ class SubscribeMessagePage extends StatefulWidget {
/// see wechat [document](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1500434436_aWfqW&token=&lang=zh_CN)
class _SubscribeMessagePageState extends State<SubscribeMessagePage> {
TextEditingController appId =
TextEditingController(text: "wx316f9c82e99ac105");
TextEditingController scene = TextEditingController(text: "1");
TextEditingController(text: 'wx316f9c82e99ac105');
TextEditingController scene = TextEditingController(text: '1');
TextEditingController templateId = TextEditingController(
text: "cm_vM2k3IjHcYbkGUeAfL6Fja_7Pgv4Hx_q4tA253Ss");
TextEditingController reserved = TextEditingController(text: "123");
text: 'cm_vM2k3IjHcYbkGUeAfL6Fja_7Pgv4Hx_q4tA253Ss');
TextEditingController reserved = TextEditingController(text: '123');
@override
void initState() {
super.initState();
weChatResponseEventHandler.listen((resp) {
print("resp = $resp");
print('resp = $resp');
});
}
......@@ -41,12 +43,23 @@ class _SubscribeMessagePageState extends State<SubscribeMessagePage> {
body: Container(
child: Column(
children: <Widget>[
_buildTextField(title: "appId", textEditController: appId),
_buildTextField(title: "scene", textEditController: scene),
_buildTextField(
title: "templateId", textEditController: templateId),
_buildTextField(title: "reserved", textEditController: reserved),
FlatButton(
title: 'appId',
textEditController: appId,
),
_buildTextField(
title: 'scene',
textEditController: scene,
),
_buildTextField(
title: 'templateId',
textEditController: templateId,
),
_buildTextField(
title: 'reserved',
textEditController: reserved,
),
TextButton(
child: Text('request once subscribe message'),
onPressed: _requestSubMsg,
),
......@@ -61,9 +74,7 @@ class _SubscribeMessagePageState extends State<SubscribeMessagePage> {
TextEditingController? textEditController,
}) {
return TextField(
decoration: InputDecoration(
labelText: title,
),
decoration: InputDecoration(labelText: title),
controller: textEditController,
);
}
......
......@@ -5,7 +5,6 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx_example/main.dart';
......
......@@ -4,8 +4,8 @@
/// A open sou;rce project authorized by [OpenFlutter](https://github.com/OpenFlutter).
library fluwx;
export 'package:fluwx/src/fluwx_iml.dart';
export 'package:fluwx/src/response/wechat_response.dart';
export 'package:fluwx/src/share/share_models.dart';
export 'package:fluwx/src/wechat_enums.dart';
export 'package:fluwx/src/wechat_file.dart' hide FileSchema;
export 'src/fluwx_iml.dart';
export 'src/response/wechat_response.dart';
export 'src/share/share_models.dart';
export 'src/wechat_enums.dart';
export 'src/wechat_file.dart' hide FileSchema;
......@@ -20,86 +20,90 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/wechat_enums.dart';
const Map<Type, String> _shareModelMethodMapper = {
WeChatShareTextModel: "shareText",
WeChatShareImageModel: "shareImage",
WeChatShareMusicModel: "shareMusic",
WeChatShareVideoModel: "shareVideo",
WeChatShareWebPageModel: "shareWebPage",
WeChatShareMiniProgramModel: "shareMiniProgram",
WeChatShareFileModel: "shareFile",
WeChatShareTextModel: 'shareText',
WeChatShareImageModel: 'shareImage',
WeChatShareMusicModel: 'shareMusic',
WeChatShareVideoModel: 'shareVideo',
WeChatShareWebPageModel: 'shareWebPage',
WeChatShareMiniProgramModel: 'shareMiniProgram',
WeChatShareFileModel: 'shareFile',
};
MethodChannel _channel = MethodChannel('com.jarvanmo/fluwx')
..setMethodCallHandler(_methodHandler);
StreamController<BaseWeChatResponse> _weChatResponseEventHandlerController =
new StreamController.broadcast();
StreamController.broadcast();
/// Response answers from WeChat after sharing, payment etc.
Stream<BaseWeChatResponse> get weChatResponseEventHandler =>
_weChatResponseEventHandlerController.stream;
///true if WeChat installed,otherwise false.
///Please add WeChat to the white list in order to get the correct result on IOS.
/// [true] if WeChat installed, otherwise [false].
/// Please add WeChat to the white list in order use this method on IOS.
Future<bool> get isWeChatInstalled async {
return await _channel.invokeMethod("isWeChatInstalled");
return await _channel.invokeMethod('isWeChatInstalled');
}
///just open WeChat, noting to do.
Future<bool> openWeChatApp() async {
return await _channel.invokeMethod("openWXApp");
return await _channel.invokeMethod('openWXApp');
}
/// it's ok if you register multi times.
///[appId] is not necessary.
///if [doOnIOS] is true ,fluwx will register WXApi on iOS.
///if [doOnAndroid] is true, fluwx will register WXApi on Android.
/// It's ok if you register multi times.
/// [appId] is not necessary.
/// if [doOnIOS] is true ,fluwx will register WXApi on iOS.
/// if [doOnAndroid] is true, fluwx will register WXApi on Android.
/// [universalLink] is required if you want to register on iOS.
Future<bool> registerWxApi(
{required String appId,
bool doOnIOS: true,
bool doOnAndroid: true,
String? universalLink}) async {
Future<bool> registerWxApi({
required String appId,
bool doOnIOS: true,
bool doOnAndroid: true,
String? universalLink,
}) async {
if (doOnIOS && Platform.isIOS) {
if (universalLink == null ||
universalLink.trim().isEmpty ||
!universalLink.startsWith("https")) {
throw ArgumentError.value(universalLink,
"you're trying to use illegal universal link , see https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html for detail");
!universalLink.startsWith('https')) {
throw ArgumentError.value(
universalLink,
"You're trying to use illegal universal link, see "
'https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html '
'for more detai.l',
);
}
}
return await _channel.invokeMethod("registerApp", {
"appId": appId,
"iOS": doOnIOS,
"android": doOnAndroid,
"universalLink": universalLink
return await _channel.invokeMethod('registerApp', {
'appId': appId,
'iOS': doOnIOS,
'android': doOnAndroid,
'universalLink': universalLink
});
}
// get ext Message
Future<String?> getExtMsg() async {
return await _channel.invokeMethod("getExtMsg");
// Get ext Message
Future<String?> getExtMsg() {
return _channel.invokeMethod('getExtMsg');
}
///Share your requests to WeChat.
///This depends on the actual type of [model].
///see [_shareModelMethodMapper] for detail.
/// Share your requests to WeChat.
/// This depends on the actual type of [model].
/// see [_shareModelMethodMapper] for detail.
Future<bool> shareToWeChat(WeChatShareBaseModel model) async {
if (_shareModelMethodMapper.containsKey(model.runtimeType)) {
var methodChannel = _shareModelMethodMapper[model.runtimeType];
if (methodChannel == null)
final methodChannel = _shareModelMethodMapper[model.runtimeType];
if (methodChannel == null) {
throw ArgumentError.value(
"${model.runtimeType} method channel not found");
'${model.runtimeType} method channel not found',
);
}
return await _channel.invokeMethod(methodChannel, model.toMap());
} else {
return Future.error("no method mapper found[${model.runtimeType}]");
}
return Future.error('no method mapper found[${model.runtimeType}]');
}
/// The WeChat-Login is under Auth-2.0
......@@ -109,58 +113,64 @@ Future<bool> shareToWeChat(WeChatShareBaseModel model) async {
/// Once AuthCode got, you need to request Access_Token
/// For more information please visit:
/// * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419317851&token=
Future<bool> sendWeChatAuth(
{required String scope, String state = "state"}) async {
Future<bool> sendWeChatAuth({
required String scope,
String state = 'state',
}) async {
assert(scope.trim().isNotEmpty);
return await _channel
.invokeMethod("sendAuth", {"scope": scope, "state": state});
return await _channel.invokeMethod(
'sendAuth',
{'scope': scope, 'state': state},
);
}
/// open mini-program
/// see [WXMiniProgramType]
Future<bool> launchWeChatMiniProgram(
{required String username,
String? path,
WXMiniProgramType miniProgramType = WXMiniProgramType.RELEASE}) async {
Future<bool> launchWeChatMiniProgram({
required String username,
String? path,
WXMiniProgramType miniProgramType = WXMiniProgramType.RELEASE,
}) async {
assert(username.trim().isNotEmpty);
return await _channel.invokeMethod("launchMiniProgram", {
"userName": username,
"path": path,
"miniProgramType": miniProgramType.toNativeInt()
return await _channel.invokeMethod('launchMiniProgram', {
'userName': username,
'path': path,
'miniProgramType': miniProgramType.toNativeInt()
});
}
/// request payment with WeChat.
/// Read the official document for more detail.
/// [timeStamp] is int because [timeStamp] will be mapped to Unit32.
Future<bool> payWithWeChat(
{required String appId,
required String partnerId,
required String prepayId,
required String packageValue,
required String nonceStr,
required int timeStamp,
required String sign,
String? signType,
String? extData}) async {
return await _channel.invokeMethod("payWithFluwx", {
"appId": appId,
"partnerId": partnerId,
"prepayId": prepayId,
"packageValue": packageValue,
"nonceStr": nonceStr,
"timeStamp": timeStamp,
"sign": sign,
"signType": signType,
"extData": extData,
Future<bool> payWithWeChat({
required String appId,
required String partnerId,
required String prepayId,
required String packageValue,
required String nonceStr,
required int timeStamp,
required String sign,
String? signType,
String? extData,
}) async {
return await _channel.invokeMethod('payWithFluwx', {
'appId': appId,
'partnerId': partnerId,
'prepayId': prepayId,
'packageValue': packageValue,
'nonceStr': nonceStr,
'timeStamp': timeStamp,
'sign': sign,
'signType': signType,
'extData': extData,
});
}
/// request Hong Kong Wallet payment with WeChat.
/// Read the official document for more detail.
Future<bool> payWithWeChatHongKongWallet({required String prepayId}) async {
return await _channel.invokeMethod("payWithHongKongWallet", {
"prepayId": prepayId,
return await _channel.invokeMethod('payWithHongKongWallet', {
'prepayId': prepayId,
});
}
......@@ -172,31 +182,32 @@ Future<bool> subscribeWeChatMsg({
String? reserved,
}) async {
return await _channel.invokeMethod(
"subscribeMsg",
'subscribeMsg',
{
"appId": appId,
"scene": scene,
"templateId": templateId,
"reserved": reserved,
'appId': appId,
'scene': scene,
'templateId': templateId,
'reserved': reserved,
},
);
}
/// please read official docs.
Future<bool> autoDeDuctWeChat(
{required String appId,
required String mchId,
required String planId,
required String contractCode,
required String requestSerial,
required String contractDisplayAccount,
required String notifyUrl,
required String version,
required String sign,
required String timestamp,
String returnApp = '3',
int businessType = 12}) async {
return await _channel.invokeMethod("autoDeduct", {
Future<bool> autoDeDuctWeChat({
required String appId,
required String mchId,
required String planId,
required String contractCode,
required String requestSerial,
required String contractDisplayAccount,
required String notifyUrl,
required String version,
required String sign,
required String timestamp,
String returnApp = '3',
int businessType = 12,
}) async {
return await _channel.invokeMethod('autoDeduct', {
'appid': appId,
'mch_id': mchId,
'plan_id': planId,
......@@ -208,7 +219,7 @@ Future<bool> autoDeDuctWeChat(
'sign': sign,
'timestamp': timestamp,
'return_app': returnApp,
"businessType": businessType
'businessType': businessType
});
}
......@@ -217,49 +228,61 @@ Future<bool> autoDeDuctWeChat(
/// All required params must not be null or empty
/// [schemeData] only works on iOS
/// see * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=215238808828h4XN&token=&lang=zh_CN
Future<bool> authWeChatByQRCode(
{required String appId,
required String scope,
required String nonceStr,
required String timeStamp,
required String signature,
String? schemeData}) async {
Future<bool> authWeChatByQRCode({
required String appId,
required String scope,
required String nonceStr,
required String timeStamp,
required String signature,
String? schemeData,
}) async {
assert(appId.isNotEmpty);
assert(scope.isNotEmpty);
assert(nonceStr.isNotEmpty);
assert(timeStamp.isNotEmpty);
assert(signature.isNotEmpty);
return await _channel.invokeMethod("authByQRCode", {
"appId": appId,
"scope": scope,
"nonceStr": nonceStr,
"timeStamp": timeStamp,
"signature": signature,
"schemeData": schemeData
return await _channel.invokeMethod('authByQRCode', {
'appId': appId,
'scope': scope,
'nonceStr': nonceStr,
'timeStamp': timeStamp,
'signature': signature,
'schemeData': schemeData
});
}
/// stop [authWeChatByQRCode]
Future<bool> stopWeChatAuthByQRCode() async {
return await _channel.invokeMethod("stopAuthByQRCode");
return await _channel.invokeMethod('stopAuthByQRCode');
}
Future _methodHandler(MethodCall methodCall) {
var response =
BaseWeChatResponse.create(methodCall.method, methodCall.arguments);
final response = BaseWeChatResponse.create(
methodCall.method,
methodCall.arguments,
);
_weChatResponseEventHandlerController.add(response);
return Future.value();
}
///IOS only
Future<bool> authWeChatByPhoneLogin(
{required String scope, String state = "state"}) async {
return await _channel
.invokeMethod("authByPhoneLogin", {"scope": scope, "state": state});
/// IOS only
Future<bool> authWeChatByPhoneLogin({
required String scope,
String state = 'state',
}) async {
return await _channel.invokeMethod(
'authByPhoneLogin',
{'scope': scope, 'state': state},
);
}
Future<bool> openWeChatCustomerServiceChat({required String url, required String corpId}) async {
return await _channel
.invokeMethod("openWeChatCustomerServiceChat", {"corpId": corpId, "url": url});
}
\ No newline at end of file
Future<bool> openWeChatCustomerServiceChat({
required String url,
required String corpId,
}) async {
return await _channel.invokeMethod(
'openWeChatCustomerServiceChat',
{'corpId': corpId, 'url': url},
);
}
......@@ -19,42 +19,37 @@
import 'dart:typed_data';
const String _errCode = "errCode";
const String _errStr = "errStr";
const String _errCode = 'errCode';
const String _errStr = 'errStr';
typedef BaseWeChatResponse _WeChatResponseInvoker(Map argument);
Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
"onShareResponse": (Map argument) => WeChatShareResponse.fromMap(argument),
"onAuthResponse": (Map argument) => WeChatAuthResponse.fromMap(argument),
"onLaunchMiniProgramResponse": (Map argument) =>
'onShareResponse': (Map argument) => WeChatShareResponse.fromMap(argument),
'onAuthResponse': (Map argument) => WeChatAuthResponse.fromMap(argument),
'onLaunchMiniProgramResponse': (Map argument) =>
WeChatLaunchMiniProgramResponse.fromMap(argument),
"onPayResponse": (Map argument) => WeChatPaymentResponse.fromMap(argument),
"onSubscribeMsgResp": (Map argument) =>
'onPayResponse': (Map argument) => WeChatPaymentResponse.fromMap(argument),
'onSubscribeMsgResp': (Map argument) =>
WeChatSubscribeMsgResponse.fromMap(argument),
"onWXOpenBusinessWebviewResponse": (Map argument) =>
'onWXOpenBusinessWebviewResponse': (Map argument) =>
WeChatOpenBusinessWebviewResponse.fromMap(argument),
"onAuthByQRCodeFinished": (Map argument) =>
'onAuthByQRCodeFinished': (Map argument) =>
WeChatAuthByQRCodeFinishedResponse.fromMap(argument),
"onAuthGotQRCode": (Map argument) =>
'onAuthGotQRCode': (Map argument) =>
WeChatAuthGotQRCodeResponse.fromMap(argument),
"onQRCodeScanned": (Map argument) =>
'onQRCodeScanned': (Map argument) =>
WeChatQRCodeScannedResponse.fromMap(argument),
"onWXShowMessageFromWX": (Map argument) =>
'onWXShowMessageFromWX': (Map argument) =>
WeChatShowMessageFromWXRequest.fromMap(argument),
"onWXOpenCustomerServiceChatResponse": (Map argument) =>
'onWXOpenCustomerServiceChatResponse': (Map argument) =>
WeChatOpenCustomerServiceChatResponse.fromMap(argument),
};
class BaseWeChatResponse {
final int errCode;
final String? errStr;
bool get isSuccessful => errCode == 0;
BaseWeChatResponse._(this.errCode, this.errStr);
/// create response from response pool
/// Create response from the response pool.
factory BaseWeChatResponse.create(String name, Map argument) {
var result = _nameAndResponseMapper[name];
if (result == null) {
......@@ -62,127 +57,129 @@ class BaseWeChatResponse {
}
return result(argument);
}
final int errCode;
final String? errStr;
bool get isSuccessful => errCode == 0;
}
class WeChatShareResponse extends BaseWeChatResponse {
final int type;
WeChatShareResponse.fromMap(Map map)
: type = map["type"],
: type = map['type'],
super._(map[_errCode], map[_errStr]);
final int type;
}
class WeChatAuthResponse extends BaseWeChatResponse {
WeChatAuthResponse.fromMap(Map map)
: type = map['type'],
country = map['country'],
lang = map['lang'],
code = map['code'],
state = map['state'],
super._(map[_errCode], map[_errStr]);
final int type;
final String? country;
final String? lang;
final String? code;
final String? state;
WeChatAuthResponse.fromMap(Map map)
: type = map["type"],
country = map["country"],
lang = map["lang"],
code = map["code"],
state = map["state"],
super._(map[_errCode], map[_errStr]);
@override
bool operator ==(other) {
if (other is WeChatAuthResponse) {
return code == other.code &&
country == other.country &&
lang == other.lang &&
state == other.state;
} else {
return false;
}
return other is WeChatAuthResponse &&
code == other.code &&
country == other.country &&
lang == other.lang &&
state == other.state;
}
@override
int get hashCode =>
super.hashCode + errCode.hashCode &
1345 + errStr.hashCode &
15 + (code ?? "").hashCode &
15 + (code ?? '').hashCode &
1432;
}
class WeChatLaunchMiniProgramResponse extends BaseWeChatResponse {
final int? type;
final String? extMsg;
WeChatLaunchMiniProgramResponse.fromMap(Map map)
: type = map["type"],
extMsg = map["extMsg"],
: type = map['type'],
extMsg = map['extMsg'],
super._(map[_errCode], map[_errStr]);
final int? type;
final String? extMsg;
}
class WeChatPaymentResponse extends BaseWeChatResponse {
final int type;
final String? extData;
WeChatPaymentResponse.fromMap(Map map)
: type = map["type"],
extData = map["extData"],
: type = map['type'],
extData = map['extData'],
super._(map[_errCode], map[_errStr]);
final int type;
final String? extData;
}
class WeChatOpenCustomerServiceChatResponse extends BaseWeChatResponse {
final String? extMsg;
WeChatOpenCustomerServiceChatResponse.fromMap(Map map)
: extMsg = map["extMsg"],
: extMsg = map['extMsg'],
super._(map[_errCode], map[_errStr]);
final String? extMsg;
}
class WeChatSubscribeMsgResponse extends BaseWeChatResponse {
WeChatSubscribeMsgResponse.fromMap(Map map)
: openid = map['openid'],
templateId = map['templateId'],
action = map['action'],
reserved = map['reserved'],
scene = map['scene'],
super._(map[_errCode], map[_errStr]);
final String? openid;
final String? templateId;
final String? action;
final String? reserved;
final int scene;
WeChatSubscribeMsgResponse.fromMap(Map map)
: openid = map["openid"],
templateId = map["templateId"],
action = map["action"],
reserved = map["reserved"],
scene = map["scene"],
super._(map[_errCode], map[_errStr]);
}
class WeChatOpenBusinessWebviewResponse extends BaseWeChatResponse {
WeChatOpenBusinessWebviewResponse.fromMap(Map map)
: type = map['type'],
errCode = map[_errCode],
businessType = map['businessType'],
resultInfo = map['resultInfo'],
super._(map[_errCode], map[_errStr]);
final int? type;
final int errCode;
final int? businessType;
final String resultInfo;
WeChatOpenBusinessWebviewResponse.fromMap(Map map)
: type = map["type"],
errCode = map[_errCode],
businessType = map["businessType"],
resultInfo = map["resultInfo"],
super._(map[_errCode], map[_errStr]);
}
class WeChatAuthByQRCodeFinishedResponse extends BaseWeChatResponse {
final String? authCode;
final AuthByQRCodeErrorCode? qrCodeErrorCode;
WeChatAuthByQRCodeFinishedResponse.fromMap(Map map)
: authCode = map["authCode"],
: authCode = map['authCode'],
qrCodeErrorCode = (_authByQRCodeErrorCodes[_errCode] ??
AuthByQRCodeErrorCode.UNKNOWN),
super._(map[_errCode], map[_errStr]);
final String? authCode;
final AuthByQRCodeErrorCode? qrCodeErrorCode;
}
///[qrCode] in memory.
class WeChatAuthGotQRCodeResponse extends BaseWeChatResponse {
final Uint8List? qrCode;
WeChatAuthGotQRCodeResponse.fromMap(Map map)
: qrCode = map["qrCode"],
: qrCode = map['qrCode'],
super._(map[_errCode], map[_errStr]);
final Uint8List? qrCode;
}
class WeChatQRCodeScannedResponse extends BaseWeChatResponse {
......@@ -192,30 +189,21 @@ class WeChatQRCodeScannedResponse extends BaseWeChatResponse {
// 获取微信打开App时携带的参数
class WeChatShowMessageFromWXRequest extends BaseWeChatResponse {
final String? extMsg;
WeChatShowMessageFromWXRequest.fromMap(Map map)
: extMsg = map["extMsg"],
: extMsg = map['extMsg'],
super._(0, '');
final String? extMsg;
}
///WechatAuth_Err_OK(0),
///WechatAuth_Err_NormalErr(-1),
///WechatAuth_Err_NetworkErr(-2),
///WechatAuth_Err_JsonDecodeErr(-3),
///WechatAuth_Err_Cancel(-4),
///WechatAuth_Err_Timeout(-5),
///WechatAuth_Err_Auth_Stopped(-6);
///[AuthByQRCodeErrorCode.JSON_DECODE_ERR] means WechatAuth_Err_GetQrcodeFailed when platform is iOS
///only Android will get [AUTH_STOPPED]
enum AuthByQRCodeErrorCode {
OK,
NORMAL_ERR,
NETWORK_ERR,
JSON_DECODE_ERR,
CANCEL,
TIMEOUT,
AUTH_STOPPED,
OK, // WechatAuth_Err_OK(0)
NORMAL_ERR, // WechatAuth_Err_NormalErr(-1)
NETWORK_ERR, // WechatAuth_Err_NetworkErr(-2)
JSON_DECODE_ERR, // WechatAuth_Err_JsonDecodeErr(-3), WechatAuth_Err_GetQrcodeFailed on iOS
CANCEL, // WechatAuth_Err_Cancel(-4)
TIMEOUT, // WechatAuth_Err_Timeout(-5)
AUTH_STOPPED, // WechatAuth_Err_Auth_Stopped(-6), Android only
UNKNOWN
}
......
......@@ -16,9 +16,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
import 'package:flutter/foundation.dart';
import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/wechat_enums.dart';
const String _scene = "scene";
const String _source = "source";
......@@ -34,9 +32,20 @@ mixin WeChatShareBaseModel {
Map toMap();
}
///[source] the text you want to send to WeChat
///[scene] the target you want to send
/// [source] the text you want to send to WeChat
/// [scene] the target you want to send
class WeChatShareTextModel implements WeChatShareBaseModel {
WeChatShareTextModel(
this.source, {
this.scene = WeChatScene.SESSION,
this.mediaTagName,
this.messageAction,
this.messageExt,
String? description,
String? title,
}) : this.title = title ?? source,
this.description = description ?? source;
final String source;
final WeChatScene scene;
final String? messageExt;
......@@ -45,16 +54,6 @@ class WeChatShareTextModel implements WeChatShareBaseModel {
final String? title;
final String? description;
WeChatShareTextModel(this.source,
{this.scene = WeChatScene.SESSION,
this.mediaTagName,
this.messageAction,
this.messageExt,
String? description,
String? title})
: this.title = title ?? source,
this.description = description ?? source;
@override
Map toMap() {
return {
......@@ -69,10 +68,28 @@ class WeChatShareTextModel implements WeChatShareBaseModel {
}
}
///
/// the default value is [MINI_PROGRAM_TYPE_RELEASE]
///[hdImagePath] only works on iOS, not sure the relationship between [thumbnail] and [hdImagePath].
/// [hdImagePath] only works on iOS, not sure the relationship
/// between [thumbnail] and [hdImagePath].
class WeChatShareMiniProgramModel implements WeChatShareBaseModel {
WeChatShareMiniProgramModel({
required this.webPageUrl,
this.miniProgramType = WXMiniProgramType.RELEASE,
required this.userName,
this.path: "/",
this.title,
this.description,
this.withShareTicket: false,
this.thumbnail,
this.hdImagePath,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
}) : assert(webPageUrl.isNotEmpty),
assert(userName.isNotEmpty),
assert(path.isNotEmpty);
final String webPageUrl;
final WXMiniProgramType miniProgramType;
final String userName;
......@@ -87,24 +104,6 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel {
final String? mediaTagName;
final bool compressThumbnail;
WeChatShareMiniProgramModel(
{required this.webPageUrl,
this.miniProgramType = WXMiniProgramType.RELEASE,
required this.userName,
this.path: "/",
this.title,
this.description,
this.withShareTicket: false,
this.thumbnail,
this.hdImagePath,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true})
: assert(webPageUrl.isNotEmpty),
assert(userName.isNotEmpty),
assert(path.isNotEmpty);
@override
Map toMap() {
return {
......@@ -124,10 +123,22 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel {
}
}
///[source] the image you want to send to WeChat
///[scene] the target you want to send
///[thumbnail] the preview of your image, will be created from [scene] if null.
/// [source] the image you want to send to WeChat
/// [scene] the target you want to send
/// [thumbnail] the preview of your image, will be created from [scene] if null.
class WeChatShareImageModel implements WeChatShareBaseModel {
WeChatShareImageModel(
this.source, {
WeChatImage? thumbnail,
this.title,
this.scene = WeChatScene.SESSION,
this.description,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
}) : this.thumbnail = thumbnail ?? source;
final WeChatImage source;
final WeChatImage thumbnail;
final String? title;
......@@ -138,17 +149,6 @@ class WeChatShareImageModel implements WeChatShareBaseModel {
final String? mediaTagName;
final bool compressThumbnail;
WeChatShareImageModel(this.source,
{WeChatImage? thumbnail,
this.title,
this.scene = WeChatScene.SESSION,
this.description,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true})
: this.thumbnail = thumbnail ?? source;
@override
Map toMap() {
return {
......@@ -167,6 +167,21 @@ class WeChatShareImageModel implements WeChatShareBaseModel {
/// if [musicUrl] and [musicLowBandUrl] are both provided,
/// only [musicUrl] will be used.
class WeChatShareMusicModel implements WeChatShareBaseModel {
WeChatShareMusicModel({
this.musicUrl,
this.musicLowBandUrl,
this.title: "",
this.description: "",
this.musicDataUrl,
this.musicLowBandDataUrl,
this.thumbnail,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.scene = WeChatScene.SESSION,
this.compressThumbnail = true,
}) : assert(musicUrl != null || musicLowBandUrl != null);
final String? musicUrl;
final String? musicDataUrl;
final String? musicLowBandUrl;
......@@ -180,21 +195,6 @@ class WeChatShareMusicModel implements WeChatShareBaseModel {
final String? mediaTagName;
final bool compressThumbnail;
WeChatShareMusicModel(
{this.musicUrl,
this.musicLowBandUrl,
this.title: "",
this.description: "",
this.musicDataUrl,
this.musicLowBandDataUrl,
this.thumbnail,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.scene = WeChatScene.SESSION,
this.compressThumbnail = true})
: assert(musicUrl != null || musicLowBandUrl != null);
@override
Map toMap() {
return {
......@@ -216,6 +216,20 @@ class WeChatShareMusicModel implements WeChatShareBaseModel {
/// if [videoUrl] and [videoLowBandUrl] are both provided,
/// only [videoUrl] will be used.
class WeChatShareVideoModel implements WeChatShareBaseModel {
WeChatShareVideoModel({
this.scene = WeChatScene.SESSION,
this.videoUrl,
this.videoLowBandUrl,
this.title: "",
this.description: "",
this.thumbnail,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
}) : assert(videoUrl != null || videoLowBandUrl != null),
assert(thumbnail != null);
final String? videoUrl;
final String? videoLowBandUrl;
final WeChatImage? thumbnail;
......@@ -227,20 +241,6 @@ class WeChatShareVideoModel implements WeChatShareBaseModel {
final String? mediaTagName;
final bool compressThumbnail;
WeChatShareVideoModel(
{this.scene = WeChatScene.SESSION,
this.videoUrl,
this.videoLowBandUrl,
this.title: "",
this.description: "",
this.thumbnail,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true})
: assert(videoUrl != null || videoLowBandUrl != null),
assert(thumbnail != null);
@override
Map toMap() {
return {
......@@ -257,9 +257,22 @@ class WeChatShareVideoModel implements WeChatShareBaseModel {
}
}
///[webPage] url you want to send to wechat
///[thumbnail] logo of your website
/// [webPage] url you want to send to wechat
/// [thumbnail] logo of your website
class WeChatShareWebPageModel implements WeChatShareBaseModel {
WeChatShareWebPageModel(
this.webPage, {
this.title: "",
String? description,
this.thumbnail,
this.scene = WeChatScene.SESSION,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
}) : assert(webPage.isNotEmpty),
this.description = description ?? webPage;
final String webPage;
final WeChatImage? thumbnail;
final String title;
......@@ -270,18 +283,6 @@ class WeChatShareWebPageModel implements WeChatShareBaseModel {
final String? mediaTagName;
final bool compressThumbnail;
WeChatShareWebPageModel(this.webPage,
{this.title: "",
String? description,
this.thumbnail,
this.scene = WeChatScene.SESSION,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true})
: assert(webPage.isNotEmpty),
this.description = description ?? webPage;
@override
Map toMap() {
return {
......@@ -301,6 +302,18 @@ class WeChatShareWebPageModel implements WeChatShareBaseModel {
/// [scene] can't be [WeChatScene.TIMELINE], otherwise, sharing nothing.
/// send files to WeChat
class WeChatShareFileModel implements WeChatShareBaseModel {
WeChatShareFileModel(
this.source, {
this.title: "",
this.description: "",
this.thumbnail,
this.scene = WeChatScene.SESSION,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
});
final WeChatFile source;
final WeChatImage? thumbnail;
final String title;
......@@ -311,16 +324,6 @@ class WeChatShareFileModel implements WeChatShareBaseModel {
final String? mediaTagName;
final bool compressThumbnail;
WeChatShareFileModel(this.source,
{this.title: "",
this.description: "",
this.thumbnail,
this.scene = WeChatScene.SESSION,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true});
@override
Map toMap() {
return {
......
......@@ -17,14 +17,14 @@
* the License.
*/
///[WXMiniProgramType.RELEASE]正式版
///[WXMiniProgramType.TEST]测试版
///[WXMiniProgramType.PREVIEW]预览版
/// [WXMiniProgramType.RELEASE]正式版
/// [WXMiniProgramType.TEST]测试版
/// [WXMiniProgramType.PREVIEW]预览版
enum WXMiniProgramType { RELEASE, TEST, PREVIEW }
///[WeChatScene.SESSION]会话
///[WeChatScene.TIMELINE]朋友圈
///[WeChatScene.FAVORITE]收藏
/// [WeChatScene.SESSION]会话
/// [WeChatScene.TIMELINE]朋友圈
/// [WeChatScene.FAVORITE]收藏
enum WeChatScene { SESSION, TIMELINE, FAVORITE }
extension MiniProgramTypeExtensions on WXMiniProgramType {
......@@ -36,7 +36,8 @@ extension MiniProgramTypeExtensions on WXMiniProgramType {
return 1;
case WXMiniProgramType.RELEASE:
return 0;
default:
return 0;
}
return 0;
}
}
......@@ -4,14 +4,14 @@
* Licensed to the Apache Software Foundation (ASF) under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership. The ASF licenses this
* file to you under the Apache License, Version 2.0 (the "License"); you may not
* file to you under the Apache License, Version 2.0 (the 'License'); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
......@@ -19,85 +19,96 @@
import 'dart:io';
import 'dart:typed_data';
const String defaultSuffixJpeg = ".jpeg";
const String defaultSuffixTxt = ".txt";
const String defaultSuffixJpeg = '.jpeg';
const String defaultSuffixTxt = '.txt';
class WeChatImage extends WeChatFile {
WeChatImage.network(String source, {String suffix = defaultSuffixJpeg})
: super.network(source, suffix: suffix);
WeChatImage.network(
String source, {
String suffix = defaultSuffixJpeg,
}) : super.network(source, suffix: suffix);
WeChatImage.asset(String source, {String suffix = defaultSuffixJpeg})
: super.asset(source, suffix: suffix);
WeChatImage.asset(
String source, {
String suffix = defaultSuffixJpeg,
}) : super.asset(source, suffix: suffix);
WeChatImage.file(File source, {String suffix = defaultSuffixJpeg})
: super.file(source, suffix: suffix);
WeChatImage.file(
File source, {
String suffix = defaultSuffixJpeg,
}) : super.file(source, suffix: suffix);
WeChatImage.binary(Uint8List source, {String suffix = defaultSuffixJpeg})
: super.binary(source, suffix: suffix);
WeChatImage.binary(
Uint8List source, {
String suffix = defaultSuffixJpeg,
}) : super.binary(source, suffix: suffix);
}
class WeChatFile {
final dynamic source;
final FileSchema schema;
final String suffix;
/// [source] must begin with http or https
WeChatFile.network(String source, {String? suffix})
: assert(source.startsWith("http")),
this.source = source,
this.schema = FileSchema.NETWORK,
this.suffix = source.readSuffix(suffix, defaultSuffixTxt);
WeChatFile.network(
String source, {
String? suffix,
}) : assert(source.startsWith('http')),
source = source,
schema = FileSchema.NETWORK,
suffix = source.readSuffix(suffix, defaultSuffixTxt);
///[source] path of the image, like '/asset/image.pdf?package=flutter',
///the query param package in [source] only available when you want to specify the package of image
WeChatFile.asset(String source, {String? suffix})
: assert(source.trim().isNotEmpty),
WeChatFile.asset(
String source, {
String? suffix,
}) : assert(source.trim().isNotEmpty),
this.source = source,
this.schema = FileSchema.ASSET,
this.suffix = source.readSuffix(suffix, defaultSuffixTxt);
WeChatFile.file(File source, {String suffix = defaultSuffixTxt})
: this.source = source.path,
this.schema = FileSchema.FILE,
this.suffix = source.path.readSuffix(suffix, defaultSuffixTxt);
WeChatFile.file(
File source, {
String suffix = defaultSuffixTxt,
}) : source = source.path,
schema = FileSchema.FILE,
suffix = source.path.readSuffix(suffix, defaultSuffixTxt);
WeChatFile.binary(Uint8List source, {String suffix = defaultSuffixTxt})
: assert(suffix.trim().isNotEmpty),
this.source = source,
this.schema = FileSchema.BINARY,
this.suffix = suffix;
WeChatFile.binary(
Uint8List source, {
String suffix = defaultSuffixTxt,
}) : assert(suffix.trim().isNotEmpty),
source = source,
schema = FileSchema.BINARY,
suffix = suffix;
Map toMap() =>
{"source": source, "schema": schema.index, "suffix": suffix};
}
final dynamic source;
final FileSchema schema;
final String suffix;
///Types of image, usually there are for types listed below.
///[FileSchema.NETWORK] is online images.
///[FileSchema.ASSET] is flutter asset image.
///[FileSchema.BINARY] is binary image, shall be be [Uint8List]
///[FileSchema.FILE] is local file, usually not comes from flutter asset.
enum FileSchema {
NETWORK,
ASSET,
FILE,
BINARY,
Map toMap() => {'source': source, 'schema': schema.index, 'suffix': suffix};
}
/// Types of image, usually there are for types listed below.
///
/// [NETWORK] is online images.
/// [ASSET] is flutter asset image.
/// [BINARY] is binary image, shall be be [Uint8List]
/// [FILE] is local file, usually not comes from flutter asset.
enum FileSchema { NETWORK, ASSET, FILE, BINARY }
extension _FileSuffix on String {
/// returns [suffix] if [suffix] not blank.
/// If [suffix] is blank, then try to read from url
/// if suffix in url not found, then return jpg as default.
String readSuffix(String? suffix, String defaultSuffix) {
if (suffix != null && suffix.trim().isNotEmpty) {
if (suffix.startsWith(".")) {
if (suffix.startsWith('.')) {
return suffix;
} else {
return ".$suffix";
return '.$suffix';
}
}
var path = Uri.parse(this).path;
var index = path.lastIndexOf(".");
var index = path.lastIndexOf('.');
if (index >= 0) {
return path.substring(index);
......
......@@ -9,19 +9,23 @@ void main() {
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == "registerApp") {
if (methodCall.arguments["appId"] == "wx13124324324") {
if (methodCall.method == 'registerApp') {
if (methodCall.arguments['appId'] == 'wx13124324324') {
return Future.value(true);
} else {
return Future.value(false);
}
} else if (methodCall.method == "shareText") {
} else if (methodCall.method == 'shareText') {
channel.invokeMethod(
"onShareResponse", {"type": 1, "errCode": 1, "errStr": "hehe"});
'onShareResponse',
{'type': 1, 'errCode': 1, 'errStr': 'hehe'},
);
return Future.value(true);
} else if (methodCall.method == "shareImage") {
} else if (methodCall.method == 'shareImage') {
channel.invokeMethod(
"onShareResponse", {"type": 1, "errCode": 0, "errStr": ""});
'onShareResponse',
{'type': 1, 'errCode': 0, 'errStr': ''},
);
return Future.value(true);
}
return '42';
......@@ -32,34 +36,38 @@ void main() {
channel.setMockMethodCallHandler(null);
});
group("register", () {
test("success", () async {
expect(await fluwx.registerWxApi(appId: "wx13124324324"), true);
group('register', () {
test('success', () async {
expect(await fluwx.registerWxApi(appId: 'wx13124324324'), true);
});
test("failed", () async {
expect(await fluwx.registerWxApi(appId: "wx131256"), false);
test('failed', () async {
expect(await fluwx.registerWxApi(appId: 'wx131256'), false);
});
});
group("share", () {
test("text", () async {
group('share', () {
test('text', () async {
expect(
await fluwx.shareToWeChat(fluwx.WeChatShareTextModel("text")), true);
await fluwx.shareToWeChat(fluwx.WeChatShareTextModel('text')),
true,
);
});
test("shareImage", () async {
test('shareImage', () async {
expect(
await fluwx.shareToWeChat(fluwx.WeChatShareImageModel(
fluwx.WeChatImage.network("http://flutter.dev"))),
true);
await fluwx.shareToWeChat(
fluwx.WeChatShareImageModel(
fluwx.WeChatImage.network('http://flutter.dev'),
),
),
true,
);
});
});
group("learn", () {
test("description", () async {
print("argumentsss");
group('learn', () {
test('description', () async {
print('argumentsss');
});
});
}
......@@ -21,97 +21,103 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx/fluwx.dart';
void main() {
group("create response", () {
test("WeChatShareResponse", () {
group('create response', () {
test('WeChatShareResponse', () {
var response = BaseWeChatResponse.create(
"onShareResponse", {"type": 1, "errCode": 1, "errStr": "hehe"});
'onShareResponse',
{'type': 1, 'errCode': 1, 'errStr': 'hehe'},
);
expect(response is WeChatShareResponse, true);
var casted = response as WeChatShareResponse;
expect(casted.type, 1);
expect(casted.errCode, 1);
expect(casted.errStr, "hehe");
expect(casted.errStr, 'hehe');
});
test("WeChatAuthResponse", () {
var response = BaseWeChatResponse.create("onAuthResponse", {
"type": 1,
"errCode": 1,
"errStr": "hehe",
"country": "cn",
"lang": "lang",
"code": "code",
"state": "ok"
test('WeChatAuthResponse', () {
var response = BaseWeChatResponse.create('onAuthResponse', {
'type': 1,
'errCode': 1,
'errStr': 'hehe',
'country': 'cn',
'lang': 'lang',
'code': 'code',
'state': 'ok'
});
expect(response is WeChatAuthResponse, true);
var casted = response as WeChatAuthResponse;
expect(casted.type, 1);
expect(casted.errCode, 1);
expect(casted.errStr, "hehe");
expect(casted.country, "cn");
expect(casted.lang, "lang");
expect(casted.code, "code");
expect(casted.state, "ok");
expect(casted.errStr, 'hehe');
expect(casted.country, 'cn');
expect(casted.lang, 'lang');
expect(casted.code, 'code');
expect(casted.state, 'ok');
});
test("onLaunchMiniProgramResponse", () {
var response = BaseWeChatResponse.create("onLaunchMiniProgramResponse",
{"type": 1, "errCode": 1, "errStr": "hehe", "extMsg": "extMsg"});
test('onLaunchMiniProgramResponse', () {
var response = BaseWeChatResponse.create(
'onLaunchMiniProgramResponse',
{'type': 1, 'errCode': 1, 'errStr': 'hehe', 'extMsg': 'extMsg'},
);
expect(response is WeChatLaunchMiniProgramResponse, true);
var casted = response as WeChatLaunchMiniProgramResponse;
expect(casted.type, 1);
expect(casted.errCode, 1);
expect(casted.errStr, "hehe");
expect(casted.extMsg, "extMsg");
expect(casted.errStr, 'hehe');
expect(casted.extMsg, 'extMsg');
});
test("WeChatPaymentResponse", () {
var response = BaseWeChatResponse.create("onPayResponse",
{"type": 1, "errCode": 1, "errStr": "hehe", "extData": "extData"});
test('WeChatPaymentResponse', () {
var response = BaseWeChatResponse.create(
'onPayResponse',
{'type': 1, 'errCode': 1, 'errStr': 'hehe', 'extData': 'extData'},
);
expect(response is WeChatPaymentResponse, true);
var casted = response as WeChatPaymentResponse;
expect(casted.type, 1);
expect(casted.errCode, 1);
expect(casted.errStr, "hehe");
expect(casted.extData, "extData");
expect(casted.errStr, 'hehe');
expect(casted.extData, 'extData');
});
test("WeChatSubscribeMsgResponse", () {
var response = BaseWeChatResponse.create("onSubscribeMsgResp", {
"type": 1,
"errCode": 1,
"errStr": "hehe",
"openid": "425235131",
"templateId": "4252345",
"action": "action",
"reserved": "reserved",
"scene": 1
test('WeChatSubscribeMsgResponse', () {
var response = BaseWeChatResponse.create('onSubscribeMsgResp', {
'type': 1,
'errCode': 1,
'errStr': 'hehe',
'openid': '425235131',
'templateId': '4252345',
'action': 'action',
'reserved': 'reserved',
'scene': 1
});
expect(response is WeChatSubscribeMsgResponse, true);
var casted = response as WeChatSubscribeMsgResponse;
expect(casted.errCode, 1);
expect(casted.errStr, "hehe");
expect(casted.openid, "425235131");
expect(casted.templateId, "4252345");
expect(casted.action, "action");
expect(casted.reserved, "reserved");
expect(casted.errStr, 'hehe');
expect(casted.openid, '425235131');
expect(casted.templateId, '4252345');
expect(casted.action, 'action');
expect(casted.reserved, 'reserved');
expect(casted.scene, 1);
});
test("WeChatAutoDeductResponse", () {
var response = BaseWeChatResponse.create("onAutoDeductResponse", {
"type": 1,
"errCode": 0,
"errStr": "hehe",
"businessType": 2,
"resultInfo": "resultInfo"
test('WeChatAutoDeductResponse', () {
var response = BaseWeChatResponse.create('onAutoDeductResponse', {
'type': 1,
'errCode': 0,
'errStr': 'hehe',
'businessType': 2,
'resultInfo': 'resultInfo'
});
expect(response is WeChatOpenBusinessWebviewResponse, true);
var casted = response as WeChatOpenBusinessWebviewResponse;
assert(casted.isSuccessful);
expect(casted.type, 1);
expect(casted.errCode, 0);
expect(casted.errStr, "hehe");
expect(casted.resultInfo, "resultInfo");
expect(casted.errStr, 'hehe');
expect(casted.resultInfo, 'resultInfo');
expect(casted.businessType, 2);
});
});
......
......@@ -18,35 +18,38 @@
*/
import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/share/share_models.dart';
import 'package:fluwx/src/wechat_enums.dart';
void main() {
test("test create WeChatShareImageModel with thumbnail", () {
var image = WeChatImage.network("http://openflutter.dev/fluwx.png");
var thumbnail = WeChatImage.network("http://openflutter.dev/fluwx.png");
var model = WeChatShareImageModel(image,
scene: WeChatScene.FAVORITE, thumbnail: thumbnail);
test('test create WeChatShareImageModel with thumbnail', () {
var image = WeChatImage.network('http://openflutter.dev/fluwx.png');
var thumbnail = WeChatImage.network('http://openflutter.dev/fluwx.png');
var model = WeChatShareImageModel(
image,
scene: WeChatScene.FAVORITE,
thumbnail: thumbnail,
);
expect(model.source, image);
expect(model.scene, WeChatScene.FAVORITE);
expect(model.thumbnail, thumbnail);
});
test("test create WeChatShareImageModel without thumbnail", () {
var image = WeChatImage.network("http://openflutter.dev/fluwx.png");
test('test create WeChatShareImageModel without thumbnail', () {
var image = WeChatImage.network('http://openflutter.dev/fluwx.png');
var model = WeChatShareImageModel(image, scene: WeChatScene.FAVORITE);
expect(model.source, image);
expect(model.scene, WeChatScene.FAVORITE);
expect(model.thumbnail, image);
});
test("test WeChatShareImageModel toMap", () {
var image = WeChatImage.network("http://openflutter.dev/fluwx.png");
var thumbnail = WeChatImage.network("http://openflutter.dev/fluwx.png");
var map = WeChatShareImageModel(image,
scene: WeChatScene.FAVORITE, thumbnail: thumbnail)
.toMap();
assert(map["thumbnail"] != null);
expect(map["thumbnail"]["source"], "http://openflutter.dev/fluwx.png");
test('test WeChatShareImageModel toMap', () {
var image = WeChatImage.network('http://openflutter.dev/fluwx.png');
var thumbnail = WeChatImage.network('http://openflutter.dev/fluwx.png');
var map = WeChatShareImageModel(
image,
scene: WeChatScene.FAVORITE,
thumbnail: thumbnail,
).toMap();
assert(map['thumbnail'] != null);
expect(map['thumbnail']['source'], 'http://openflutter.dev/fluwx.png');
});
}
......@@ -18,8 +18,6 @@
*/
import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/share/share_models.dart';
import 'package:fluwx/src/wechat_enums.dart';
void main() {
group("construct", () {
......
......@@ -21,15 +21,15 @@ import 'package:fluwx/src/share/share_models.dart';
import 'package:fluwx/src/wechat_enums.dart';
void main() {
test("create WeChatTextModel", () {
var model = WeChatShareTextModel("text", scene: WeChatScene.FAVORITE);
expect(model.source, "text");
test('create WeChatTextModel', () {
var model = WeChatShareTextModel('text', scene: WeChatScene.FAVORITE);
expect(model.source, 'text');
expect(model.scene, WeChatScene.FAVORITE);
});
test("WeChatTextModel toMap", () {
var map = WeChatShareTextModel("text", scene: WeChatScene.FAVORITE).toMap();
expect(map["source"], "text");
expect(map["scene"], 2);
test('WeChatTextModel toMap', () {
var map = WeChatShareTextModel('text', scene: WeChatScene.FAVORITE).toMap();
expect(map['source'], 'text');
expect(map['scene'], 2);
});
}
......@@ -17,30 +17,36 @@
* the License.
*/
import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/wechat_file.dart';
void main() {
test("test WeChatImage.fromNetwork", () {
var withSuffixImage =
WeChatImage.network("http://image.openflutter.dev/fluwx.png");
expect(withSuffixImage.source, "http://image.openflutter.dev/fluwx.png");
expect(withSuffixImage.suffix, ".png");
test('test WeChatImage.fromNetwork', () {
var withSuffixImage = WeChatImage.network(
'http://image.openflutter.dev/fluwx.png',
);
expect(withSuffixImage.source, 'http://image.openflutter.dev/fluwx.png');
expect(withSuffixImage.suffix, '.png');
expect(FileSchema.NETWORK, withSuffixImage.schema);
var withNoSuffixNoUrlSuffixImage =
WeChatImage.network("http://image.openflutter.dev/fluwx");
expect("http://image.openflutter.dev/fluwx",
withNoSuffixNoUrlSuffixImage.source);
expect(withNoSuffixNoUrlSuffixImage.suffix, ".jpeg");
var withNoSuffixNoUrlSuffixImage = WeChatImage.network(
'http://image.openflutter.dev/fluwx',
);
expect(
'http://image.openflutter.dev/fluwx',
withNoSuffixNoUrlSuffixImage.source,
);
expect(withNoSuffixNoUrlSuffixImage.suffix, '.jpeg');
expect(FileSchema.NETWORK, withSuffixImage.schema);
var withSpecifiedSuffixImage = WeChatImage.network(
"http://image.openflutter.dev/fluwx.jpeg",
suffix: ".png");
expect(withSpecifiedSuffixImage.source, "http://image.openflutter.dev/fluwx.jpeg");
expect(withSpecifiedSuffixImage.suffix, ".png");
'http://image.openflutter.dev/fluwx.jpeg',
suffix: '.png',
);
expect(
withSpecifiedSuffixImage.source,
'http://image.openflutter.dev/fluwx.jpeg',
);
expect(withSpecifiedSuffixImage.suffix, '.png');
expect(withSpecifiedSuffixImage.schema, FileSchema.NETWORK);
});
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论