123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- import 'dart:io';
- import 'dart:typed_data';
- import 'dart:ui';
- import 'package:flutter/material.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/rendering.dart';
- import 'package:fluwx/fluwx.dart';
- import 'package:fluwx/fluwx.dart' as fluwx;
- import 'package:image_gallery_saver/image_gallery_saver.dart';
- import 'package:jpush_flutter/jpush_flutter.dart';
- import 'package:permission_handler/permission_handler.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:ysairplane2/code/YSAboutUs.dart';
- import 'package:ysairplane2/code/YSCollection.dart';
- import 'package:ysairplane2/code/YSFeedback.dart';
- import 'package:ysairplane2/code/YSMoney.dart';
- import 'package:ysairplane2/code/YSSetting.dart';
- import 'package:ysairplane2/code/YSTabbar.dart';
- import 'package:ysairplane2/code/YSUnionHome.dart';
- import 'package:ysairplane2/code/YSUnionJoin.dart';
- import 'package:ysairplane2/code/YSUserInfo.dart';
- import 'package:ysairplane2/tools/YSNetWorking.dart';
- import 'package:ysairplane2/tools/YSTools.dart';
- import 'YSSettleIn.dart';
- class YSMine extends StatefulWidget {
- @override
- _YSMineState createState() => _YSMineState();
- }
- class _YSMineState extends State<YSMine> with AutomaticKeepAliveClientMixin{
- Map _msgDict;
- List _titleArray = [{'title':'钱包','img':'money'},{'title':'行程','img':'travel'},{'title':'收藏','img':'collection'},{'title':'反馈','img':'feedback'}
- ,{'title':'入驻','img':'入驻'},{'title':'邀请好友 ','img':'fenxiang'},{'title':'顺翔联盟','img':'联盟'},{'title':'设置','img':'setting'}
- ,{'title':'关于我们','img':'guanyuwomen'}];
- @override
- bool get wantKeepAlive => true;
- @override
- void initState() {
- Future.delayed(Duration(seconds: 0)).then((value){
- _getUserData();
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- return Scaffold(
- backgroundColor: Color(0xFFF5F6F8),
- body: SingleChildScrollView(
- child: Column(
- children: [
- Container(
- height: MediaQuery.of(context).padding.top+200,
- width: MediaQuery.of(context).size.width,
- decoration: BoxDecoration(
- color: Color(0xFF00A8FF),
- // image: DecorationImage(
- // image: AssetImage('lib/images/top.png'),
- // fit: BoxFit.fill
- // ),
- ),
- child: Stack(
- children: [
- // Container(
- // margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+30,left: MediaQuery.of(context).size.width-50),
- // child: Icon(Icons.settings,size: 25,color: Colors.white,),
- // ),
- Container(
- margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+100,left: 20,right: 10),
- height: 70,
- width: 70,
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(35))
- ),
- child: _msgDict!=null?ClipRRect(
- borderRadius: BorderRadius.all(Radius.circular(35)),
- child: ysImageLoad(
- imageUrl: '${_msgDict['avatar']}',
- fit: BoxFit.fill,
- height: 70,
- width: 70,
- ),
- ):Container(),
- ),
- Container(
- margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+110,left: 100),
- width: MediaQuery.of(context).size.width-150,
- child: Text(_msgDict!=null?'${_msgDict['nickname']}':'',style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold),overflow: TextOverflow.ellipsis,),
- ),
- if(_msgDict!=null)Container(
- margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+145,left: 100),
- child: Row(
- children: [
- Container(
- child: Row(
- children: [
- Text(getSecretStr('${_msgDict['phoneNumber']}'),style: TextStyle(fontSize: 10,color: Colors.white),),
- Icon(Icons.keyboard_arrow_right,size: 15,color: Colors.white,),
- ],
- ),
- height: 20,
- alignment: Alignment.center,
- padding: EdgeInsets.only(left: 10,right: 5),
- decoration: BoxDecoration(
- color: Color(0xFF009DFF).withOpacity(0.6),
- borderRadius: BorderRadius.all(Radius.circular(10))
- ),
- ),
- // GestureDetector(
- // onTap: (){
- // Navigator.of(context,rootNavigator: true).push(
- // CupertinoPageRoute(
- // builder: (context){
- // return YSVipCode();
- // }
- // )
- // );
- // },
- // child: Container(
- // child: Row(
- // children: [
- // Icon(Icons.crop_square,size: 15,color: Colors.white,),
- // Text('会员码',style: TextStyle(fontSize: 10,color: Colors.white),),
- // ],
- // ),
- // height: 20,
- // alignment: Alignment.center,
- // margin: EdgeInsets.only(left: 5),
- // padding: EdgeInsets.only(left: 5,right: 10),
- // decoration: BoxDecoration(
- // color: Color(0xFF009DFF).withOpacity(0.6),
- // borderRadius: BorderRadius.all(Radius.circular(10))
- // ),
- // ),
- // )
- ],
- )
- ),
- GestureDetector(
- onTap: (){
- Navigator.of(context,rootNavigator: true).push(
- CupertinoPageRoute(
- builder: (context){
- return YSUserInfo();
- }
- )
- );
- },
- child: Container(
- margin: EdgeInsets.only(left: MediaQuery.of(context).size.width-50,top: MediaQuery.of(context).padding.top+120),
- child: Icon(Icons.keyboard_arrow_right,size: 30,color: Colors.white,),
- ),
- )
- ],
- ),
- ),
- Container(
- child: ListView.separated(
- shrinkWrap: true,
- itemBuilder: (context,index){
- Map item = _titleArray[index];
- return GestureDetector(
- onTap: () async{
- if(index==1){
- ShowNotification(true).dispatch(context);
- }else if(index==5){
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/shareFriend',parameter: {},isLoading: false,isToken: true);
- if(dict!=null){
- showGeneralDialog(
- context: context,
- pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
- return YSShareView(shareItem: dict['data'],);
- },
- );
- }
- }else if(index==6){
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/servants/getUnionText',parameter: {},isLoading: false,isToken: true);
- if(dict!=null){
- int audit = dict['audit'];
- print(audit);
- Navigator.of(context,rootNavigator: true).push(
- CupertinoPageRoute(
- builder: (context){
- return audit==0?YSUnionJoin(content: dict['data'],):
- audit==1||audit==3?YSUnionLoading(isLoading: audit==1,msg: dict['msg'],):
- YSUnionHome();
- }
- )
- );
- }
- }else{
- Navigator.of(context,rootNavigator: true).push(
- CupertinoPageRoute(
- builder: (context){
- return index==0?YSMoney():index==2?YSCollection():index==3?YSFeedback():
- index==4?YSSettleIn():index==7?YSSetting():YSAboutUs();
- }
- )
- );
- }
- },
- child: Container(
- height: 50,
- color: Colors.white,
- padding: EdgeInsets.only(left: 15,right: 15),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Row(
- children: [
- Container(
- child: Image.asset('lib/images/${item['img']}.png'),
- height: 20,
- width: 20,
- margin: EdgeInsets.only(right: 13),
- ),
- Text('${item['title']}',style: TextStyle(fontSize: 16,color: Color(0xFF000000)),)
- ],
- ),
- Icon(Icons.keyboard_arrow_right,size: 25,color: Color(0xFFCDCDCD),)
- ],
- ),
- ),
- );
- },
- separatorBuilder: (context,index){
- return Container(
- color: Color(0xFFF5F6F8),
- height: index==0||index==3||index==6?10:0.5,
- );
- },
- itemCount: _titleArray.length,
- padding: EdgeInsets.all(0),
- physics: NeverScrollableScrollPhysics(),
- ),
- )
- ],
- ),
- ),
- );
- }
- _getUserData() async{
- SharedPreferences prefer = await SharedPreferences.getInstance();
- Map dict = await ysRequestHttp(context, type: requestType.get, api: '/app/applets/center/info', parameter: {},
- isLoading: false,refresh: (){},isToken: true);
- if(dict!=null){
- _msgDict = dict['data'];
- final JPush jpush = new JPush();
- jpush.setAlias(_msgDict['phoneNumber']);
- setState(() {
- prefer.setString('name', '${_msgDict['nickname']}');
- prefer.setString('phone', '${_msgDict['phoneNumber']}');
- prefer.setString('avatar', '${_msgDict['avatar']}');
- });
- }
- }
- }
- class YSShareView extends StatefulWidget {
- final shareItem;
- const YSShareView({Key key, this.shareItem}) : super(key: key);
- @override
- _YSShareViewState createState() => _YSShareViewState();
- }
- class _YSShareViewState extends State<YSShareView> {
- GlobalKey _rootWidgetKey = GlobalKey();
- Uint8List _pngBytes;
- @override
- void initState() {
- Future.delayed(Duration(milliseconds: 500)).then((value){
- _capturePng(_rootWidgetKey);
- });
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Container(
- height: MediaQuery.of(context).size.height,
- width: MediaQuery.of(context).size.width,
- child: Column(
- children: [
- Container(
- height: MediaQuery.of(context).size.height-hsp(300),
- width: MediaQuery.of(context).size.width-hsp(100),
- padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(50),bottom: hsp(50)),
- child: RepaintBoundary(
- key: _rootWidgetKey,
- child: Container(
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(5))
- ),
- padding: EdgeInsets.all(hsp(20)),
- child: LayoutBuilder(
- builder: (context,conSize){
- return Column(
- children: [
- Container(
- child: GestureDetector(
- child: Icon(Icons.close,size: hsp(40),color: Colors.black,),
- onTap: (){Navigator.pop(context);},
- ),
- alignment: Alignment.centerRight,
- margin: EdgeInsets.only(bottom: hsp(20)),
- ),
- Container(
- height: conSize.maxHeight-hsp(350),
- decoration: BoxDecoration(
- image: DecorationImage(image: NetworkImage(widget.shareItem['picture']),fit: BoxFit.fill)
- ),
- ),
- Container(
- height: hsp(200),
- margin: EdgeInsets.only(top: hsp(40)),
- child: Row(
- children: [
- Container(
- width: conSize.maxWidth-hsp(200),
- child: Row(
- children: [
- Container(
- height: hsp(120),
- width: hsp(120),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(50)),
- image: DecorationImage(image: NetworkImage(widget.shareItem['avatar']),fit: BoxFit.fill)
- ),
- ),
- Container(
- width: conSize.maxWidth-hsp(340),
- padding: EdgeInsets.only(left: hsp(10)),
- child: Column(
- children: [
- Text(widget.shareItem['nickName'],style: TextStyle(fontSize: zsp(30),color: Colors.black,decoration: TextDecoration.none,
- fontWeight: FontWeight.normal),),
- Text(widget.shareItem['slogan'],style: TextStyle(fontSize: zsp(28),color: Color(0xFF999999),decoration: TextDecoration.none,
- fontWeight: FontWeight.normal),maxLines: 2,overflow: TextOverflow.ellipsis,)
- ],
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- ),
- )
- ],
- ),
- padding: EdgeInsets.only(right: hsp(20)),
- ),
- Image.network(widget.shareItem['${Platform.isAndroid==true?'androidCode':'iosCode'}'],height: hsp(200),width: hsp(200),),
- ],
- ),
- )
- ],
- );
- },
- ),
- ),
- ),
- ),
- Container(
- height: hsp(300),
- color: Colors.white,
- child: ListView.separated(
- itemBuilder: (context,index){
- return GestureDetector(
- onTap: (){
- Future.delayed(Duration(milliseconds: 500)).then((value){
- if(index==0){
- WeChatScene scene = WeChatScene.SESSION;
- fluwx.shareToWeChat(fluwx.WeChatShareImageModel(
- WeChatImage.binary(_pngBytes),
- scene: scene,
- ));
- }else{
- _saveImage();
- }
- });
- },
- behavior: HitTestBehavior.opaque,
- child: Container(
- alignment: Alignment.center,
- width: MediaQuery.of(context).size.width/2-hsp(1),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Container(
- height: MediaQuery.of(context).size.width/8,
- width: MediaQuery.of(context).size.width/8,
- child: Image.asset('lib/images/${index==0?'wexinLogo':'xiazai-tianchong'}.png'),
- margin: EdgeInsets.only(bottom: hsp(20)),
- ),
- Text(index==0?'微信好友':'保存本地',style: TextStyle(fontSize: zsp(30),color: Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal),)
- ],
- ),
- ),
- );
- },
- separatorBuilder: (context,index){
- return Container(
- width: hsp(2),
- color: Color(0xFFE2E2E2),
- margin: EdgeInsets.only(top: hsp(75),bottom: hsp(75)),
- );
- },
- scrollDirection: Axis.horizontal,
- itemCount: 2,
- ),
- )
- ],
- ),
- );
- }
- _capturePng(GlobalKey globalKey, {double pixelRatio = 3}) async {
- try {
- RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
- var image = await boundary.toImage(pixelRatio: pixelRatio);
- ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
- _pngBytes = byteData.buffer.asUint8List();
- } catch (e) {
- print(e);
- }
- }
- _saveImage() async{
- print(_pngBytes);
- if(_pngBytes!=null){
- if (await Permission.storage.request().isGranted) {
- }else{
- Map<Permission, PermissionStatus> statuses = await [
- Permission.storage,
- ].request();
- if(statuses[Permission.storage].isDenied){
- return;
- }
- print('==============C ${statuses[Permission.location]}');
- }
- final result = await ImageGallerySaver.saveImage(_pngBytes);
- print(result);
- if(result['isSuccess']){
- ysFlutterToast(context,'图片已保存到${Platform.isAndroid?result['filePath']:'相册'}');
- }
- }
- }
- }
|