MyCode.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/material.dart' as prefix0;
  3. import 'package:flutter/rendering.dart';
  4. import 'package:flutter/rendering.dart' as prefix1;
  5. import 'dart:ui';
  6. import 'dart:typed_data';
  7. import 'dart:async';
  8. import 'package:qr_flutter/qr_flutter.dart';
  9. import 'package:redux/redux.dart';
  10. import 'package:flutter_redux/flutter_redux.dart';
  11. import '../redux/AppState.dart';
  12. import '../model/UserInfo.dart';
  13. import '../widget/LinearButton.dart';
  14. import 'dart:ui' as ui;
  15. import 'dart:io';
  16. import 'package:path_provider/path_provider.dart';
  17. import '../widget/Dialog.dart';
  18. import '../net/HttpManager.dart';
  19. import '../styles/totast.dart';
  20. import '../net/Result.dart';
  21. import '../model/ChannelInfo.dart';
  22. import 'package:image_gallery_saver/image_gallery_saver.dart';
  23. import 'package:permission_handler/permission_handler.dart';
  24. class MyCode extends StatefulWidget {
  25. @override
  26. MyCodeState createState() => MyCodeState();
  27. }
  28. class MyCodeState extends State<MyCode> {
  29. ChannelInfo channelInfo;
  30. GlobalKey globalKey = new GlobalKey();
  31. // 截图boundary,并且返回图片的二进制数据。
  32. Future<Uint8List> _capturePng() async {
  33. RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
  34. ui.Image image = await boundary.toImage();
  35. // 注意:png是压缩后格式,如果需要图片的原始像素数据,请使用rawRgba
  36. ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
  37. Uint8List pngBytes = byteData.buffer.asUint8List();
  38. return pngBytes;
  39. }
  40. Future<String> _capturePath(String name) async {
  41. Directory documentsDirectory = await getExternalStorageDirectory();
  42. String path = documentsDirectory.path + name;
  43. return path;
  44. }
  45. Future<void> getChannelInfo() async {
  46. Toast.show(context, '加载中', -1, 'loading');
  47. Result res = await HttpManager.get('channelInfo/getOne', data: {'id': StoreProvider.of<AppState>(context).state.userInfo.channel});
  48. Toast.hide();
  49. if (res.success) {
  50. setState(() {
  51. channelInfo = ChannelInfo.fromJson(res.data);
  52. });
  53. }
  54. }
  55. @override
  56. void initState() {
  57. super.initState();
  58. Future.delayed(Duration.zero, () => getChannelInfo());
  59. }
  60. @override
  61. Widget build(BuildContext context) {
  62. AppBar appbar = AppBar(title: Text('我的推广码'), centerTitle: true);
  63. double _height = MediaQuery.of(context).size.height - MediaQueryData.fromWindow(window).padding.top - appbar.preferredSize.height;
  64. return StoreConnector<AppState, UserInfo>(
  65. converter: (Store store) => store.state.userInfo,
  66. builder: (context, userInfo) {
  67. String qrstr = HttpManager.baseUrl + "share?userId=${userInfo.id}&channel=${userInfo.channel}";
  68. // final cryptor = new PlatformStringCryptor();
  69. return Scaffold(
  70. appBar: appbar,
  71. body: Container(
  72. color: Color(0xFF2B2B42),
  73. height: double.infinity,
  74. width: double.infinity,
  75. child: SingleChildScrollView(
  76. child: Container(
  77. height: _height - 60,
  78. constraints: BoxConstraints(minHeight: 543),
  79. margin: EdgeInsets.symmetric(vertical: 30, horizontal: 30),
  80. color: Color(0xFF363759),
  81. child: Column(
  82. mainAxisAlignment: MainAxisAlignment.center,
  83. children: <Widget>[
  84. RepaintBoundary(
  85. key: globalKey,
  86. child: Container(
  87. width: 256,
  88. color: Color(0xFF363759),
  89. child: Column(
  90. children: <Widget>[
  91. Container(height: 36),
  92. Image.asset('images/text_yonghuduan.png'),
  93. Container(
  94. height: 7,
  95. ),
  96. Text('扫描二维码加入 ${userInfo.nickname.length <= 5 ? userInfo.nickname : userInfo.nickname.substring(0, 4) + "..."} 的电竞团队',
  97. style: TextStyle(color: Theme.of(context).primaryColor, fontSize: 14, fontWeight: FontWeight.w600)),
  98. Container(height: 25),
  99. Container(
  100. width: 150,
  101. height: 150,
  102. color: Colors.white,
  103. // padding: EdgeInsets.all(7),
  104. child: QrImage(
  105. data: qrstr,
  106. size: 150.0,
  107. ),
  108. ),
  109. Container(
  110. height: 10,
  111. ),
  112. Text(
  113. '扫一扫下载APP',
  114. style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500),
  115. ),
  116. Container(
  117. height: 30,
  118. )
  119. ],
  120. ),
  121. ),
  122. ),
  123. // Text(
  124. // channelInfo != null ? '一级队员:每购买一张就会获得${1 * 10 * channelInfo.ratio}' : '',
  125. // style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500),
  126. // ),
  127. // Text(
  128. // channelInfo != null ? '二级队员:每购买一张就会获得${1 * 10 * channelInfo.ratio2}' : '',
  129. // style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500),
  130. // ),
  131. Container(
  132. // margin: EdgeInsets.only(top: 30),
  133. width: 180,
  134. child: LinearButton(
  135. btntext: '立刻邀请',
  136. btnHeight: 44.0,
  137. colorList: [Color(0xFFD4504B), Color(0xFFD4504B)],
  138. onTapHomeMenu: () async {
  139. var permission = PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
  140. await PermissionHandler().requestPermissions(<PermissionGroup>[
  141. PermissionGroup.storage, // 在这里添加需要的权限
  142. ]);
  143. // MyDialog.showDialog(context, '手动截图立即分享二维码给小伙伴吧!');
  144. Uint8List val = await _capturePng();
  145. print(val);
  146. final result = await ImageGallerySaver.saveImage(val);
  147. print(result);
  148. Toast.show(context, '保存成功', 1500, 'success');
  149. },
  150. ),
  151. ),
  152. Container(
  153. height: 13,
  154. ),
  155. InkWell(
  156. onTap: () {
  157. Navigator.of(context).push(PageRouteBuilder(
  158. opaque: false,
  159. transitionDuration: Duration(milliseconds: 300),
  160. transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  161. return FadeTransition(
  162. opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  163. child: child,
  164. );
  165. },
  166. pageBuilder: (BuildContext context, _, __) {
  167. return Rule(0.1*channelInfo.ratio,0.1*channelInfo.ratio2);
  168. }));
  169. },
  170. child: Row(
  171. mainAxisAlignment: MainAxisAlignment.center,
  172. children: <Widget>[
  173. Text(
  174. '查看推广奖励规则',
  175. style: TextStyle(color: Theme.of(context).primaryColor),
  176. ),
  177. Image.asset('images/icon_inter_hongse.png')
  178. ],
  179. ),
  180. ),
  181. Expanded(
  182. flex: 1,
  183. child: Container(),
  184. ),
  185. Image.asset('images/img_0000.png'),
  186. ],
  187. ),
  188. ),
  189. ),
  190. ));
  191. });
  192. }
  193. }
  194. class Rule extends Dialog {
  195. Rule(this.ratio,this.ratio2);
  196. double ratio;
  197. double ratio2;
  198. @override
  199. Widget build(BuildContext context) {
  200. return WillPopScope(
  201. child: Scaffold(
  202. backgroundColor: Color(0xCC000000),
  203. body: Container(
  204. child: SizedBox.expand(
  205. child: UnconstrainedBox(
  206. child: Container(
  207. width: 280,
  208. // padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
  209. decoration: BoxDecoration(color: Color(0xFF15151D), border: Border.all(width: 1, color: Theme.of(context).primaryColor)),
  210. child: Stack(
  211. children: <Widget>[
  212. Padding(
  213. padding: EdgeInsets.symmetric(horizontal: 16, vertical: 25),
  214. child: Column(
  215. mainAxisAlignment: MainAxisAlignment.center,
  216. children: <Widget>[
  217. Text('推广奖励规则', style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w600)),
  218. Container(
  219. height: 20,
  220. ),
  221. Text('1、扫描该二维码下载APP的用户成为您的一级成员,可以在“我的团队”中查看 ', style: TextStyle(color: Colors.white, fontSize: 14)),
  222. Container(
  223. height: 20,
  224. ),
  225. Text('2、团队一级成员在APP中每购买一张参赛券,您就可以获得${ratio}个积分 ', style: TextStyle(color: Colors.white, fontSize: 14)),
  226. Container(
  227. height: 20,
  228. ),
  229. Text('3、团队二级成员在APP中每购买一张参赛券,您就可以获得${ratio2}个积分 ', style: TextStyle(color: Colors.white, fontSize: 14)),
  230. Container(
  231. height: 35,
  232. ),
  233. Container(
  234. width: double.infinity,
  235. child: LinearButton(
  236. btntext: '确认',
  237. btnHeight: 36.0,
  238. onTapHomeMenu: () {
  239. Navigator.of(context).pop();
  240. },
  241. )),
  242. Container(
  243. height: 5,
  244. )
  245. ],
  246. ),
  247. ),
  248. Positioned(
  249. top: 0,
  250. left: 0,
  251. child: Image.asset(
  252. 'images/tancuang_shang.png',
  253. // width: 131,
  254. ),
  255. ),
  256. Positioned(
  257. bottom: 0,
  258. right: 4,
  259. child: Image.asset(
  260. 'images/tancuang_xia.png',
  261. // width: 148,
  262. ),
  263. ),
  264. ],
  265. ),
  266. ),
  267. ),
  268. ),
  269. ),
  270. ),
  271. onWillPop: () {
  272. return Future.value(false);
  273. },
  274. );
  275. }
  276. }