提交 f10d3670 authored 作者: JarvanMo's avatar JarvanMo

update demo

上级 2371d33c
...@@ -15,7 +15,7 @@ class _SendAuthPageState extends State<SendAuthPage> { ...@@ -15,7 +15,7 @@ class _SendAuthPageState extends State<SendAuthPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
fluwx.subscribeResponse((response) { fluwx.addSubscriber((response) {
if (response is WeChatAuthResponse) { if (response is WeChatAuthResponse) {
setState(() { setState(() {
_result = 'state :${response.state} \n code:${response.code}'; _result = 'state :${response.state} \n code:${response.code}';
......
import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
import 'package:fluwx_example/utils.dart';
class ShareImagePage extends StatefulWidget { class ShareImagePage extends StatefulWidget {
const ShareImagePage({Key? key}) : super(key: key); const ShareImagePage({Key? key}) : super(key: key);
...@@ -11,13 +14,21 @@ class ShareImagePage extends StatefulWidget { ...@@ -11,13 +14,21 @@ class ShareImagePage extends StatefulWidget {
class _ShareImagePageState extends State<ShareImagePage> { class _ShareImagePageState extends State<ShareImagePage> {
WeChatScene scene = WeChatScene.session; WeChatScene scene = WeChatScene.session;
String _response = ''; String _response = '';
String _imageToShare = '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';
Fluwx fluwx = Fluwx(); Fluwx fluwx = Fluwx();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
fluwx.subscribeResponse((res) { fluwx.addSubscriber((res) {
if (res is WeChatShareResponse) { if (res is WeChatShareResponse) {
setState(() { setState(() {
_response = 'state :${res.isSuccessful}'; _response = 'state :${res.isSuccessful}';
...@@ -45,24 +56,17 @@ class _ShareImagePageState extends State<ShareImagePage> { ...@@ -45,24 +56,17 @@ class _ShareImagePageState extends State<ShareImagePage> {
TextField( TextField(
decoration: const InputDecoration(labelText: '图片地址(仅限网络)'), decoration: const InputDecoration(labelText: '图片地址(仅限网络)'),
controller: TextEditingController( controller: TextEditingController(
text: 'https://timgsa.baidu.com/timg' text: _imageToShare,
'?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) {
_imageToShare = 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) {},
},
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
...@@ -112,7 +116,12 @@ class _ShareImagePageState extends State<ShareImagePage> { ...@@ -112,7 +116,12 @@ class _ShareImagePageState extends State<ShareImagePage> {
); );
} }
void _shareImage() { void _shareImage() async{
fluwx.share(WeChatShareImageModel(
WeChatImageToShare(
uint8List: await fetchImageAsUint8List(_imageToShare) ,
),
));
} }
void handleRadioValueChanged(WeChatScene scene) { void handleRadioValueChanged(WeChatScene scene) {
......
...@@ -29,7 +29,7 @@ class _SignAutoDeductPageState extends State<SignAutoDeductPage> { ...@@ -29,7 +29,7 @@ class _SignAutoDeductPageState extends State<SignAutoDeductPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
fluwx.subscribeResponse((resp) { fluwx.addSubscriber((resp) {
print('resp = ${resp.isSuccessful}'); print('resp = ${resp.isSuccessful}');
}); });
} }
......
...@@ -21,7 +21,7 @@ class _SubscribeMessagePageState extends State<SubscribeMessagePage> { ...@@ -21,7 +21,7 @@ class _SubscribeMessagePageState extends State<SubscribeMessagePage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
fluwx.subscribeResponse((resp) { fluwx.addSubscriber((resp) {
debugPrint('resp = $resp'); debugPrint('resp = $resp');
}); });
} }
......
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
Future<Uint8List?> fetchImageAsUint8List(String imageUrl) async {
try {
final response = await http.get(Uri.parse(imageUrl));
if (response.statusCode == 200) {
return response.bodyBytes;
} else {
debugPrint('Failed to load image: ${response.statusCode}');
return null;
}
} catch (e) {
debugPrint('Error fetching image: $e');
return null;
}
}
\ No newline at end of file
...@@ -53,6 +53,7 @@ dev_dependencies: ...@@ -53,6 +53,7 @@ dev_dependencies:
# package. See that file for information about deactivating specific lint # package. See that file for information about deactivating specific lint
# rules and activating additional ones. # rules and activating additional ones.
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
http: ^1.2.2
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论