| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- import 'dart:convert';
- import 'dart:typed_data';
- import 'package:flutter/material.dart';
- import 'package:flutter_svg/svg.dart';
- import 'package:link/utils/global.dart';
- import 'package:link/view/component/web_image.dart';
- import 'package:screenshot/screenshot.dart';
- import 'dart:js' as js;
- import '../utils/size_fit.dart';
- class Share extends StatefulWidget {
- Uint8List byteData;
- Share({Key? key, required this.byteData}) : super(key: key);
- @override
- State<Share> createState() => _ShareState();
- }
- class _ShareState extends State<Share> {
- bool showShareGuide = false;
- bool isWechatBrowser = false; //false;
- ScreenshotController screenshotController = ScreenshotController();
- Uint8List? imgData;
- @override
- initState() {
- // var ua = html.window.navigator.userAgent.toLowerCase();
- getImage();
- getPlatform();
- super.initState();
- }
- getImage() async {
- screenshotController
- .captureFromWidget(SizedBox(
- width: MediaQuery.of(context).size.width,
- height: MediaQuery.of(context).size.width,
- child: SingleChildScrollView(
- physics: const NeverScrollableScrollPhysics(),
- child: Container(
- transform: Matrix4.translationValues(0, -72.px, 0),
- child: Image.memory(widget.byteData),
- ),
- ),
- ),pixelRatio: 0.6)
- .then((value) {
- imgData = value;
- });
- }
- getPlatform() async {
- bool result = js.context
- .callMethod('isWechatBrowser'); //await DdJsUtil.isWeChatBrowser;
- setState(() {
- isWechatBrowser = result;
- });
- // js.context.callMethod('shareSys');
- }
- share() {
- setState(() {
- showShareGuide = true;
- });
- String url = "data:image/png;base64," +
- base64Encode(imgData != null ? imgData! : widget.byteData);
- js.context.callMethod('shareSys', [url, '?u=' + Global().uid]);
- }
- copy() {}
- @override
- Widget build(BuildContext context) {
- SizeFit.initialize(context);
- String url = "data:image/png;base64," + base64Encode(widget.byteData);
- // js.context.callMethod('shareSys');
- return Material(
- color: Colors.transparent,
- child: Stack(
- children: [
- Positioned(
- top: 0,
- right: 0,
- bottom: 0,
- left: 0,
- child: GestureDetector(
- onTap: () {
- Navigator.of(context).pop();
- },
- child: Container(
- width: MediaQuery.of(context).size.width,
- height: MediaQuery.of(context).size.height,
- color: Colors.transparent,
- ),
- )),
- if (showShareGuide && isWechatBrowser)
- Positioned(
- right: 21.px,
- top: 12.px,
- child: Image.asset(
- 'assets/images/share_arrow_up.png',
- width: 40.px,
- height: 46.px,
- )),
- if (showShareGuide && isWechatBrowser)
- Positioned(
- right: 81.px,
- top: 40.px,
- child: Text(
- '点击…打开分享菜\n单,选择你要分享\n的好友',
- style: TextStyle(
- color: Colors.white,
- fontSize: 20.px,
- fontWeight: FontWeight.bold,
- height: 1.8),
- )),
- if (showShareGuide && !isWechatBrowser)
- Positioned(
- left: 156.px,
- bottom: 46.px,
- child: Image.asset(
- 'assets/images/share_arrow_down.png',
- width: 40.px,
- height: 46.px,
- )),
- if (showShareGuide && !isWechatBrowser)
- Positioned(
- left: 0,
- right: 0,
- bottom: 112.px,
- child: Text(
- '点击分享菜单,选\n择你要分享的平台',
- textAlign: TextAlign.center,
- style: TextStyle(
- color: Colors.white,
- fontSize: 20.px,
- fontWeight: FontWeight.bold,
- height: 1.8),
- )),
- if (!showShareGuide)
- Positioned(
- right: 24.px,
- top: 24.px,
- child: GestureDetector(
- onTap: () {
- Navigator.of(context).pop();
- },
- child: SvgPicture.asset(
- 'assets/icons/close.svg',
- width: 24.px,
- height: 24.px,
- ),
- )),
- if (!showShareGuide)
- Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Container(
- width: 200.px,
- height: MediaQuery.of(context).size.height / (375 / 200.0),
- child: WebImage(
- url: url,
- width: 200.px,
- height:
- MediaQuery.of(context).size.height / (375 / 200.0),
- )
- // Image.memory(
- // widget.byteData,
- // width: 200.px,
- // height: MediaQuery.of(context).size.height / (375 / 200.0),
- // fit: BoxFit.cover,
- // ),
- ),
- SizedBox(
- height: 53.px,
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- GestureDetector(
- onTap: () {
- share();
- },
- child: Column(
- children: [
- Image.asset(
- 'assets/images/share_weibo.png',
- width: 44.px,
- height: 44.px,
- ),
- SizedBox(
- height: 11.px,
- ),
- Text(
- '微博',
- style:
- TextStyle(color: Colors.white, fontSize: 11.px),
- )
- ],
- ),
- ),
- SizedBox(
- width: 24.px,
- ),
- GestureDetector(
- onTap: () {
- share();
- },
- child: Column(
- children: [
- Image.asset(
- 'assets/images/share_wechat.png',
- width: 44.px,
- height: 44.px,
- ),
- SizedBox(
- height: 11.px,
- ),
- Text(
- '微信',
- style:
- TextStyle(color: Colors.white, fontSize: 11.px),
- )
- ],
- ),
- ),
- SizedBox(
- width: 24.px,
- ),
- GestureDetector(
- onTap: () {
- share();
- },
- child: Column(
- children: [
- Image.asset(
- 'assets/images/share_qq.png',
- width: 44.px,
- height: 44.px,
- ),
- SizedBox(
- height: 11.px,
- ),
- Text(
- 'QQ',
- style:
- TextStyle(color: Colors.white, fontSize: 11.px),
- )
- ],
- ),
- ),
- SizedBox(
- width: 24.px,
- ),
- GestureDetector(
- onTap: () {
- copy();
- },
- child: Column(
- children: [
- Image.asset(
- 'assets/images/share_link.png',
- width: 44.px,
- height: 44.px,
- ),
- SizedBox(
- height: 11.px,
- ),
- Text(
- '复制链接',
- style:
- TextStyle(color: Colors.white, fontSize: 11.px),
- )
- ],
- ),
- ),
- ],
- )
- ],
- ),
- ],
- ),
- );
- }
- }
|