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

🎨 Clean dart code formats

上级 07e02e08
...@@ -186,7 +186,7 @@ ...@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier same "printed page" as the copyright notice for easier
identification within third-party archives. identification within third-party archives.
Copyright [yyyy] [name of copyright owner] Copyright [2020] [OpenFlutter]
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
......
差异被折叠。
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
class AuthByQRCodePage extends StatefulWidget { class AuthByQRCodePage extends StatefulWidget {
const AuthByQRCodePage({Key? key}) : super(key: key);
@override @override
_AuthByQRCodePageState createState() => _AuthByQRCodePageState(); _AuthByQRCodePageState createState() => _AuthByQRCodePageState();
} }
class _AuthByQRCodePageState extends State<AuthByQRCodePage> { class _AuthByQRCodePageState extends State<AuthByQRCodePage> {
String _status = "status"; String _status = 'status';
Uint8List? _image; Uint8List? _image;
@override @override
...@@ -18,7 +19,7 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> { ...@@ -18,7 +19,7 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> {
// fluwx.onAuthByQRCodeFinished.listen((data) { // fluwx.onAuthByQRCodeFinished.listen((data) {
// setState(() { // setState(() {
// _status = "errorCode=>${data.errorCode}\nauthCode=>${data.authCode}"; // _status = 'errorCode=>${data.errorCode}\nauthCode=>${data.authCode}';
// }); // });
// }); // });
// fluwx.onAuthGotQRCode.listen((image) { // fluwx.onAuthGotQRCode.listen((image) {
...@@ -29,7 +30,7 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> { ...@@ -29,7 +30,7 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> {
// //
// fluwx.onQRCodeScanned.listen((scanned) { // fluwx.onQRCodeScanned.listen((scanned) {
// setState(() { // setState(() {
// _status = "scanned"; // _status = 'scanned';
// }); // });
// }); // });
} }
...@@ -38,20 +39,20 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> { ...@@ -38,20 +39,20 @@ class _AuthByQRCodePageState extends State<AuthByQRCodePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("AuthByQRCode"), title: Text('AuthByQRCode'),
), ),
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
RaisedButton( ElevatedButton(
onPressed: () { onPressed: () {
// fluwx.authByQRCode( // fluwx.authByQRCode(
// appId: "wxd930ea5d5a258f4f", // appId: 'wxd930ea5d5a258f4f',
// scope: "noncestr", // scope: 'noncestr',
// nonceStr: "nonceStr", // nonceStr: 'nonceStr',
// timeStamp: "1417508194", // timeStamp: '1417508194',
// signature: "429eaaa13fd71efbc3fd344d0a9a9126835e7303"); // signature: '429eaaa13fd71efbc3fd344d0a9a9126835e7303');
}, },
child: Text("AUTH NOW"), child: Text('AUTH NOW'),
), ),
Text(_status), Text(_status),
_qrCode() _qrCode()
......
...@@ -2,12 +2,14 @@ import 'package:flutter/material.dart'; ...@@ -2,12 +2,14 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
class LaunchMiniProgramPage extends StatefulWidget { class LaunchMiniProgramPage extends StatefulWidget {
const LaunchMiniProgramPage({Key? key}) : super(key: key);
@override @override
_LaunchMiniProgramPageState createState() => _LaunchMiniProgramPageState(); _LaunchMiniProgramPageState createState() => _LaunchMiniProgramPageState();
} }
class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> { class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> {
String? _result = "无"; String? _result = '无';
@override @override
void initState() { void initState() {
...@@ -16,7 +18,7 @@ class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> { ...@@ -16,7 +18,7 @@ class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> {
if (res is WeChatLaunchMiniProgramResponse) { if (res is WeChatLaunchMiniProgramResponse) {
if (mounted) { if (mounted) {
setState(() { setState(() {
_result = "isSuccessful:${res.isSuccessful}"; _result = 'isSuccessful:${res.isSuccessful}';
}); });
} }
} }
...@@ -33,18 +35,18 @@ class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> { ...@@ -33,18 +35,18 @@ class _LaunchMiniProgramPageState extends State<LaunchMiniProgramPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("Launch MiniProgrom"), title: const Text('Launch MiniProgrom'),
), ),
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
OutlineButton( OutlinedButton(
onPressed: () { onPressed: () {
launchWeChatMiniProgram(username: "gh_d43f693ca31f"); launchWeChatMiniProgram(username: 'gh_d43f693ca31f');
}, },
child: const Text("Launch MiniProgrom"), child: const Text('Launch MiniProgrom'),
), ),
const Text("响应结果;"), const Text('响应结果;'),
Text("$_result") Text('$_result')
], ],
), ),
); );
......
...@@ -5,14 +5,15 @@ import 'package:flutter/material.dart'; ...@@ -5,14 +5,15 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx; import 'package:fluwx/fluwx.dart' as fluwx;
class PayPage extends StatefulWidget { class PayPage extends StatefulWidget {
const PayPage({Key? key}) : super(key: key);
@override @override
_PayPageState createState() => _PayPageState(); _PayPageState createState() => _PayPageState();
} }
class _PayPageState extends State<PayPage> { class _PayPageState extends State<PayPage> {
String _url = "https://wxpay.wxutil.com/pub_v2/app/app_pay.php"; String _url = 'https://wxpay.wxutil.com/pub_v2/app/app_pay.php';
String _result = '无';
String _result = "无";
@override @override
void initState() { void initState() {
...@@ -20,13 +21,13 @@ class _PayPageState extends State<PayPage> { ...@@ -20,13 +21,13 @@ class _PayPageState extends State<PayPage> {
fluwx.weChatResponseEventHandler.listen((res) { fluwx.weChatResponseEventHandler.listen((res) {
if (res is fluwx.WeChatPaymentResponse) { if (res is fluwx.WeChatPaymentResponse) {
setState(() { setState(() {
_result = "pay :${res.isSuccessful}"; _result = 'pay :${res.isSuccessful}';
}); });
} }
}); });
// fluwx.responseFromPayment.listen((data) { // fluwx.responseFromPayment.listen((data) {
// setState(() { // setState(() {
// _result = "${data.errCode}"; // _result = '${data.errCode}';
// }); // });
// }); // });
} }
...@@ -34,12 +35,10 @@ class _PayPageState extends State<PayPage> { ...@@ -34,12 +35,10 @@ class _PayPageState extends State<PayPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: const Text('pay')),
title: const Text("pay"),
),
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
OutlineButton( OutlinedButton(
onPressed: () async { onPressed: () async {
var h = H.HttpClient(); var h = H.HttpClient();
h.badCertificateCallback = (cert, String host, int port) { h.badCertificateCallback = (cert, String host, int port) {
...@@ -50,7 +49,7 @@ class _PayPageState extends State<PayPage> { ...@@ -50,7 +49,7 @@ class _PayPageState extends State<PayPage> {
var data = await Utf8Decoder().bind(response).join(); var data = await Utf8Decoder().bind(response).join();
Map<String, dynamic> result = json.decode(data); Map<String, dynamic> result = json.decode(data);
print(result['appid']); print(result['appid']);
print(result["timestamp"]); print(result['timestamp']);
fluwx fluwx
.payWithWeChat( .payWithWeChat(
appId: result['appid'].toString(), appId: result['appid'].toString(),
...@@ -62,12 +61,12 @@ class _PayPageState extends State<PayPage> { ...@@ -62,12 +61,12 @@ class _PayPageState extends State<PayPage> {
sign: result['sign'].toString(), sign: result['sign'].toString(),
) )
.then((data) { .then((data) {
print("---》$data"); print('---》$data');
}); });
}, },
child: const Text("pay"), child: const Text('pay'),
), ),
const Text("响应结果;"), const Text('响应结果;'),
Text(_result) Text(_result)
], ],
), ),
......
...@@ -2,12 +2,14 @@ import 'package:flutter/material.dart'; ...@@ -2,12 +2,14 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx; import 'package:fluwx/fluwx.dart' as fluwx;
class SendAuthPage extends StatefulWidget { class SendAuthPage extends StatefulWidget {
const SendAuthPage({Key? key}) : super(key: key);
@override @override
_SendAuthPageState createState() => _SendAuthPageState(); _SendAuthPageState createState() => _SendAuthPageState();
} }
class _SendAuthPageState extends State<SendAuthPage> { class _SendAuthPageState extends State<SendAuthPage> {
String? _result = "无"; String? _result = '无';
@override @override
void initState() { void initState() {
...@@ -15,7 +17,7 @@ class _SendAuthPageState extends State<SendAuthPage> { ...@@ -15,7 +17,7 @@ class _SendAuthPageState extends State<SendAuthPage> {
fluwx.weChatResponseEventHandler.distinct((a, b) => a == b).listen((res) { fluwx.weChatResponseEventHandler.distinct((a, b) => a == b).listen((res) {
if (res is fluwx.WeChatAuthResponse) { if (res is fluwx.WeChatAuthResponse) {
setState(() { 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> { ...@@ -30,22 +32,22 @@ class _SendAuthPageState extends State<SendAuthPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(title: const Text('Send Auth')),
title: const Text("Send Auth"),
),
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
OutlineButton( OutlinedButton(
onPressed: () { onPressed: () {
fluwx fluwx
.sendWeChatAuth( .sendWeChatAuth(
scope: "snsapi_userinfo", state: "wechat_sdk_demo_test") scope: 'snsapi_userinfo',
state: 'wechat_sdk_demo_test',
)
.then((data) {}); .then((data) {});
}, },
child: const Text("send auth"), child: const Text('send auth'),
), ),
const Text("响应结果;"), const Text('响应结果;'),
Text("$_result") Text('$_result')
], ],
), ),
); );
......
...@@ -2,17 +2,15 @@ import 'package:flutter/material.dart'; ...@@ -2,17 +2,15 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
class ShareImagePage extends StatefulWidget { class ShareImagePage extends StatefulWidget {
const ShareImagePage({Key? key}) : super(key: key);
@override @override
_ShareImagePageState createState() => _ShareImagePageState(); _ShareImagePageState createState() => _ShareImagePageState();
} }
class _ShareImagePageState extends State<ShareImagePage> { class _ShareImagePageState extends State<ShareImagePage> {
WeChatScene scene = WeChatScene.SESSION; WeChatScene scene = WeChatScene.SESSION;
String _imagePath = String _response = '';
// "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 = "";
WeChatImage? source; WeChatImage? source;
WeChatImage? thumbnail; WeChatImage? thumbnail;
...@@ -23,7 +21,7 @@ class _ShareImagePageState extends State<ShareImagePage> { ...@@ -23,7 +21,7 @@ class _ShareImagePageState extends State<ShareImagePage> {
weChatResponseEventHandler.listen((res) { weChatResponseEventHandler.listen((res) {
if (res is WeChatShareResponse) { if (res is WeChatShareResponse) {
setState(() { setState(() {
_response = "state :${res.isSuccessful}"; _response = 'state :${res.isSuccessful}';
}); });
} }
}); });
...@@ -31,16 +29,14 @@ class _ShareImagePageState extends State<ShareImagePage> { ...@@ -31,16 +29,14 @@ class _ShareImagePageState extends State<ShareImagePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("shareImage"), title: const Text('shareImage'),
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.share, color: Colors.white),
Icons.share, onPressed: _shareImage,
color: Colors.white, ),
),
onPressed: _shareImage)
], ],
), ),
body: Padding( body: Padding(
...@@ -48,56 +44,66 @@ class _ShareImagePageState extends State<ShareImagePage> { ...@@ -48,56 +44,66 @@ class _ShareImagePageState extends State<ShareImagePage> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
TextField( TextField(
decoration: InputDecoration(labelText: "图片地址(仅限网络)"), decoration: InputDecoration(labelText: '图片地址(仅限网络)'),
controller: TextEditingController( controller: TextEditingController(
text: text: 'https://timgsa.baidu.com/timg'
"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"), '?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) { onChanged: (value) {
source = WeChatImage.network(value); source = WeChatImage.network(value);
}, },
keyboardType: TextInputType.multiline, keyboardType: TextInputType.multiline,
), ),
TextField( TextField(
decoration: InputDecoration(labelText: "缩略地址"), decoration: InputDecoration(labelText: '缩略地址'),
controller: TextEditingController(text: "//images/logo.png"), controller: TextEditingController(text: '//images/logo.png'),
onChanged: (value) { onChanged: (value) {
thumbnail = WeChatImage.asset(value); thumbnail = WeChatImage.asset(value);
}, },
), ),
new Row( Row(
children: <Widget>[ children: <Widget>[
const Text("分享至"), const Text('分享至'),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.SESSION, value: WeChatScene.SESSION,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("会话") ),
const Text('会话')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.TIMELINE, value: WeChatScene.TIMELINE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("朋友圈") ),
const Text('朋友圈')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.FAVORITE, value: WeChatScene.FAVORITE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("收藏") ),
const Text('收藏')
], ],
) )
], ],
......
...@@ -8,78 +8,77 @@ class ShareMiniProgramPage extends StatefulWidget { ...@@ -8,78 +8,77 @@ class ShareMiniProgramPage extends StatefulWidget {
class _ShareMiniProgramPageState extends State<ShareMiniProgramPage> { class _ShareMiniProgramPageState extends State<ShareMiniProgramPage> {
WeChatScene scene = WeChatScene.SESSION; WeChatScene scene = WeChatScene.SESSION;
String _webPageUrl = "http://www.qq.com"; String _webPageUrl = 'http://www.qq.com';
String _thumbnail = String _thumbnail = 'https://timgsa.baidu.com/timg'
"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"; '?image'
String _title = "Fluwx"; '&quality=80'
String _userName = "gh_d43f693ca31f"; '&size=b9999_10000'
String _path = "/pages/media"; '&sec=1534614311230'
String _description = "Fluwx"; '&di=b17a892b366b5d002f52abcce7c4eea0'
'&imgtype=0'
@override '&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png';
void initState() { String _title = 'Fluwx';
super.initState(); String _userName = 'gh_d43f693ca31f';
} String _path = '/pages/media';
String _description = 'Fluwx';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("ShareMiniProgram"), title: const Text('ShareMiniProgram'),
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.share, color: Colors.white),
Icons.share, onPressed: _share,
color: Colors.white, ),
),
onPressed: _share)
], ],
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: new ListView( child: ListView(
children: <Widget>[ children: <Widget>[
new TextField( TextField(
controller: TextEditingController(text: "http://www.qq.com"), controller: TextEditingController(text: 'http://www.qq.com'),
onChanged: (str) { onChanged: (str) {
_webPageUrl = str; _webPageUrl = str;
}, },
decoration: InputDecoration(labelText: "web page url"), decoration: InputDecoration(labelText: 'web page url'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "gh_d43f693ca31f"), controller: TextEditingController(text: 'gh_d43f693ca31f'),
onChanged: (str) { onChanged: (str) {
_userName = str; _userName = str;
}, },
decoration: InputDecoration(labelText: "user name"), decoration: InputDecoration(labelText: 'user name'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "/pages/media"), controller: TextEditingController(text: '/pages/media'),
onChanged: (str) { onChanged: (str) {
_path = str; _path = str;
}, },
decoration: InputDecoration(labelText: "user name"), decoration: InputDecoration(labelText: 'user name'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "Fluwx"), controller: TextEditingController(text: 'Fluwx'),
onChanged: (str) { onChanged: (str) {
_title = str; _title = str;
}, },
decoration: InputDecoration(labelText: "title"), decoration: InputDecoration(labelText: 'title'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "Fluwx"), controller: TextEditingController(text: 'Fluwx'),
onChanged: (str) { onChanged: (str) {
_description = str; _description = str;
}, },
decoration: InputDecoration(labelText: "description"), decoration: InputDecoration(labelText: 'description'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "images/logo.png"), controller: TextEditingController(text: 'images/logo.png'),
onChanged: (str) { onChanged: (str) {
_thumbnail = str; _thumbnail = str;
}, },
decoration: InputDecoration(labelText: "thumbnail"), decoration: InputDecoration(labelText: 'thumbnail'),
), ),
], ],
), ),
...@@ -88,13 +87,14 @@ class _ShareMiniProgramPageState extends State<ShareMiniProgramPage> { ...@@ -88,13 +87,14 @@ class _ShareMiniProgramPageState extends State<ShareMiniProgramPage> {
} }
void _share() { void _share() {
var model = new WeChatShareMiniProgramModel( var model = WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl, webPageUrl: _webPageUrl,
userName: _userName, userName: _userName,
title: _title, title: _title,
path: _path, path: _path,
description: _description, description: _description,
thumbnail: WeChatImage.network(_thumbnail)); thumbnail: WeChatImage.network(_thumbnail),
);
shareToWeChat(model); shareToWeChat(model);
} }
} }
...@@ -2,118 +2,118 @@ import 'package:flutter/material.dart'; ...@@ -2,118 +2,118 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
class ShareMusicPage extends StatefulWidget { class ShareMusicPage extends StatefulWidget {
const ShareMusicPage({Key? key}) : super(key: key);
@override @override
_ShareMusicPageState createState() => _ShareMusicPageState(); _ShareMusicPageState createState() => _ShareMusicPageState();
} }
class _ShareMusicPageState extends State<ShareMusicPage> { class _ShareMusicPageState extends State<ShareMusicPage> {
String _musicUrl = String _musicUrl =
"http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3"; 'http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3';
String _musicLowBandUrl = "http://www.qq.com"; String _musicLowBandUrl = 'http://www.qq.com';
String _title = "Beyond"; String _title = 'Beyond';
String _description = "A Popular Rock Band From China"; String _description = 'A Popular Rock Band From China';
String _thumnail = "images/logo.png"; String _thumnail = 'images/logo.png';
WeChatScene scene = WeChatScene.SESSION; WeChatScene scene = WeChatScene.SESSION;
@override
void initState() {
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("ShareMusicPage"), title: const Text('ShareMusicPage'),
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.share, color: Colors.white),
Icons.share, onPressed: _share,
color: Colors.white, ),
),
onPressed: _share)
], ],
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: new Column( child: Column(
children: <Widget>[ children: <Widget>[
new TextField( TextField(
controller: TextEditingController( controller: TextEditingController(
text: text: 'http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/'
"http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3"), '0042515_05.ANDY.mp3',
),
onChanged: (str) { onChanged: (str) {
_musicUrl = str; _musicUrl = str;
}, },
decoration: InputDecoration(labelText: "music url"), decoration: InputDecoration(labelText: 'music url'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "http://www.qq.com"), controller: TextEditingController(text: 'http://www.qq.com'),
onChanged: (str) { onChanged: (str) {
_musicLowBandUrl = str; _musicLowBandUrl = str;
}, },
decoration: InputDecoration(labelText: "music low band url"), decoration: InputDecoration(labelText: 'music low band url'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "Beyond"), controller: TextEditingController(text: 'Beyond'),
onChanged: (str) { onChanged: (str) {
_title = str; _title = str;
}, },
decoration: InputDecoration(labelText: "title"), decoration: InputDecoration(labelText: 'title'),
), ),
new TextField( TextField(
controller: controller: TextEditingController(
TextEditingController(text: "A Popular Rock Band From China"), text: 'A Popular Rock Band From China',
),
onChanged: (str) { onChanged: (str) {
_description = str; _description = str;
}, },
decoration: InputDecoration(labelText: "description"), decoration: InputDecoration(labelText: 'description'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "images/logo.png"), controller: TextEditingController(text: 'images/logo.png'),
onChanged: (str) { onChanged: (str) {
_thumnail = str; _thumnail = str;
}, },
decoration: InputDecoration(labelText: "thumbnail"), decoration: InputDecoration(labelText: 'thumbnail'),
), ),
new Row( Row(
children: <Widget>[ children: <Widget>[
const Text("分享至"), const Text('分享至'),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.SESSION, value: WeChatScene.SESSION,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("会话") ),
const Text('会话')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.TIMELINE, value: WeChatScene.TIMELINE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("朋友圈") ),
const Text('朋友圈')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.FAVORITE, value: WeChatScene.FAVORITE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("收藏") ),
const Text('收藏')
], ],
) ),
], ],
) ),
], ],
), ),
), ),
...@@ -122,12 +122,13 @@ class _ShareMusicPageState extends State<ShareMusicPage> { ...@@ -122,12 +122,13 @@ class _ShareMusicPageState extends State<ShareMusicPage> {
void _share() { void _share() {
var model = WeChatShareMusicModel( var model = WeChatShareMusicModel(
title: _title, title: _title,
description: _description, description: _description,
musicUrl: _musicUrl, musicUrl: _musicUrl,
scene: scene, scene: scene,
musicLowBandUrl: _musicLowBandUrl, musicLowBandUrl: _musicLowBandUrl,
thumbnail: WeChatImage.network(_thumnail)); thumbnail: WeChatImage.network(_thumnail),
);
shareToWeChat(model); shareToWeChat(model);
} }
......
...@@ -7,77 +7,73 @@ class ShareTextPage extends StatefulWidget { ...@@ -7,77 +7,73 @@ class ShareTextPage extends StatefulWidget {
} }
class _ShareTextPageState extends State<ShareTextPage> { class _ShareTextPageState extends State<ShareTextPage> {
String _text = "share text from fluwx"; String _text = 'share text from fluwx';
WeChatScene scene = WeChatScene.SESSION; WeChatScene scene = WeChatScene.SESSION;
@override
void initState() {
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("ShareText"), title: const Text('ShareText'),
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.share, color: Colors.white),
Icons.share, onPressed: _shareText,
color: Colors.white, ),
),
onPressed: _shareText)
], ],
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: new Column( child: Column(
children: <Widget>[ children: <Widget>[
new TextField( TextField(
controller: TextEditingController(text: "share text from fluwx"), controller: TextEditingController(text: 'share text from fluwx'),
onChanged: (str) { onChanged: (str) {
_text = str; _text = str;
}, },
decoration: InputDecoration(labelText: "TextToShare"), decoration: InputDecoration(labelText: 'TextToShare'),
), ),
new Row( Row(
children: <Widget>[ children: <Widget>[
const Text("分享至"), const Text('分享至'),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.SESSION, value: WeChatScene.SESSION,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("会话") ),
const Text('会话')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.TIMELINE, value: WeChatScene.TIMELINE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("朋友圈") ),
const Text('朋友圈')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.FAVORITE, value: WeChatScene.FAVORITE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("收藏") ),
const Text('收藏')
], ],
) ),
], ],
) ),
], ],
), ),
), ),
...@@ -86,10 +82,8 @@ class _ShareTextPageState extends State<ShareTextPage> { ...@@ -86,10 +82,8 @@ class _ShareTextPageState extends State<ShareTextPage> {
void _shareText() { void _shareText() {
shareToWeChat(WeChatShareTextModel(_text, scene: scene)).then((data) { 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) { void handleRadioValueChanged(WeChatScene scene) {
......
...@@ -2,117 +2,116 @@ import 'package:flutter/material.dart'; ...@@ -2,117 +2,116 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
class ShareVideoPage extends StatefulWidget { class ShareVideoPage extends StatefulWidget {
const ShareVideoPage({Key? key}) : super(key: key);
@override @override
_ShareMusicPageState createState() => _ShareMusicPageState(); _ShareMusicPageState createState() => _ShareMusicPageState();
} }
class _ShareMusicPageState extends State<ShareVideoPage> { class _ShareMusicPageState extends State<ShareVideoPage> {
String _videoUrl = "http://www.qq.com"; String _videoUrl = 'http://www.qq.com';
String _videoLowBandUrl = "http://www.qq.com"; String _videoLowBandUrl = 'http://www.qq.com';
String _title = "Beyond"; String _title = 'Beyond';
String _description = "A Popular Rock Band From China"; String _description = 'A Popular Rock Band From China';
String _thumnail = "images/logo.png"; String _thumnail = 'images/logo.png';
WeChatScene scene = WeChatScene.SESSION; WeChatScene scene = WeChatScene.SESSION;
@override
void initState() {
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("ShareVideoPage"), title: const Text('ShareVideoPage'),
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.share, color: Colors.white),
Icons.share, onPressed: _share,
color: Colors.white, ),
),
onPressed: _share)
], ],
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: new Column( child: Column(
children: <Widget>[ children: <Widget>[
new TextField( TextField(
controller: TextEditingController( controller: TextEditingController(
text: text: 'http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/'
"http://staff2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3"), '0042515_05.ANDY.mp3',
),
onChanged: (str) { onChanged: (str) {
_videoUrl = str; _videoUrl = str;
}, },
decoration: InputDecoration(labelText: "video url"), decoration: InputDecoration(labelText: 'video url'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "http://www.qq.com"), controller: TextEditingController(text: 'http://www.qq.com'),
onChanged: (str) { onChanged: (str) {
_videoLowBandUrl = str; _videoLowBandUrl = str;
}, },
decoration: InputDecoration(labelText: "video low band url"), decoration: InputDecoration(labelText: 'video low band url'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "Beyond"), controller: TextEditingController(text: 'Beyond'),
onChanged: (str) { onChanged: (str) {
_title = str; _title = str;
}, },
decoration: InputDecoration(labelText: "title"), decoration: InputDecoration(labelText: 'title'),
), ),
new TextField( TextField(
controller: controller:
TextEditingController(text: "A Popular Rock Band From China"), TextEditingController(text: 'A Popular Rock Band From China'),
onChanged: (str) { onChanged: (str) {
_description = str; _description = str;
}, },
decoration: InputDecoration(labelText: "description"), decoration: InputDecoration(labelText: 'description'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "images/logo.png"), controller: TextEditingController(text: 'images/logo.png'),
onChanged: (str) { onChanged: (str) {
_thumnail = str; _thumnail = str;
}, },
decoration: InputDecoration(labelText: "thumbnail"), decoration: InputDecoration(labelText: 'thumbnail'),
), ),
new Row( Row(
children: <Widget>[ children: <Widget>[
const Text("分享至"), const Text('分享至'),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.SESSION, value: WeChatScene.SESSION,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("会话") ),
const Text('会话')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.TIMELINE, value: WeChatScene.TIMELINE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("朋友圈") ),
const Text('朋友圈')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.FAVORITE, value: WeChatScene.FAVORITE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("收藏") ),
const Text('收藏')
], ],
) ),
], ],
) ),
], ],
), ),
), ),
...@@ -120,13 +119,14 @@ class _ShareMusicPageState extends State<ShareVideoPage> { ...@@ -120,13 +119,14 @@ class _ShareMusicPageState extends State<ShareVideoPage> {
} }
void _share() { void _share() {
var model = new WeChatShareVideoModel( var model = WeChatShareVideoModel(
videoUrl: _videoUrl, videoUrl: _videoUrl,
videoLowBandUrl: _videoLowBandUrl, videoLowBandUrl: _videoLowBandUrl,
thumbnail: WeChatImage.network(_thumnail), thumbnail: WeChatImage.network(_thumnail),
description: _description, description: _description,
scene: this.scene, scene: this.scene,
title: _title); title: _title,
);
shareToWeChat(model); shareToWeChat(model);
} }
......
...@@ -2,97 +2,94 @@ import 'package:flutter/material.dart'; ...@@ -2,97 +2,94 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
class ShareWebPagePage extends StatefulWidget { class ShareWebPagePage extends StatefulWidget {
const ShareWebPagePage({Key? key}) : super(key: key);
@override @override
ShareWebPagePageState createState() { ShareWebPagePageState createState() => ShareWebPagePageState();
return new ShareWebPagePageState();
}
} }
class ShareWebPagePageState extends State<ShareWebPagePage> { class ShareWebPagePageState extends State<ShareWebPagePage> {
String _url = "share text from fluwx"; String _url = 'share text from fluwx';
String _title = "Fluwx"; String _title = 'Fluwx';
String _thumnail = "images/logo.png"; String _thumnail = 'images/logo.png';
WeChatScene scene = WeChatScene.SESSION; WeChatScene scene = WeChatScene.SESSION;
@override
void initState() {
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("ShareWebPage"), title: const Text('ShareWebPage'),
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.share, color: Colors.white),
Icons.share, onPressed: _share,
color: Colors.white, ),
),
onPressed: _share)
], ],
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: new Column( child: Column(
children: <Widget>[ children: <Widget>[
new TextField( TextField(
controller: TextEditingController( controller: TextEditingController(
text: "https://github.com/JarvanMo/fluwx"), text: 'https://github.com/JarvanMo/fluwx',
),
onChanged: (str) { onChanged: (str) {
_url = str; _url = str;
}, },
decoration: InputDecoration(labelText: "web page"), decoration: InputDecoration(labelText: 'web page'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "Fluwx"), controller: TextEditingController(text: 'Fluwx'),
onChanged: (str) { onChanged: (str) {
_title = str; _title = str;
}, },
decoration: InputDecoration(labelText: "thumbnail"), decoration: InputDecoration(labelText: 'thumbnail'),
), ),
new TextField( TextField(
controller: TextEditingController(text: "images/logo.png"), controller: TextEditingController(text: 'images/logo.png'),
onChanged: (str) { onChanged: (str) {
_thumnail = str; _thumnail = str;
}, },
decoration: InputDecoration(labelText: "thumbnail"), decoration: InputDecoration(labelText: 'thumbnail'),
), ),
new Row( Row(
children: <Widget>[ children: <Widget>[
const Text("分享至"), const Text('分享至'),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.SESSION, value: WeChatScene.SESSION,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("会话") ),
const Text('会话')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.TIMELINE, value: WeChatScene.TIMELINE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("朋友圈") ),
const Text('朋友圈')
], ],
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
new Radio<WeChatScene>( Radio<WeChatScene>(
value: WeChatScene.FAVORITE, value: WeChatScene.FAVORITE,
groupValue: scene, groupValue: scene,
onChanged: (v) { onChanged: (v) {
if (v != null) handleRadioValueChanged(v); if (v != null) handleRadioValueChanged(v);
}), },
const Text("收藏") ),
const Text('收藏')
], ],
) )
], ],
......
...@@ -3,6 +3,8 @@ import 'package:flutter/material.dart'; ...@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
class SignAutoDeductPage extends StatefulWidget { class SignAutoDeductPage extends StatefulWidget {
const SignAutoDeductPage({Key? key}) : super(key: key);
@override @override
_SignAutoDeductPageState createState() => _SignAutoDeductPageState(); _SignAutoDeductPageState createState() => _SignAutoDeductPageState();
} }
...@@ -10,24 +12,24 @@ class SignAutoDeductPage extends StatefulWidget { ...@@ -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) /// see wechat [document](https://pay.weixin.qq.com/wiki/doc/api/pap.php?chapter=18_5&index=2)
class _SignAutoDeductPageState extends State<SignAutoDeductPage> { class _SignAutoDeductPageState extends State<SignAutoDeductPage> {
TextEditingController appId = TextEditingController appId =
TextEditingController(text: "wx316f9c82e99ac105"); TextEditingController(text: 'wx316f9c82e99ac105');
TextEditingController mchId = TextEditingController(text: ""); TextEditingController mchId = TextEditingController(text: '');
TextEditingController planId = TextEditingController(text: ""); TextEditingController planId = TextEditingController(text: '');
TextEditingController contractCode = TextEditingController(text: ""); TextEditingController contractCode = TextEditingController(text: '');
TextEditingController requestSerial = TextEditingController(text: ""); TextEditingController requestSerial = TextEditingController(text: '');
TextEditingController contractDisplayAccount = TextEditingController contractDisplayAccount =
TextEditingController(text: ""); TextEditingController(text: '');
TextEditingController notifyUrl = TextEditingController(text: ""); TextEditingController notifyUrl = TextEditingController(text: '');
TextEditingController version = TextEditingController(text: "1.0"); TextEditingController version = TextEditingController(text: '1.0');
TextEditingController sign = TextEditingController(text: ""); TextEditingController sign = TextEditingController(text: '');
TextEditingController timestamp = TextEditingController(text: ""); TextEditingController timestamp = TextEditingController(text: '');
TextEditingController returnApp = TextEditingController(text: "3"); TextEditingController returnApp = TextEditingController(text: '3');
@override @override
void initState() { void initState() {
super.initState(); super.initState();
weChatResponseEventHandler.listen((resp) { weChatResponseEventHandler.listen((resp) {
print("resp = ${resp.isSuccessful}"); print('resp = ${resp.isSuccessful}');
}); });
} }
...@@ -57,21 +59,50 @@ class _SignAutoDeductPageState extends State<SignAutoDeductPage> { ...@@ -57,21 +59,50 @@ class _SignAutoDeductPageState extends State<SignAutoDeductPage> {
body: Container( body: Container(
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
_buildTextField(title: "appId", textEditController: appId),
_buildTextField(title: "mchId", textEditController: mchId),
_buildTextField(title: "planId", textEditController: planId),
_buildTextField( _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( _buildTextField(
title: "requestSerial", textEditController: requestSerial), title: 'version',
textEditController: version,
),
_buildTextField(
title: 'sign',
textEditController: sign,
),
_buildTextField( _buildTextField(
title: "contractDisplayAccount", title: 'timestamp',
textEditController: contractDisplayAccount), textEditController: timestamp,
_buildTextField(title: "notifyUrl", textEditController: notifyUrl), ),
_buildTextField(title: "version", textEditController: version), _buildTextField(
_buildTextField(title: "sign", textEditController: sign), title: 'returnApp',
_buildTextField(title: "timestamp", textEditController: timestamp), textEditController: returnApp,
_buildTextField(title: "returnApp", textEditController: returnApp), ),
CupertinoButton( CupertinoButton(
child: Text('request once sign auto-deduct message'), child: Text('request once sign auto-deduct message'),
onPressed: _signAutoDeduct, onPressed: _signAutoDeduct,
...@@ -87,25 +118,24 @@ class _SignAutoDeductPageState extends State<SignAutoDeductPage> { ...@@ -87,25 +118,24 @@ class _SignAutoDeductPageState extends State<SignAutoDeductPage> {
TextEditingController? textEditController, TextEditingController? textEditController,
}) { }) {
return TextField( return TextField(
decoration: InputDecoration( decoration: InputDecoration(labelText: title),
labelText: title,
),
controller: textEditController, controller: textEditController,
); );
} }
void _signAutoDeduct() { void _signAutoDeduct() {
autoDeDuctWeChat( autoDeDuctWeChat(
appId: appId.text , appId: appId.text,
mchId: mchId.text, mchId: mchId.text,
planId: planId.text , planId: planId.text,
contractCode: contractCode.text, contractCode: contractCode.text,
requestSerial: requestSerial.text, requestSerial: requestSerial.text,
contractDisplayAccount: contractDisplayAccount.text, contractDisplayAccount: contractDisplayAccount.text,
notifyUrl: notifyUrl.text, notifyUrl: notifyUrl.text,
version: version.text, version: version.text,
sign: sign.text, sign: sign.text,
timestamp: timestamp.text, timestamp: timestamp.text,
returnApp: '3'); returnApp: '3',
);
} }
} }
...@@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; ...@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
class SubscribeMessagePage extends StatefulWidget { class SubscribeMessagePage extends StatefulWidget {
const SubscribeMessagePage({Key? key}) : super(key: key);
@override @override
_SubscribeMessagePageState createState() => _SubscribeMessagePageState(); _SubscribeMessagePageState createState() => _SubscribeMessagePageState();
} }
...@@ -9,17 +11,17 @@ class SubscribeMessagePage extends StatefulWidget { ...@@ -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) /// 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> { class _SubscribeMessagePageState extends State<SubscribeMessagePage> {
TextEditingController appId = TextEditingController appId =
TextEditingController(text: "wx316f9c82e99ac105"); TextEditingController(text: 'wx316f9c82e99ac105');
TextEditingController scene = TextEditingController(text: "1"); TextEditingController scene = TextEditingController(text: '1');
TextEditingController templateId = TextEditingController( TextEditingController templateId = TextEditingController(
text: "cm_vM2k3IjHcYbkGUeAfL6Fja_7Pgv4Hx_q4tA253Ss"); text: 'cm_vM2k3IjHcYbkGUeAfL6Fja_7Pgv4Hx_q4tA253Ss');
TextEditingController reserved = TextEditingController(text: "123"); TextEditingController reserved = TextEditingController(text: '123');
@override @override
void initState() { void initState() {
super.initState(); super.initState();
weChatResponseEventHandler.listen((resp) { weChatResponseEventHandler.listen((resp) {
print("resp = $resp"); print('resp = $resp');
}); });
} }
...@@ -41,12 +43,23 @@ class _SubscribeMessagePageState extends State<SubscribeMessagePage> { ...@@ -41,12 +43,23 @@ class _SubscribeMessagePageState extends State<SubscribeMessagePage> {
body: Container( body: Container(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
_buildTextField(title: "appId", textEditController: appId),
_buildTextField(title: "scene", textEditController: scene),
_buildTextField( _buildTextField(
title: "templateId", textEditController: templateId), title: 'appId',
_buildTextField(title: "reserved", textEditController: reserved), textEditController: appId,
FlatButton( ),
_buildTextField(
title: 'scene',
textEditController: scene,
),
_buildTextField(
title: 'templateId',
textEditController: templateId,
),
_buildTextField(
title: 'reserved',
textEditController: reserved,
),
TextButton(
child: Text('request once subscribe message'), child: Text('request once subscribe message'),
onPressed: _requestSubMsg, onPressed: _requestSubMsg,
), ),
...@@ -61,9 +74,7 @@ class _SubscribeMessagePageState extends State<SubscribeMessagePage> { ...@@ -61,9 +74,7 @@ class _SubscribeMessagePageState extends State<SubscribeMessagePage> {
TextEditingController? textEditController, TextEditingController? textEditController,
}) { }) {
return TextField( return TextField(
decoration: InputDecoration( decoration: InputDecoration(labelText: title),
labelText: title,
),
controller: textEditController, controller: textEditController,
); );
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
// gestures. You can also use WidgetTester to find child widgets in the widget // 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. // 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:flutter_test/flutter_test.dart';
import 'package:fluwx_example/main.dart'; import 'package:fluwx_example/main.dart';
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
/// A open sou;rce project authorized by [OpenFlutter](https://github.com/OpenFlutter). /// A open sou;rce project authorized by [OpenFlutter](https://github.com/OpenFlutter).
library fluwx; library fluwx;
export 'package:fluwx/src/fluwx_iml.dart'; export 'src/fluwx_iml.dart';
export 'package:fluwx/src/response/wechat_response.dart'; export 'src/response/wechat_response.dart';
export 'package:fluwx/src/share/share_models.dart'; export 'src/share/share_models.dart';
export 'package:fluwx/src/wechat_enums.dart'; export 'src/wechat_enums.dart';
export 'package:fluwx/src/wechat_file.dart' hide FileSchema; export 'src/wechat_file.dart' hide FileSchema;
差异被折叠。
...@@ -19,42 +19,37 @@ ...@@ -19,42 +19,37 @@
import 'dart:typed_data'; import 'dart:typed_data';
const String _errCode = "errCode"; const String _errCode = 'errCode';
const String _errStr = "errStr"; const String _errStr = 'errStr';
typedef BaseWeChatResponse _WeChatResponseInvoker(Map argument); typedef BaseWeChatResponse _WeChatResponseInvoker(Map argument);
Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = { Map<String, _WeChatResponseInvoker> _nameAndResponseMapper = {
"onShareResponse": (Map argument) => WeChatShareResponse.fromMap(argument), 'onShareResponse': (Map argument) => WeChatShareResponse.fromMap(argument),
"onAuthResponse": (Map argument) => WeChatAuthResponse.fromMap(argument), 'onAuthResponse': (Map argument) => WeChatAuthResponse.fromMap(argument),
"onLaunchMiniProgramResponse": (Map argument) => 'onLaunchMiniProgramResponse': (Map argument) =>
WeChatLaunchMiniProgramResponse.fromMap(argument), WeChatLaunchMiniProgramResponse.fromMap(argument),
"onPayResponse": (Map argument) => WeChatPaymentResponse.fromMap(argument), 'onPayResponse': (Map argument) => WeChatPaymentResponse.fromMap(argument),
"onSubscribeMsgResp": (Map argument) => 'onSubscribeMsgResp': (Map argument) =>
WeChatSubscribeMsgResponse.fromMap(argument), WeChatSubscribeMsgResponse.fromMap(argument),
"onWXOpenBusinessWebviewResponse": (Map argument) => 'onWXOpenBusinessWebviewResponse': (Map argument) =>
WeChatOpenBusinessWebviewResponse.fromMap(argument), WeChatOpenBusinessWebviewResponse.fromMap(argument),
"onAuthByQRCodeFinished": (Map argument) => 'onAuthByQRCodeFinished': (Map argument) =>
WeChatAuthByQRCodeFinishedResponse.fromMap(argument), WeChatAuthByQRCodeFinishedResponse.fromMap(argument),
"onAuthGotQRCode": (Map argument) => 'onAuthGotQRCode': (Map argument) =>
WeChatAuthGotQRCodeResponse.fromMap(argument), WeChatAuthGotQRCodeResponse.fromMap(argument),
"onQRCodeScanned": (Map argument) => 'onQRCodeScanned': (Map argument) =>
WeChatQRCodeScannedResponse.fromMap(argument), WeChatQRCodeScannedResponse.fromMap(argument),
"onWXShowMessageFromWX": (Map argument) => 'onWXShowMessageFromWX': (Map argument) =>
WeChatShowMessageFromWXRequest.fromMap(argument), WeChatShowMessageFromWXRequest.fromMap(argument),
"onWXOpenCustomerServiceChatResponse": (Map argument) => 'onWXOpenCustomerServiceChatResponse': (Map argument) =>
WeChatOpenCustomerServiceChatResponse.fromMap(argument), WeChatOpenCustomerServiceChatResponse.fromMap(argument),
}; };
class BaseWeChatResponse { class BaseWeChatResponse {
final int errCode;
final String? errStr;
bool get isSuccessful => errCode == 0;
BaseWeChatResponse._(this.errCode, this.errStr); BaseWeChatResponse._(this.errCode, this.errStr);
/// create response from response pool /// Create response from the response pool.
factory BaseWeChatResponse.create(String name, Map argument) { factory BaseWeChatResponse.create(String name, Map argument) {
var result = _nameAndResponseMapper[name]; var result = _nameAndResponseMapper[name];
if (result == null) { if (result == null) {
...@@ -62,127 +57,129 @@ class BaseWeChatResponse { ...@@ -62,127 +57,129 @@ class BaseWeChatResponse {
} }
return result(argument); return result(argument);
} }
final int errCode;
final String? errStr;
bool get isSuccessful => errCode == 0;
} }
class WeChatShareResponse extends BaseWeChatResponse { class WeChatShareResponse extends BaseWeChatResponse {
final int type;
WeChatShareResponse.fromMap(Map map) WeChatShareResponse.fromMap(Map map)
: type = map["type"], : type = map['type'],
super._(map[_errCode], map[_errStr]); super._(map[_errCode], map[_errStr]);
final int type;
} }
class WeChatAuthResponse extends BaseWeChatResponse { 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 int type;
final String? country; final String? country;
final String? lang; final String? lang;
final String? code; final String? code;
final String? state; 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 @override
bool operator ==(other) { bool operator ==(other) {
if (other is WeChatAuthResponse) { return other is WeChatAuthResponse &&
return code == other.code && code == other.code &&
country == other.country && country == other.country &&
lang == other.lang && lang == other.lang &&
state == other.state; state == other.state;
} else {
return false;
}
} }
@override @override
int get hashCode => int get hashCode =>
super.hashCode + errCode.hashCode & super.hashCode + errCode.hashCode &
1345 + errStr.hashCode & 1345 + errStr.hashCode &
15 + (code ?? "").hashCode & 15 + (code ?? '').hashCode &
1432; 1432;
} }
class WeChatLaunchMiniProgramResponse extends BaseWeChatResponse { class WeChatLaunchMiniProgramResponse extends BaseWeChatResponse {
final int? type;
final String? extMsg;
WeChatLaunchMiniProgramResponse.fromMap(Map map) WeChatLaunchMiniProgramResponse.fromMap(Map map)
: type = map["type"], : type = map['type'],
extMsg = map["extMsg"], extMsg = map['extMsg'],
super._(map[_errCode], map[_errStr]); super._(map[_errCode], map[_errStr]);
final int? type;
final String? extMsg;
} }
class WeChatPaymentResponse extends BaseWeChatResponse { class WeChatPaymentResponse extends BaseWeChatResponse {
final int type;
final String? extData;
WeChatPaymentResponse.fromMap(Map map) WeChatPaymentResponse.fromMap(Map map)
: type = map["type"], : type = map['type'],
extData = map["extData"], extData = map['extData'],
super._(map[_errCode], map[_errStr]); super._(map[_errCode], map[_errStr]);
final int type;
final String? extData;
} }
class WeChatOpenCustomerServiceChatResponse extends BaseWeChatResponse { class WeChatOpenCustomerServiceChatResponse extends BaseWeChatResponse {
final String? extMsg;
WeChatOpenCustomerServiceChatResponse.fromMap(Map map) WeChatOpenCustomerServiceChatResponse.fromMap(Map map)
: extMsg = map["extMsg"], : extMsg = map['extMsg'],
super._(map[_errCode], map[_errStr]); super._(map[_errCode], map[_errStr]);
final String? extMsg;
} }
class WeChatSubscribeMsgResponse extends BaseWeChatResponse { 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? openid;
final String? templateId; final String? templateId;
final String? action; final String? action;
final String? reserved; final String? reserved;
final int scene; 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 { 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? type;
final int errCode; final int errCode;
final int? businessType; final int? businessType;
final String resultInfo; 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 { class WeChatAuthByQRCodeFinishedResponse extends BaseWeChatResponse {
final String? authCode;
final AuthByQRCodeErrorCode? qrCodeErrorCode;
WeChatAuthByQRCodeFinishedResponse.fromMap(Map map) WeChatAuthByQRCodeFinishedResponse.fromMap(Map map)
: authCode = map["authCode"], : authCode = map['authCode'],
qrCodeErrorCode = (_authByQRCodeErrorCodes[_errCode] ?? qrCodeErrorCode = (_authByQRCodeErrorCodes[_errCode] ??
AuthByQRCodeErrorCode.UNKNOWN), AuthByQRCodeErrorCode.UNKNOWN),
super._(map[_errCode], map[_errStr]); super._(map[_errCode], map[_errStr]);
final String? authCode;
final AuthByQRCodeErrorCode? qrCodeErrorCode;
} }
///[qrCode] in memory. ///[qrCode] in memory.
class WeChatAuthGotQRCodeResponse extends BaseWeChatResponse { class WeChatAuthGotQRCodeResponse extends BaseWeChatResponse {
final Uint8List? qrCode;
WeChatAuthGotQRCodeResponse.fromMap(Map map) WeChatAuthGotQRCodeResponse.fromMap(Map map)
: qrCode = map["qrCode"], : qrCode = map['qrCode'],
super._(map[_errCode], map[_errStr]); super._(map[_errCode], map[_errStr]);
final Uint8List? qrCode;
} }
class WeChatQRCodeScannedResponse extends BaseWeChatResponse { class WeChatQRCodeScannedResponse extends BaseWeChatResponse {
...@@ -192,30 +189,21 @@ class WeChatQRCodeScannedResponse extends BaseWeChatResponse { ...@@ -192,30 +189,21 @@ class WeChatQRCodeScannedResponse extends BaseWeChatResponse {
// 获取微信打开App时携带的参数 // 获取微信打开App时携带的参数
class WeChatShowMessageFromWXRequest extends BaseWeChatResponse { class WeChatShowMessageFromWXRequest extends BaseWeChatResponse {
final String? extMsg;
WeChatShowMessageFromWXRequest.fromMap(Map map) WeChatShowMessageFromWXRequest.fromMap(Map map)
: extMsg = map["extMsg"], : extMsg = map['extMsg'],
super._(0, ''); 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 { enum AuthByQRCodeErrorCode {
OK, OK, // WechatAuth_Err_OK(0)
NORMAL_ERR, NORMAL_ERR, // WechatAuth_Err_NormalErr(-1)
NETWORK_ERR, NETWORK_ERR, // WechatAuth_Err_NetworkErr(-2)
JSON_DECODE_ERR, JSON_DECODE_ERR, // WechatAuth_Err_JsonDecodeErr(-3), WechatAuth_Err_GetQrcodeFailed on iOS
CANCEL, CANCEL, // WechatAuth_Err_Cancel(-4)
TIMEOUT, TIMEOUT, // WechatAuth_Err_Timeout(-5)
AUTH_STOPPED, AUTH_STOPPED, // WechatAuth_Err_Auth_Stopped(-6), Android only
UNKNOWN UNKNOWN
} }
......
...@@ -16,9 +16,7 @@ ...@@ -16,9 +16,7 @@
* License for the specific language governing permissions and limitations under * License for the specific language governing permissions and limitations under
* the License. * the License.
*/ */
import 'package:flutter/foundation.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/wechat_enums.dart';
const String _scene = "scene"; const String _scene = "scene";
const String _source = "source"; const String _source = "source";
...@@ -34,9 +32,20 @@ mixin WeChatShareBaseModel { ...@@ -34,9 +32,20 @@ mixin WeChatShareBaseModel {
Map toMap(); Map toMap();
} }
///[source] the text you want to send to WeChat /// [source] the text you want to send to WeChat
///[scene] the target you want to send /// [scene] the target you want to send
class WeChatShareTextModel implements WeChatShareBaseModel { 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 String source;
final WeChatScene scene; final WeChatScene scene;
final String? messageExt; final String? messageExt;
...@@ -45,16 +54,6 @@ class WeChatShareTextModel implements WeChatShareBaseModel { ...@@ -45,16 +54,6 @@ class WeChatShareTextModel implements WeChatShareBaseModel {
final String? title; final String? title;
final String? description; 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 @override
Map toMap() { Map toMap() {
return { return {
...@@ -69,10 +68,28 @@ class WeChatShareTextModel implements WeChatShareBaseModel { ...@@ -69,10 +68,28 @@ class WeChatShareTextModel implements WeChatShareBaseModel {
} }
} }
///
/// the default value is [MINI_PROGRAM_TYPE_RELEASE] /// 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 { 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 String webPageUrl;
final WXMiniProgramType miniProgramType; final WXMiniProgramType miniProgramType;
final String userName; final String userName;
...@@ -87,24 +104,6 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel { ...@@ -87,24 +104,6 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel {
final String? mediaTagName; final String? mediaTagName;
final bool compressThumbnail; 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 @override
Map toMap() { Map toMap() {
return { return {
...@@ -124,10 +123,22 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel { ...@@ -124,10 +123,22 @@ class WeChatShareMiniProgramModel implements WeChatShareBaseModel {
} }
} }
///[source] the image you want to send to WeChat /// [source] the image you want to send to WeChat
///[scene] the target you want to send /// [scene] the target you want to send
///[thumbnail] the preview of your image, will be created from [scene] if null. /// [thumbnail] the preview of your image, will be created from [scene] if null.
class WeChatShareImageModel implements WeChatShareBaseModel { 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 source;
final WeChatImage thumbnail; final WeChatImage thumbnail;
final String? title; final String? title;
...@@ -138,17 +149,6 @@ class WeChatShareImageModel implements WeChatShareBaseModel { ...@@ -138,17 +149,6 @@ class WeChatShareImageModel implements WeChatShareBaseModel {
final String? mediaTagName; final String? mediaTagName;
final bool compressThumbnail; 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 @override
Map toMap() { Map toMap() {
return { return {
...@@ -167,6 +167,21 @@ class WeChatShareImageModel implements WeChatShareBaseModel { ...@@ -167,6 +167,21 @@ class WeChatShareImageModel implements WeChatShareBaseModel {
/// if [musicUrl] and [musicLowBandUrl] are both provided, /// if [musicUrl] and [musicLowBandUrl] are both provided,
/// only [musicUrl] will be used. /// only [musicUrl] will be used.
class WeChatShareMusicModel implements WeChatShareBaseModel { 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? musicUrl;
final String? musicDataUrl; final String? musicDataUrl;
final String? musicLowBandUrl; final String? musicLowBandUrl;
...@@ -180,21 +195,6 @@ class WeChatShareMusicModel implements WeChatShareBaseModel { ...@@ -180,21 +195,6 @@ class WeChatShareMusicModel implements WeChatShareBaseModel {
final String? mediaTagName; final String? mediaTagName;
final bool compressThumbnail; 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 @override
Map toMap() { Map toMap() {
return { return {
...@@ -216,6 +216,20 @@ class WeChatShareMusicModel implements WeChatShareBaseModel { ...@@ -216,6 +216,20 @@ class WeChatShareMusicModel implements WeChatShareBaseModel {
/// if [videoUrl] and [videoLowBandUrl] are both provided, /// if [videoUrl] and [videoLowBandUrl] are both provided,
/// only [videoUrl] will be used. /// only [videoUrl] will be used.
class WeChatShareVideoModel implements WeChatShareBaseModel { 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? videoUrl;
final String? videoLowBandUrl; final String? videoLowBandUrl;
final WeChatImage? thumbnail; final WeChatImage? thumbnail;
...@@ -227,20 +241,6 @@ class WeChatShareVideoModel implements WeChatShareBaseModel { ...@@ -227,20 +241,6 @@ class WeChatShareVideoModel implements WeChatShareBaseModel {
final String? mediaTagName; final String? mediaTagName;
final bool compressThumbnail; 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 @override
Map toMap() { Map toMap() {
return { return {
...@@ -257,9 +257,22 @@ class WeChatShareVideoModel implements WeChatShareBaseModel { ...@@ -257,9 +257,22 @@ class WeChatShareVideoModel implements WeChatShareBaseModel {
} }
} }
///[webPage] url you want to send to wechat /// [webPage] url you want to send to wechat
///[thumbnail] logo of your website /// [thumbnail] logo of your website
class WeChatShareWebPageModel implements WeChatShareBaseModel { 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 String webPage;
final WeChatImage? thumbnail; final WeChatImage? thumbnail;
final String title; final String title;
...@@ -270,18 +283,6 @@ class WeChatShareWebPageModel implements WeChatShareBaseModel { ...@@ -270,18 +283,6 @@ class WeChatShareWebPageModel implements WeChatShareBaseModel {
final String? mediaTagName; final String? mediaTagName;
final bool compressThumbnail; 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 @override
Map toMap() { Map toMap() {
return { return {
...@@ -301,6 +302,18 @@ class WeChatShareWebPageModel implements WeChatShareBaseModel { ...@@ -301,6 +302,18 @@ class WeChatShareWebPageModel implements WeChatShareBaseModel {
/// [scene] can't be [WeChatScene.TIMELINE], otherwise, sharing nothing. /// [scene] can't be [WeChatScene.TIMELINE], otherwise, sharing nothing.
/// send files to WeChat /// send files to WeChat
class WeChatShareFileModel implements WeChatShareBaseModel { 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 WeChatFile source;
final WeChatImage? thumbnail; final WeChatImage? thumbnail;
final String title; final String title;
...@@ -311,16 +324,6 @@ class WeChatShareFileModel implements WeChatShareBaseModel { ...@@ -311,16 +324,6 @@ class WeChatShareFileModel implements WeChatShareBaseModel {
final String? mediaTagName; final String? mediaTagName;
final bool compressThumbnail; 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 @override
Map toMap() { Map toMap() {
return { return {
......
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
* the License. * the License.
*/ */
///[WXMiniProgramType.RELEASE]正式版 /// [WXMiniProgramType.RELEASE]正式版
///[WXMiniProgramType.TEST]测试版 /// [WXMiniProgramType.TEST]测试版
///[WXMiniProgramType.PREVIEW]预览版 /// [WXMiniProgramType.PREVIEW]预览版
enum WXMiniProgramType { RELEASE, TEST, PREVIEW } enum WXMiniProgramType { RELEASE, TEST, PREVIEW }
///[WeChatScene.SESSION]会话 /// [WeChatScene.SESSION]会话
///[WeChatScene.TIMELINE]朋友圈 /// [WeChatScene.TIMELINE]朋友圈
///[WeChatScene.FAVORITE]收藏 /// [WeChatScene.FAVORITE]收藏
enum WeChatScene { SESSION, TIMELINE, FAVORITE } enum WeChatScene { SESSION, TIMELINE, FAVORITE }
extension MiniProgramTypeExtensions on WXMiniProgramType { extension MiniProgramTypeExtensions on WXMiniProgramType {
...@@ -36,7 +36,8 @@ extension MiniProgramTypeExtensions on WXMiniProgramType { ...@@ -36,7 +36,8 @@ extension MiniProgramTypeExtensions on WXMiniProgramType {
return 1; return 1;
case WXMiniProgramType.RELEASE: case WXMiniProgramType.RELEASE:
return 0; return 0;
default:
return 0;
} }
return 0;
} }
} }
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
* Licensed to the Apache Software Foundation (ASF) under one or more contributor * Licensed to the Apache Software Foundation (ASF) under one or more contributor
* license agreements. See the NOTICE file distributed with this work for * license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership. The ASF licenses this * 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 * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * 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 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under * License for the specific language governing permissions and limitations under
* the License. * the License.
...@@ -19,85 +19,96 @@ ...@@ -19,85 +19,96 @@
import 'dart:io'; import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
const String defaultSuffixJpeg = ".jpeg"; const String defaultSuffixJpeg = '.jpeg';
const String defaultSuffixTxt = ".txt"; const String defaultSuffixTxt = '.txt';
class WeChatImage extends WeChatFile { class WeChatImage extends WeChatFile {
WeChatImage.network(String source, {String suffix = defaultSuffixJpeg}) WeChatImage.network(
: super.network(source, suffix: suffix); String source, {
String suffix = defaultSuffixJpeg,
}) : super.network(source, suffix: suffix);
WeChatImage.asset(String source, {String suffix = defaultSuffixJpeg}) WeChatImage.asset(
: super.asset(source, suffix: suffix); String source, {
String suffix = defaultSuffixJpeg,
}) : super.asset(source, suffix: suffix);
WeChatImage.file(File source, {String suffix = defaultSuffixJpeg}) WeChatImage.file(
: super.file(source, suffix: suffix); File source, {
String suffix = defaultSuffixJpeg,
}) : super.file(source, suffix: suffix);
WeChatImage.binary(Uint8List source, {String suffix = defaultSuffixJpeg}) WeChatImage.binary(
: super.binary(source, suffix: suffix); Uint8List source, {
String suffix = defaultSuffixJpeg,
}) : super.binary(source, suffix: suffix);
} }
class WeChatFile { class WeChatFile {
final dynamic source;
final FileSchema schema;
final String suffix;
/// [source] must begin with http or https /// [source] must begin with http or https
WeChatFile.network(String source, {String? suffix}) WeChatFile.network(
: assert(source.startsWith("http")), String source, {
this.source = source, String? suffix,
this.schema = FileSchema.NETWORK, }) : assert(source.startsWith('http')),
this.suffix = source.readSuffix(suffix, defaultSuffixTxt); source = source,
schema = FileSchema.NETWORK,
suffix = source.readSuffix(suffix, defaultSuffixTxt);
///[source] path of the image, like '/asset/image.pdf?package=flutter', ///[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 ///the query param package in [source] only available when you want to specify the package of image
WeChatFile.asset(String source, {String? suffix}) WeChatFile.asset(
: assert(source.trim().isNotEmpty), String source, {
String? suffix,
}) : assert(source.trim().isNotEmpty),
this.source = source, this.source = source,
this.schema = FileSchema.ASSET, this.schema = FileSchema.ASSET,
this.suffix = source.readSuffix(suffix, defaultSuffixTxt); this.suffix = source.readSuffix(suffix, defaultSuffixTxt);
WeChatFile.file(File source, {String suffix = defaultSuffixTxt}) WeChatFile.file(
: this.source = source.path, File source, {
this.schema = FileSchema.FILE, String suffix = defaultSuffixTxt,
this.suffix = source.path.readSuffix(suffix, defaultSuffixTxt); }) : source = source.path,
schema = FileSchema.FILE,
suffix = source.path.readSuffix(suffix, defaultSuffixTxt);
WeChatFile.binary(Uint8List source, {String suffix = defaultSuffixTxt}) WeChatFile.binary(
: assert(suffix.trim().isNotEmpty), Uint8List source, {
this.source = source, String suffix = defaultSuffixTxt,
this.schema = FileSchema.BINARY, }) : assert(suffix.trim().isNotEmpty),
this.suffix = suffix; source = source,
schema = FileSchema.BINARY,
suffix = suffix;
Map toMap() => final dynamic source;
{"source": source, "schema": schema.index, "suffix": suffix}; final FileSchema schema;
} final String suffix;
///Types of image, usually there are for types listed below. Map toMap() => {'source': source, 'schema': schema.index, 'suffix': suffix};
///[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,
} }
/// 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 { extension _FileSuffix on String {
/// returns [suffix] if [suffix] not blank. /// returns [suffix] if [suffix] not blank.
/// If [suffix] is blank, then try to read from url /// If [suffix] is blank, then try to read from url
/// if suffix in url not found, then return jpg as default. /// if suffix in url not found, then return jpg as default.
String readSuffix(String? suffix, String defaultSuffix) { String readSuffix(String? suffix, String defaultSuffix) {
if (suffix != null && suffix.trim().isNotEmpty) { if (suffix != null && suffix.trim().isNotEmpty) {
if (suffix.startsWith(".")) { if (suffix.startsWith('.')) {
return suffix; return suffix;
} else { } else {
return ".$suffix"; return '.$suffix';
} }
} }
var path = Uri.parse(this).path; var path = Uri.parse(this).path;
var index = path.lastIndexOf("."); var index = path.lastIndexOf('.');
if (index >= 0) { if (index >= 0) {
return path.substring(index); return path.substring(index);
......
...@@ -9,19 +9,23 @@ void main() { ...@@ -9,19 +9,23 @@ void main() {
setUp(() { setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async { channel.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == "registerApp") { if (methodCall.method == 'registerApp') {
if (methodCall.arguments["appId"] == "wx13124324324") { if (methodCall.arguments['appId'] == 'wx13124324324') {
return Future.value(true); return Future.value(true);
} else { } else {
return Future.value(false); return Future.value(false);
} }
} else if (methodCall.method == "shareText") { } else if (methodCall.method == 'shareText') {
channel.invokeMethod( channel.invokeMethod(
"onShareResponse", {"type": 1, "errCode": 1, "errStr": "hehe"}); 'onShareResponse',
{'type': 1, 'errCode': 1, 'errStr': 'hehe'},
);
return Future.value(true); return Future.value(true);
} else if (methodCall.method == "shareImage") { } else if (methodCall.method == 'shareImage') {
channel.invokeMethod( channel.invokeMethod(
"onShareResponse", {"type": 1, "errCode": 0, "errStr": ""}); 'onShareResponse',
{'type': 1, 'errCode': 0, 'errStr': ''},
);
return Future.value(true); return Future.value(true);
} }
return '42'; return '42';
...@@ -32,34 +36,38 @@ void main() { ...@@ -32,34 +36,38 @@ void main() {
channel.setMockMethodCallHandler(null); channel.setMockMethodCallHandler(null);
}); });
group("register", () { group('register', () {
test("success", () async { test('success', () async {
expect(await fluwx.registerWxApi(appId: "wx13124324324"), true); expect(await fluwx.registerWxApi(appId: 'wx13124324324'), true);
}); });
test("failed", () async { test('failed', () async {
expect(await fluwx.registerWxApi(appId: "wx131256"), false); expect(await fluwx.registerWxApi(appId: 'wx131256'), false);
}); });
}); });
group("share", () { group('share', () {
test("text", () async { test('text', () async {
expect( expect(
await fluwx.shareToWeChat(fluwx.WeChatShareTextModel("text")), true); await fluwx.shareToWeChat(fluwx.WeChatShareTextModel('text')),
true,
);
}); });
test("shareImage", () async { test('shareImage', () async {
expect( expect(
await fluwx.shareToWeChat(fluwx.WeChatShareImageModel( await fluwx.shareToWeChat(
fluwx.WeChatImage.network("http://flutter.dev"))), fluwx.WeChatShareImageModel(
true); fluwx.WeChatImage.network('http://flutter.dev'),
),
),
true,
);
}); });
}); });
group("learn", () { group('learn', () {
test("description", () async { test('description', () async {
print("argumentsss"); print('argumentsss');
}); });
}); });
} }
...@@ -21,97 +21,103 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -21,97 +21,103 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
void main() { void main() {
group("create response", () { group('create response', () {
test("WeChatShareResponse", () { test('WeChatShareResponse', () {
var response = BaseWeChatResponse.create( var response = BaseWeChatResponse.create(
"onShareResponse", {"type": 1, "errCode": 1, "errStr": "hehe"}); 'onShareResponse',
{'type': 1, 'errCode': 1, 'errStr': 'hehe'},
);
expect(response is WeChatShareResponse, true); expect(response is WeChatShareResponse, true);
var casted = response as WeChatShareResponse; var casted = response as WeChatShareResponse;
expect(casted.type, 1); expect(casted.type, 1);
expect(casted.errCode, 1); expect(casted.errCode, 1);
expect(casted.errStr, "hehe"); expect(casted.errStr, 'hehe');
}); });
test("WeChatAuthResponse", () { test('WeChatAuthResponse', () {
var response = BaseWeChatResponse.create("onAuthResponse", { var response = BaseWeChatResponse.create('onAuthResponse', {
"type": 1, 'type': 1,
"errCode": 1, 'errCode': 1,
"errStr": "hehe", 'errStr': 'hehe',
"country": "cn", 'country': 'cn',
"lang": "lang", 'lang': 'lang',
"code": "code", 'code': 'code',
"state": "ok" 'state': 'ok'
}); });
expect(response is WeChatAuthResponse, true); expect(response is WeChatAuthResponse, true);
var casted = response as WeChatAuthResponse; var casted = response as WeChatAuthResponse;
expect(casted.type, 1); expect(casted.type, 1);
expect(casted.errCode, 1); expect(casted.errCode, 1);
expect(casted.errStr, "hehe"); expect(casted.errStr, 'hehe');
expect(casted.country, "cn"); expect(casted.country, 'cn');
expect(casted.lang, "lang"); expect(casted.lang, 'lang');
expect(casted.code, "code"); expect(casted.code, 'code');
expect(casted.state, "ok"); expect(casted.state, 'ok');
}); });
test("onLaunchMiniProgramResponse", () { test('onLaunchMiniProgramResponse', () {
var response = BaseWeChatResponse.create("onLaunchMiniProgramResponse", var response = BaseWeChatResponse.create(
{"type": 1, "errCode": 1, "errStr": "hehe", "extMsg": "extMsg"}); 'onLaunchMiniProgramResponse',
{'type': 1, 'errCode': 1, 'errStr': 'hehe', 'extMsg': 'extMsg'},
);
expect(response is WeChatLaunchMiniProgramResponse, true); expect(response is WeChatLaunchMiniProgramResponse, true);
var casted = response as WeChatLaunchMiniProgramResponse; var casted = response as WeChatLaunchMiniProgramResponse;
expect(casted.type, 1); expect(casted.type, 1);
expect(casted.errCode, 1); expect(casted.errCode, 1);
expect(casted.errStr, "hehe"); expect(casted.errStr, 'hehe');
expect(casted.extMsg, "extMsg"); expect(casted.extMsg, 'extMsg');
}); });
test("WeChatPaymentResponse", () { test('WeChatPaymentResponse', () {
var response = BaseWeChatResponse.create("onPayResponse", var response = BaseWeChatResponse.create(
{"type": 1, "errCode": 1, "errStr": "hehe", "extData": "extData"}); 'onPayResponse',
{'type': 1, 'errCode': 1, 'errStr': 'hehe', 'extData': 'extData'},
);
expect(response is WeChatPaymentResponse, true); expect(response is WeChatPaymentResponse, true);
var casted = response as WeChatPaymentResponse; var casted = response as WeChatPaymentResponse;
expect(casted.type, 1); expect(casted.type, 1);
expect(casted.errCode, 1); expect(casted.errCode, 1);
expect(casted.errStr, "hehe"); expect(casted.errStr, 'hehe');
expect(casted.extData, "extData"); expect(casted.extData, 'extData');
}); });
test("WeChatSubscribeMsgResponse", () { test('WeChatSubscribeMsgResponse', () {
var response = BaseWeChatResponse.create("onSubscribeMsgResp", { var response = BaseWeChatResponse.create('onSubscribeMsgResp', {
"type": 1, 'type': 1,
"errCode": 1, 'errCode': 1,
"errStr": "hehe", 'errStr': 'hehe',
"openid": "425235131", 'openid': '425235131',
"templateId": "4252345", 'templateId': '4252345',
"action": "action", 'action': 'action',
"reserved": "reserved", 'reserved': 'reserved',
"scene": 1 'scene': 1
}); });
expect(response is WeChatSubscribeMsgResponse, true); expect(response is WeChatSubscribeMsgResponse, true);
var casted = response as WeChatSubscribeMsgResponse; var casted = response as WeChatSubscribeMsgResponse;
expect(casted.errCode, 1); expect(casted.errCode, 1);
expect(casted.errStr, "hehe"); expect(casted.errStr, 'hehe');
expect(casted.openid, "425235131"); expect(casted.openid, '425235131');
expect(casted.templateId, "4252345"); expect(casted.templateId, '4252345');
expect(casted.action, "action"); expect(casted.action, 'action');
expect(casted.reserved, "reserved"); expect(casted.reserved, 'reserved');
expect(casted.scene, 1); expect(casted.scene, 1);
}); });
test("WeChatAutoDeductResponse", () { test('WeChatAutoDeductResponse', () {
var response = BaseWeChatResponse.create("onAutoDeductResponse", { var response = BaseWeChatResponse.create('onAutoDeductResponse', {
"type": 1, 'type': 1,
"errCode": 0, 'errCode': 0,
"errStr": "hehe", 'errStr': 'hehe',
"businessType": 2, 'businessType': 2,
"resultInfo": "resultInfo" 'resultInfo': 'resultInfo'
}); });
expect(response is WeChatOpenBusinessWebviewResponse, true); expect(response is WeChatOpenBusinessWebviewResponse, true);
var casted = response as WeChatOpenBusinessWebviewResponse; var casted = response as WeChatOpenBusinessWebviewResponse;
assert(casted.isSuccessful); assert(casted.isSuccessful);
expect(casted.type, 1); expect(casted.type, 1);
expect(casted.errCode, 0); expect(casted.errCode, 0);
expect(casted.errStr, "hehe"); expect(casted.errStr, 'hehe');
expect(casted.resultInfo, "resultInfo"); expect(casted.resultInfo, 'resultInfo');
expect(casted.businessType, 2); expect(casted.businessType, 2);
}); });
}); });
......
...@@ -18,35 +18,38 @@ ...@@ -18,35 +18,38 @@
*/ */
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/share/share_models.dart';
import 'package:fluwx/src/wechat_enums.dart';
void main() { void main() {
test("test create WeChatShareImageModel with thumbnail", () { test('test create WeChatShareImageModel with thumbnail', () {
var image = WeChatImage.network("http://openflutter.dev/fluwx.png"); var image = WeChatImage.network('http://openflutter.dev/fluwx.png');
var thumbnail = WeChatImage.network("http://openflutter.dev/fluwx.png"); var thumbnail = WeChatImage.network('http://openflutter.dev/fluwx.png');
var model = WeChatShareImageModel(image, var model = WeChatShareImageModel(
scene: WeChatScene.FAVORITE, thumbnail: thumbnail); image,
scene: WeChatScene.FAVORITE,
thumbnail: thumbnail,
);
expect(model.source, image); expect(model.source, image);
expect(model.scene, WeChatScene.FAVORITE); expect(model.scene, WeChatScene.FAVORITE);
expect(model.thumbnail, thumbnail); expect(model.thumbnail, thumbnail);
}); });
test("test create WeChatShareImageModel without thumbnail", () { test('test create WeChatShareImageModel without thumbnail', () {
var image = WeChatImage.network("http://openflutter.dev/fluwx.png"); var image = WeChatImage.network('http://openflutter.dev/fluwx.png');
var model = WeChatShareImageModel(image, scene: WeChatScene.FAVORITE); var model = WeChatShareImageModel(image, scene: WeChatScene.FAVORITE);
expect(model.source, image); expect(model.source, image);
expect(model.scene, WeChatScene.FAVORITE); expect(model.scene, WeChatScene.FAVORITE);
expect(model.thumbnail, image); expect(model.thumbnail, image);
}); });
test("test WeChatShareImageModel toMap", () { test('test WeChatShareImageModel toMap', () {
var image = WeChatImage.network("http://openflutter.dev/fluwx.png"); var image = WeChatImage.network('http://openflutter.dev/fluwx.png');
var thumbnail = WeChatImage.network("http://openflutter.dev/fluwx.png"); var thumbnail = WeChatImage.network('http://openflutter.dev/fluwx.png');
var map = WeChatShareImageModel(image, var map = WeChatShareImageModel(
scene: WeChatScene.FAVORITE, thumbnail: thumbnail) image,
.toMap(); scene: WeChatScene.FAVORITE,
assert(map["thumbnail"] != null); thumbnail: thumbnail,
expect(map["thumbnail"]["source"], "http://openflutter.dev/fluwx.png"); ).toMap();
assert(map['thumbnail'] != null);
expect(map['thumbnail']['source'], 'http://openflutter.dev/fluwx.png');
}); });
} }
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
*/ */
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/share/share_models.dart';
import 'package:fluwx/src/wechat_enums.dart';
void main() { void main() {
group("construct", () { group("construct", () {
......
...@@ -21,15 +21,15 @@ import 'package:fluwx/src/share/share_models.dart'; ...@@ -21,15 +21,15 @@ import 'package:fluwx/src/share/share_models.dart';
import 'package:fluwx/src/wechat_enums.dart'; import 'package:fluwx/src/wechat_enums.dart';
void main() { void main() {
test("create WeChatTextModel", () { test('create WeChatTextModel', () {
var model = WeChatShareTextModel("text", scene: WeChatScene.FAVORITE); var model = WeChatShareTextModel('text', scene: WeChatScene.FAVORITE);
expect(model.source, "text"); expect(model.source, 'text');
expect(model.scene, WeChatScene.FAVORITE); expect(model.scene, WeChatScene.FAVORITE);
}); });
test("WeChatTextModel toMap", () { test('WeChatTextModel toMap', () {
var map = WeChatShareTextModel("text", scene: WeChatScene.FAVORITE).toMap(); var map = WeChatShareTextModel('text', scene: WeChatScene.FAVORITE).toMap();
expect(map["source"], "text"); expect(map['source'], 'text');
expect(map["scene"], 2); expect(map['scene'], 2);
}); });
} }
...@@ -17,30 +17,36 @@ ...@@ -17,30 +17,36 @@
* the License. * the License.
*/ */
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:fluwx/fluwx.dart';
import 'package:fluwx/src/wechat_file.dart'; import 'package:fluwx/src/wechat_file.dart';
void main() { void main() {
test('test WeChatImage.fromNetwork', () {
test("test WeChatImage.fromNetwork", () { var withSuffixImage = WeChatImage.network(
var withSuffixImage = 'http://image.openflutter.dev/fluwx.png',
WeChatImage.network("http://image.openflutter.dev/fluwx.png"); );
expect(withSuffixImage.source, "http://image.openflutter.dev/fluwx.png"); expect(withSuffixImage.source, 'http://image.openflutter.dev/fluwx.png');
expect(withSuffixImage.suffix, ".png"); expect(withSuffixImage.suffix, '.png');
expect(FileSchema.NETWORK, withSuffixImage.schema); expect(FileSchema.NETWORK, withSuffixImage.schema);
var withNoSuffixNoUrlSuffixImage = var withNoSuffixNoUrlSuffixImage = WeChatImage.network(
WeChatImage.network("http://image.openflutter.dev/fluwx"); 'http://image.openflutter.dev/fluwx',
expect("http://image.openflutter.dev/fluwx", );
withNoSuffixNoUrlSuffixImage.source); expect(
expect(withNoSuffixNoUrlSuffixImage.suffix, ".jpeg"); 'http://image.openflutter.dev/fluwx',
withNoSuffixNoUrlSuffixImage.source,
);
expect(withNoSuffixNoUrlSuffixImage.suffix, '.jpeg');
expect(FileSchema.NETWORK, withSuffixImage.schema); expect(FileSchema.NETWORK, withSuffixImage.schema);
var withSpecifiedSuffixImage = WeChatImage.network( var withSpecifiedSuffixImage = WeChatImage.network(
"http://image.openflutter.dev/fluwx.jpeg", 'http://image.openflutter.dev/fluwx.jpeg',
suffix: ".png"); suffix: '.png',
expect(withSpecifiedSuffixImage.source, "http://image.openflutter.dev/fluwx.jpeg"); );
expect(withSpecifiedSuffixImage.suffix, ".png"); expect(
withSpecifiedSuffixImage.source,
'http://image.openflutter.dev/fluwx.jpeg',
);
expect(withSpecifiedSuffixImage.suffix, '.png');
expect(withSpecifiedSuffixImage.schema, FileSchema.NETWORK); expect(withSpecifiedSuffixImage.schema, FileSchema.NETWORK);
}); });
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论