YSMine.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. import 'dart:io';
  2. import 'dart:typed_data';
  3. import 'dart:ui';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/cupertino.dart';
  6. import 'package:flutter/rendering.dart';
  7. import 'package:fluwx/fluwx.dart';
  8. import 'package:fluwx/fluwx.dart' as fluwx;
  9. import 'package:image_gallery_saver/image_gallery_saver.dart';
  10. import 'package:jpush_flutter/jpush_flutter.dart';
  11. import 'package:permission_handler/permission_handler.dart';
  12. import 'package:shared_preferences/shared_preferences.dart';
  13. import 'package:ysairplane2/code/YSAboutUs.dart';
  14. import 'package:ysairplane2/code/YSCollection.dart';
  15. import 'package:ysairplane2/code/YSFeedback.dart';
  16. import 'package:ysairplane2/code/YSMoney.dart';
  17. import 'package:ysairplane2/code/YSSetting.dart';
  18. import 'package:ysairplane2/code/YSTabbar.dart';
  19. import 'package:ysairplane2/code/YSUnionHome.dart';
  20. import 'package:ysairplane2/code/YSUnionJoin.dart';
  21. import 'package:ysairplane2/code/YSUserInfo.dart';
  22. import 'package:ysairplane2/tools/YSNetWorking.dart';
  23. import 'package:ysairplane2/tools/YSTools.dart';
  24. import 'YSSettleIn.dart';
  25. class YSMine extends StatefulWidget {
  26. @override
  27. _YSMineState createState() => _YSMineState();
  28. }
  29. class _YSMineState extends State<YSMine> with AutomaticKeepAliveClientMixin{
  30. Map _msgDict;
  31. List _titleArray = [{'title':'钱包','img':'money'},{'title':'行程','img':'travel'},{'title':'收藏','img':'collection'},{'title':'反馈','img':'feedback'}
  32. ,{'title':'入驻','img':'入驻'},{'title':'邀请好友 ','img':'fenxiang'},{'title':'顺翔联盟','img':'联盟'},{'title':'设置','img':'setting'}
  33. ,{'title':'关于我们','img':'guanyuwomen'}];
  34. @override
  35. bool get wantKeepAlive => true;
  36. @override
  37. void initState() {
  38. Future.delayed(Duration(seconds: 0)).then((value){
  39. _getUserData();
  40. });
  41. super.initState();
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. super.build(context);
  46. return Scaffold(
  47. backgroundColor: Color(0xFFF5F6F8),
  48. body: SingleChildScrollView(
  49. child: Column(
  50. children: [
  51. Container(
  52. height: MediaQuery.of(context).padding.top+200,
  53. width: MediaQuery.of(context).size.width,
  54. decoration: BoxDecoration(
  55. color: Color(0xFF00A8FF),
  56. // image: DecorationImage(
  57. // image: AssetImage('lib/images/top.png'),
  58. // fit: BoxFit.fill
  59. // ),
  60. ),
  61. child: Stack(
  62. children: [
  63. // Container(
  64. // margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+30,left: MediaQuery.of(context).size.width-50),
  65. // child: Icon(Icons.settings,size: 25,color: Colors.white,),
  66. // ),
  67. Container(
  68. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+100,left: 20,right: 10),
  69. height: 70,
  70. width: 70,
  71. decoration: BoxDecoration(
  72. color: Colors.white,
  73. borderRadius: BorderRadius.all(Radius.circular(35))
  74. ),
  75. child: _msgDict!=null?ClipRRect(
  76. borderRadius: BorderRadius.all(Radius.circular(35)),
  77. child: ysImageLoad(
  78. imageUrl: '${_msgDict['avatar']}',
  79. fit: BoxFit.fill,
  80. height: 70,
  81. width: 70,
  82. ),
  83. ):Container(),
  84. ),
  85. Container(
  86. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+110,left: 100),
  87. width: MediaQuery.of(context).size.width-150,
  88. child: Text(_msgDict!=null?'${_msgDict['nickname']}':'',style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold),overflow: TextOverflow.ellipsis,),
  89. ),
  90. if(_msgDict!=null)Container(
  91. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+145,left: 100),
  92. child: Row(
  93. children: [
  94. Container(
  95. child: Row(
  96. children: [
  97. Text(getSecretStr('${_msgDict['phoneNumber']}'),style: TextStyle(fontSize: 10,color: Colors.white),),
  98. Icon(Icons.keyboard_arrow_right,size: 15,color: Colors.white,),
  99. ],
  100. ),
  101. height: 20,
  102. alignment: Alignment.center,
  103. padding: EdgeInsets.only(left: 10,right: 5),
  104. decoration: BoxDecoration(
  105. color: Color(0xFF009DFF).withOpacity(0.6),
  106. borderRadius: BorderRadius.all(Radius.circular(10))
  107. ),
  108. ),
  109. // GestureDetector(
  110. // onTap: (){
  111. // Navigator.of(context,rootNavigator: true).push(
  112. // CupertinoPageRoute(
  113. // builder: (context){
  114. // return YSVipCode();
  115. // }
  116. // )
  117. // );
  118. // },
  119. // child: Container(
  120. // child: Row(
  121. // children: [
  122. // Icon(Icons.crop_square,size: 15,color: Colors.white,),
  123. // Text('会员码',style: TextStyle(fontSize: 10,color: Colors.white),),
  124. // ],
  125. // ),
  126. // height: 20,
  127. // alignment: Alignment.center,
  128. // margin: EdgeInsets.only(left: 5),
  129. // padding: EdgeInsets.only(left: 5,right: 10),
  130. // decoration: BoxDecoration(
  131. // color: Color(0xFF009DFF).withOpacity(0.6),
  132. // borderRadius: BorderRadius.all(Radius.circular(10))
  133. // ),
  134. // ),
  135. // )
  136. ],
  137. )
  138. ),
  139. GestureDetector(
  140. onTap: (){
  141. Navigator.of(context,rootNavigator: true).push(
  142. CupertinoPageRoute(
  143. builder: (context){
  144. return YSUserInfo();
  145. }
  146. )
  147. );
  148. },
  149. child: Container(
  150. margin: EdgeInsets.only(left: MediaQuery.of(context).size.width-50,top: MediaQuery.of(context).padding.top+120),
  151. child: Icon(Icons.keyboard_arrow_right,size: 30,color: Colors.white,),
  152. ),
  153. )
  154. ],
  155. ),
  156. ),
  157. Container(
  158. child: ListView.separated(
  159. shrinkWrap: true,
  160. itemBuilder: (context,index){
  161. Map item = _titleArray[index];
  162. return GestureDetector(
  163. onTap: () async{
  164. if(index==1){
  165. ShowNotification(true).dispatch(context);
  166. }else if(index==5){
  167. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/shareFriend',parameter: {},isLoading: false,isToken: true);
  168. if(dict!=null){
  169. showGeneralDialog(
  170. context: context,
  171. pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
  172. return YSShareView(shareItem: dict['data'],);
  173. },
  174. );
  175. }
  176. }else if(index==6){
  177. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/getUnionText',parameter: {},isLoading: false,isToken: true);
  178. if(dict!=null){
  179. int audit = dict['audit'];
  180. print(audit);
  181. Navigator.of(context,rootNavigator: true).push(
  182. CupertinoPageRoute(
  183. builder: (context){
  184. return audit==0?YSUnionJoin(content: dict['data'],):
  185. audit==1||audit==3?YSUnionLoading(isLoading: audit==1,msg: dict['msg'],):
  186. YSUnionHome();
  187. }
  188. )
  189. );
  190. }
  191. }else{
  192. Navigator.of(context,rootNavigator: true).push(
  193. CupertinoPageRoute(
  194. builder: (context){
  195. return index==0?YSMoney():index==2?YSCollection():index==3?YSFeedback():
  196. index==4?YSSettleIn():index==7?YSSetting():YSAboutUs();
  197. }
  198. )
  199. );
  200. }
  201. },
  202. child: Container(
  203. height: 50,
  204. color: Colors.white,
  205. padding: EdgeInsets.only(left: 15,right: 15),
  206. child: Row(
  207. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  208. children: [
  209. Row(
  210. children: [
  211. Container(
  212. child: Image.asset('lib/images/${item['img']}.png'),
  213. height: 20,
  214. width: 20,
  215. margin: EdgeInsets.only(right: 13),
  216. ),
  217. Text('${item['title']}',style: TextStyle(fontSize: 16,color: Color(0xFF000000)),)
  218. ],
  219. ),
  220. Icon(Icons.keyboard_arrow_right,size: 25,color: Color(0xFFCDCDCD),)
  221. ],
  222. ),
  223. ),
  224. );
  225. },
  226. separatorBuilder: (context,index){
  227. return Container(
  228. color: Color(0xFFF5F6F8),
  229. height: index==0||index==3||index==6?10:0.5,
  230. );
  231. },
  232. itemCount: _titleArray.length,
  233. padding: EdgeInsets.all(0),
  234. physics: NeverScrollableScrollPhysics(),
  235. ),
  236. )
  237. ],
  238. ),
  239. ),
  240. );
  241. }
  242. _getUserData() async{
  243. SharedPreferences prefer = await SharedPreferences.getInstance();
  244. Map dict = await ysRequestHttp(context, type: requestType.get, api: '/app/applets/center/info', parameter: {},
  245. isLoading: false,refresh: (){},isToken: true);
  246. if(dict!=null){
  247. _msgDict = dict['data'];
  248. final JPush jpush = new JPush();
  249. jpush.setAlias(_msgDict['phoneNumber']);
  250. setState(() {
  251. prefer.setString('name', '${_msgDict['nickname']}');
  252. prefer.setString('phone', '${_msgDict['phoneNumber']}');
  253. prefer.setString('avatar', '${_msgDict['avatar']}');
  254. });
  255. }
  256. }
  257. }
  258. class YSShareView extends StatefulWidget {
  259. final shareItem;
  260. const YSShareView({Key key, this.shareItem}) : super(key: key);
  261. @override
  262. _YSShareViewState createState() => _YSShareViewState();
  263. }
  264. class _YSShareViewState extends State<YSShareView> {
  265. GlobalKey _rootWidgetKey = GlobalKey();
  266. Uint8List _pngBytes;
  267. @override
  268. void initState() {
  269. Future.delayed(Duration(milliseconds: 500)).then((value){
  270. _capturePng(_rootWidgetKey);
  271. });
  272. super.initState();
  273. }
  274. @override
  275. Widget build(BuildContext context) {
  276. return Container(
  277. height: MediaQuery.of(context).size.height,
  278. width: MediaQuery.of(context).size.width,
  279. child: Column(
  280. children: [
  281. Container(
  282. height: MediaQuery.of(context).size.height-hsp(300),
  283. width: MediaQuery.of(context).size.width-hsp(100),
  284. padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(50),bottom: hsp(50)),
  285. child: RepaintBoundary(
  286. key: _rootWidgetKey,
  287. child: Container(
  288. decoration: BoxDecoration(
  289. color: Colors.white,
  290. borderRadius: BorderRadius.all(Radius.circular(5))
  291. ),
  292. padding: EdgeInsets.all(hsp(20)),
  293. child: LayoutBuilder(
  294. builder: (context,conSize){
  295. return Column(
  296. children: [
  297. Container(
  298. child: GestureDetector(
  299. child: Icon(Icons.close,size: hsp(40),color: Colors.black,),
  300. onTap: (){Navigator.pop(context);},
  301. ),
  302. alignment: Alignment.centerRight,
  303. margin: EdgeInsets.only(bottom: hsp(20)),
  304. ),
  305. Container(
  306. height: conSize.maxHeight-hsp(350),
  307. decoration: BoxDecoration(
  308. image: DecorationImage(image: NetworkImage(widget.shareItem['picture']),fit: BoxFit.fill)
  309. ),
  310. ),
  311. Container(
  312. height: hsp(200),
  313. margin: EdgeInsets.only(top: hsp(40)),
  314. child: Row(
  315. children: [
  316. Container(
  317. width: conSize.maxWidth-hsp(200),
  318. child: Row(
  319. children: [
  320. Container(
  321. height: hsp(120),
  322. width: hsp(120),
  323. decoration: BoxDecoration(
  324. borderRadius: BorderRadius.all(Radius.circular(50)),
  325. image: DecorationImage(image: NetworkImage(widget.shareItem['avatar']),fit: BoxFit.fill)
  326. ),
  327. ),
  328. Container(
  329. width: conSize.maxWidth-hsp(340),
  330. padding: EdgeInsets.only(left: hsp(10)),
  331. child: Column(
  332. children: [
  333. Text(widget.shareItem['nickName'],style: TextStyle(fontSize: zsp(30),color: Colors.black,decoration: TextDecoration.none,
  334. fontWeight: FontWeight.normal),),
  335. Text(widget.shareItem['slogan'],style: TextStyle(fontSize: zsp(28),color: Color(0xFF999999),decoration: TextDecoration.none,
  336. fontWeight: FontWeight.normal),maxLines: 2,overflow: TextOverflow.ellipsis,)
  337. ],
  338. mainAxisSize: MainAxisSize.min,
  339. crossAxisAlignment: CrossAxisAlignment.start,
  340. ),
  341. )
  342. ],
  343. ),
  344. padding: EdgeInsets.only(right: hsp(20)),
  345. ),
  346. Image.network(widget.shareItem['${Platform.isAndroid==true?'androidCode':'iosCode'}'],height: hsp(200),width: hsp(200),),
  347. ],
  348. ),
  349. )
  350. ],
  351. );
  352. },
  353. ),
  354. ),
  355. ),
  356. ),
  357. Container(
  358. height: hsp(300),
  359. color: Colors.white,
  360. child: ListView.separated(
  361. itemBuilder: (context,index){
  362. return GestureDetector(
  363. onTap: (){
  364. Future.delayed(Duration(milliseconds: 500)).then((value){
  365. if(index==0){
  366. WeChatScene scene = WeChatScene.SESSION;
  367. fluwx.shareToWeChat(fluwx.WeChatShareImageModel(
  368. WeChatImage.binary(_pngBytes),
  369. scene: scene,
  370. ));
  371. }else{
  372. _saveImage();
  373. }
  374. });
  375. },
  376. behavior: HitTestBehavior.opaque,
  377. child: Container(
  378. alignment: Alignment.center,
  379. width: MediaQuery.of(context).size.width/2-hsp(1),
  380. child: Column(
  381. mainAxisSize: MainAxisSize.min,
  382. children: [
  383. Container(
  384. height: MediaQuery.of(context).size.width/8,
  385. width: MediaQuery.of(context).size.width/8,
  386. child: Image.asset('lib/images/${index==0?'wexinLogo':'xiazai-tianchong'}.png'),
  387. margin: EdgeInsets.only(bottom: hsp(20)),
  388. ),
  389. Text(index==0?'微信好友':'保存本地',style: TextStyle(fontSize: zsp(30),color: Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal),)
  390. ],
  391. ),
  392. ),
  393. );
  394. },
  395. separatorBuilder: (context,index){
  396. return Container(
  397. width: hsp(2),
  398. color: Color(0xFFE2E2E2),
  399. margin: EdgeInsets.only(top: hsp(75),bottom: hsp(75)),
  400. );
  401. },
  402. scrollDirection: Axis.horizontal,
  403. itemCount: 2,
  404. ),
  405. )
  406. ],
  407. ),
  408. );
  409. }
  410. _capturePng(GlobalKey globalKey, {double pixelRatio = 3}) async {
  411. try {
  412. RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
  413. var image = await boundary.toImage(pixelRatio: pixelRatio);
  414. ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
  415. _pngBytes = byteData.buffer.asUint8List();
  416. } catch (e) {
  417. print(e);
  418. }
  419. }
  420. _saveImage() async{
  421. print(_pngBytes);
  422. if(_pngBytes!=null){
  423. if (await Permission.storage.request().isGranted) {
  424. }else{
  425. Map<Permission, PermissionStatus> statuses = await [
  426. Permission.storage,
  427. ].request();
  428. if(statuses[Permission.storage].isDenied){
  429. return;
  430. }
  431. print('==============C ${statuses[Permission.location]}');
  432. }
  433. final result = await ImageGallerySaver.saveImage(_pngBytes);
  434. print(result);
  435. if(result['isSuccess']){
  436. ysFlutterToast(context,'图片已保存到${Platform.isAndroid?result['filePath']:'相册'}');
  437. }
  438. }
  439. }
  440. }