|
|
|
@ -1,11 +1,16 @@
|
|
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:flutter/rendering.dart'; |
|
|
|
|
import 'package:flutter/services.dart'; |
|
|
|
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
|
import 'dart:ui' as ui; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
|
import 'package:qr_flutter/qr_flutter.dart'; |
|
|
|
|
import 'package:sharesdk_plugin/sharesdk_plugin.dart'; |
|
|
|
|
|
|
|
|
|
class QrShareImagePage extends StatefulWidget { |
|
|
|
|
|
|
|
|
|
String mobile; |
|
|
|
|
|
|
|
|
|
QrShareImagePage(this.mobile); |
|
|
|
@ -14,19 +19,138 @@ class QrShareImagePage extends StatefulWidget {
|
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
|
return _QrShareImagePage(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class _QrShareImagePage extends State<QrShareImagePage> { |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
widgetToImage(); |
|
|
|
|
return Container( |
|
|
|
|
width: 200, |
|
|
|
|
height: 300, |
|
|
|
|
color: Colors.white.withAlpha(123), |
|
|
|
|
child: Text(widget.mobile), |
|
|
|
|
return Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
|
children: [ |
|
|
|
|
RepaintBoundary( |
|
|
|
|
key: globalKey, |
|
|
|
|
child: Container( |
|
|
|
|
width: MediaQuery.of(context).size.width * 0.8, |
|
|
|
|
height: (MediaQuery.of(context).size.width * 0.8) * 1.36, |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
borderRadius: BorderRadius.circular(10.w), |
|
|
|
|
), |
|
|
|
|
child: Column( |
|
|
|
|
children: [ |
|
|
|
|
Image.asset( |
|
|
|
|
"assets/image/share_image_bg.png", |
|
|
|
|
height: (MediaQuery.of(context).size.width * 0.8) * 0.47, |
|
|
|
|
width: (MediaQuery.of(context).size.width * 0.8), |
|
|
|
|
), |
|
|
|
|
Expanded( |
|
|
|
|
child: Container( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Colors.white, |
|
|
|
|
borderRadius: BorderRadius.vertical( |
|
|
|
|
bottom: Radius.circular(10.w), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
child: Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
|
|
|
children: [ |
|
|
|
|
Container( |
|
|
|
|
width: 206.w, |
|
|
|
|
height: 30.h, |
|
|
|
|
child: Text( |
|
|
|
|
"邀请人手机号:${widget.mobile.substring(0, 3)}****${widget.mobile.substring(7, 11)}", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
color: Color(0xFF2E3552), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFFFC93B), |
|
|
|
|
border: Border.all( |
|
|
|
|
color: Color(0xFF2E3552), |
|
|
|
|
width: 1, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Container( |
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 68.w), |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
border: Border.all( |
|
|
|
|
color: Color(0xFF2E3552), |
|
|
|
|
width: 1, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
child: AspectRatio( |
|
|
|
|
aspectRatio: 1, |
|
|
|
|
child: QrImage( |
|
|
|
|
data: "http://mp.hx.lotus-wallet.com/pages/invite/index?mobile=${widget.mobile ?? ""}", |
|
|
|
|
version: QrVersions.auto, |
|
|
|
|
size: 200.w, |
|
|
|
|
gapless: true, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Container( |
|
|
|
|
margin: EdgeInsets.only(left: 16.w, right: 24.w), |
|
|
|
|
child: Text( |
|
|
|
|
"扫码识别,关注公众号", |
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF2E3552), |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
flex: 1, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
SizedBox( |
|
|
|
|
height: 15, |
|
|
|
|
), |
|
|
|
|
TextButton( |
|
|
|
|
onPressed: () { |
|
|
|
|
widgetToImage(); |
|
|
|
|
}, |
|
|
|
|
style: ButtonStyle( |
|
|
|
|
backgroundColor: MaterialStateProperty.all( |
|
|
|
|
Color(0xFFFFC93B), |
|
|
|
|
), |
|
|
|
|
shape: MaterialStateProperty.all( |
|
|
|
|
RoundedRectangleBorder( |
|
|
|
|
side: BorderSide( |
|
|
|
|
color: Color(0xFF2E3552), |
|
|
|
|
width: 1, |
|
|
|
|
), |
|
|
|
|
borderRadius: BorderRadius.circular(5), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
elevation: MaterialStateProperty.all(3), |
|
|
|
|
shadowColor: MaterialStateProperty.all(Colors.amber), |
|
|
|
|
padding: MaterialStateProperty.all( |
|
|
|
|
EdgeInsets.symmetric( |
|
|
|
|
vertical: 5.h, |
|
|
|
|
horizontal: 20.w, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
child: Text( |
|
|
|
|
"分享至微信", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF2E3552), |
|
|
|
|
fontSize: 18.sp, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -36,10 +160,49 @@ class _QrShareImagePage extends State<QrShareImagePage> {
|
|
|
|
|
BuildContext buildContext = globalKey.currentContext; |
|
|
|
|
if (null != buildContext) { |
|
|
|
|
RenderRepaintBoundary boundary = buildContext.findRenderObject(); |
|
|
|
|
ui.Image image = await boundary.toImage(); |
|
|
|
|
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png); |
|
|
|
|
// byteData.buffer.asUint16List() |
|
|
|
|
ui.Image image = await boundary.toImage(pixelRatio: 3); |
|
|
|
|
ByteData byteData = |
|
|
|
|
await image.toByteData(format: ui.ImageByteFormat.png); |
|
|
|
|
|
|
|
|
|
String filePath = ""; |
|
|
|
|
if (Platform.isAndroid) { |
|
|
|
|
filePath = (await getExternalStorageDirectory()).path; |
|
|
|
|
} else { |
|
|
|
|
filePath = (await getApplicationDocumentsDirectory()).path; |
|
|
|
|
} |
|
|
|
|
filePath = "$filePath/${DateTime.now().millisecondsSinceEpoch}.png"; |
|
|
|
|
|
|
|
|
|
File file = File(filePath); |
|
|
|
|
if (!file.existsSync()) { |
|
|
|
|
file.createSync(); |
|
|
|
|
print("object: ${file.path}"); |
|
|
|
|
} |
|
|
|
|
file.writeAsBytesSync(byteData.buffer.asUint8List()); |
|
|
|
|
|
|
|
|
|
SSDKMap params = SSDKMap() |
|
|
|
|
..setGeneral( |
|
|
|
|
"", |
|
|
|
|
"", |
|
|
|
|
[ |
|
|
|
|
file.path, |
|
|
|
|
], |
|
|
|
|
"", |
|
|
|
|
file.path, |
|
|
|
|
"", |
|
|
|
|
"", |
|
|
|
|
"", |
|
|
|
|
"", |
|
|
|
|
"", |
|
|
|
|
SSDKContentTypes.image, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
SharesdkPlugin.share(ShareSDKPlatforms.wechatSession, params, |
|
|
|
|
(state, userData, contentEntity, error) { |
|
|
|
|
print("share state !$state"); |
|
|
|
|
print("share userData !$userData"); |
|
|
|
|
print("share contentEntity !$contentEntity"); |
|
|
|
|
print("share error !$error"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |