From bd352fd7aef6e099e8523b4940c21bf1a6079e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyanghuaxuan=E2=80=9D?= <“646903573@qq.com”> Date: Tue, 9 Mar 2021 17:21:52 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0=E5=88=86=E4=BA=AB=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=9A=84=E6=B8=85=E6=99=B0=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainActivity.java | 6 +- example/lib/main.dart | 72 +++--- .../goods_share_image/goods_share_image.dart | 2 +- .../mine_detail_page/mine_detail_page.dart | 3 +- lib/widgets/share/share_alert_select.dart | 206 ++++++++---------- 5 files changed, 136 insertions(+), 153 deletions(-) diff --git a/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java b/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java index 33e1cda..14272b9 100644 --- a/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java +++ b/example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java @@ -154,9 +154,9 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN @Override public Map getSetting() { Map map = new HashMap(); - map.put("domain", "http://inapi.izhyin.cn/"); //"http://120.76.175.204:8989"); - // map.put("domain", "http://api.zhios.cn/");//45678910,api.zhios.cn68703914 - map.put("master_id", "123456"); + //map.put("domain", "http://inapi.izhyin.cn/"); //"http://120.76.175.204:8989"); + map.put("domain", "http://api.zhios.cn/");//45678910,api.zhios.cn68703914 + map.put("master_id", "68703914"); map.put("secret_key", "123456"); // map.put("token", "123465"); return map; diff --git a/example/lib/main.dart b/example/lib/main.dart index bce11b8..702ae8e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -88,39 +88,47 @@ class _MyAppState extends State { providers: [ ChangeNotifierProvider.value(value: UserInfoNotifier()), ], - child: MaterialApp( - builder: (context,child){ - return MediaQuery( - //设置文字大小不随系统设置改变 - data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), - child: child, - ); + child: GestureDetector( + onTap: (){ + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) { + FocusManager.instance.primaryFocus.unfocus(); + } }, - theme: ThemeData( - fontFamily: 'PingFang', - primaryColor: HexColor.fromHex('#FF4242'), - accentColor: HexColor.fromHex('#FF4242'), - ), - routes: { - '/homePage': (BuildContext context) => HomePage(), - }, - navigatorKey: navigatorKey, - localizationsDelegates: [ - RefreshLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - CommonLocalizationsDelegate(), - ], - supportedLocales: [ - const Locale('en'), - const Locale('zh'), - ], - localeResolutionCallback: (Locale locale, Iterable supportedLocales) { - print("change language ${locale.toString()}"); - return locale; - }, - home: LaunchPage( - // builder: (context) => HomePage(), + child: MaterialApp( + builder: (context,child){ + return MediaQuery( + //设置文字大小不随系统设置改变 + data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), + child: child, + ); + }, + theme: ThemeData( + fontFamily: 'PingFang', + primaryColor: HexColor.fromHex('#FF4242'), + accentColor: HexColor.fromHex('#FF4242'), + ), + routes: { + '/homePage': (BuildContext context) => HomePage(), + }, + navigatorKey: navigatorKey, + localizationsDelegates: [ + RefreshLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + CommonLocalizationsDelegate(), + ], + supportedLocales: [ + const Locale('en'), + const Locale('zh'), + ], + localeResolutionCallback: (Locale locale, Iterable supportedLocales) { + print("change language ${locale.toString()}"); + return locale; + }, + home: LaunchPage( + // builder: (context) => HomePage(), + ), ), ), ); diff --git a/lib/pages/goods_share_page/goods_share_image/goods_share_image.dart b/lib/pages/goods_share_page/goods_share_image/goods_share_image.dart index 8e924c1..8af4d0e 100644 --- a/lib/pages/goods_share_page/goods_share_image/goods_share_image.dart +++ b/lib/pages/goods_share_page/goods_share_image/goods_share_image.dart @@ -368,7 +368,7 @@ class _GoodsShareImageContentState extends State<_GoodsShareImageContent> with A Loading.show(context); ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png); Uint8List pngBytes = byteData.buffer.asUint8List(); - File file = await EncodeUtil.compressImage(context,images: pngBytes, size: 200); + File file = await EncodeUtil.compressImage(context,images: pngBytes, size: 400); Loading.dismiss(); _shareModel.poster = file.readAsBytesSync(); } diff --git a/lib/pages/mine_detail_page/mine_detail_page.dart b/lib/pages/mine_detail_page/mine_detail_page.dart index a5fcb68..c5ce758 100644 --- a/lib/pages/mine_detail_page/mine_detail_page.dart +++ b/lib/pages/mine_detail_page/mine_detail_page.dart @@ -316,8 +316,9 @@ class _MineDetailContainerState extends State<_MineDetailContainer> { if (cropperFile == null) { return; } - File resultFile = await EncodeUtil.compressImage(context,file:cropperFile,size: 800); Loading.show(context); + File resultFile = await EncodeUtil.compressImage(context,file:cropperFile,size: 800); + _bloc.uploadAvatar(resultFile); } } diff --git a/lib/widgets/share/share_alert_select.dart b/lib/widgets/share/share_alert_select.dart index 062f64b..754b42a 100644 --- a/lib/widgets/share/share_alert_select.dart +++ b/lib/widgets/share/share_alert_select.dart @@ -34,9 +34,7 @@ class ShareAlertSelect extends StatefulWidget { final bool isPicShow; final ShareSelectPicModel selectPicModel; - const ShareAlertSelect(this.model, this.skipIdentifier, - {Key key, this.isContentShow = false, this.selectPicModel, this.isPicShow}) - : super(key: key); // 中间视图 + const ShareAlertSelect(this.model, this.skipIdentifier, {Key key, this.isContentShow = false, this.selectPicModel, this.isPicShow}) : super(key: key); // 中间视图 @override _ShareAlertSelectState createState() => _ShareAlertSelectState(); @@ -48,10 +46,11 @@ class _ShareAlertSelectState extends State { ShareSelectPicModel selectPicModel; GlobalKey _globalKey = GlobalKey(); + List tempPoster; + @override void initState() { - NetUtil.request('/api/v1/mod/${widget.skipIdentifier}', method: NetMethod.GET, - onCache: (data) { + NetUtil.request('/api/v1/mod/${widget.skipIdentifier}', method: NetMethod.GET, onCache: (data) { // try{ // _parseData(data); // }catch(e){ @@ -76,8 +75,7 @@ class _ShareAlertSelectState extends State { Map d = modList.first; if (d != null) { String dString = d['data']; - _iconModel = - ShareAlertModel.fromJson(Map.from(jsonDecode(dString))); + _iconModel = ShareAlertModel.fromJson(Map.from(jsonDecode(dString))); setState(() {}); } @@ -89,8 +87,15 @@ class _ShareAlertSelectState extends State { for (int i = 0; i < picList.length; i++) { if (picList[i].select) { if (i == 0) { - ShareDataModel shareDataModel = await _updateModel(_globalKey); - model.poster = shareDataModel.poster; + if (tempPoster == null) { + Loading.show(context); + ShareDataModel shareDataModel = await _updateModel(_globalKey); + tempPoster = shareDataModel.poster; + model.poster = shareDataModel.poster; + Loading.dismiss(); + } else { + model.poster = tempPoster; + } } else { model.image.add(picList[i].pic); } @@ -105,6 +110,7 @@ class _ShareAlertSelectState extends State { BuildContext buildContext = _globalKey.currentContext; if (null != buildContext) { RenderRepaintBoundary boundary = buildContext.findRenderObject(); + ///pixelRatio是放大倍数 ui.Image image = await boundary.toImage(pixelRatio: 5); // 注意:png是压缩后格式,如果需要图片的原始像素数据,请使用rawRgba @@ -182,8 +188,7 @@ class _ShareAlertSelectState extends State { right: 15, child: GestureDetector( onTap: () { - selectPicModel.picList[index].select = - !selectPicModel.picList[index].select; + selectPicModel.picList[index].select = !selectPicModel.picList[index].select; setState(() {}); _selectPic(selectPicModel.picList, index); }, @@ -191,9 +196,7 @@ class _ShareAlertSelectState extends State { alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(50), - color: selectPicModel.picList[index].select - ? Colors.red - : Colors.grey, + color: selectPicModel.picList[index].select ? Colors.red : Colors.grey, ), child: Icon( CupertinoIcons.check_mark, @@ -212,8 +215,7 @@ class _ShareAlertSelectState extends State { ), ) : Container(), - _ShareAlertContent( - widget.model, widget.skipIdentifier, _iconModel, isPicShow), + _ShareAlertContent(widget.model, widget.skipIdentifier, _iconModel, isPicShow), ], ), ), // 模糊化 @@ -233,10 +235,7 @@ class _ShareAlertContent extends StatefulWidget { final ShareAlertModel iconModel; final bool isSelectPic; - const _ShareAlertContent( - this.model, this.skipIdentifier, this.iconModel, this.isSelectPic, - {Key key}) - : super(key: key); + const _ShareAlertContent(this.model, this.skipIdentifier, this.iconModel, this.isSelectPic, {Key key}) : super(key: key); @override _ShareAlertContentState createState() => _ShareAlertContentState(); @@ -295,13 +294,11 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { margin: EdgeInsets.only(top: 8, bottom: 8), width: 62, height: 4, - decoration: BoxDecoration( - color: Color(0xffd8d8d8), borderRadius: BorderRadius.circular(2)), + decoration: BoxDecoration(color: Color(0xffd8d8d8), borderRadius: BorderRadius.circular(2)), ), Text( '分享至', - style: TextStyle( - fontSize: 15, color: Color(0xff333333), fontWeight: FontWeight.bold), + style: TextStyle(fontSize: 15, color: Color(0xff333333), fontWeight: FontWeight.bold), ), Container( margin: EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10), @@ -311,15 +308,11 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { child: Container( margin: EdgeInsets.only(left: 12, right: 12, bottom: 10), padding: EdgeInsets.all(12), - decoration: BoxDecoration( - color: Color(0xfff3f3f3), borderRadius: BorderRadius.circular(8)), + decoration: BoxDecoration(color: Color(0xfff3f3f3), borderRadius: BorderRadius.circular(8)), child: Center( child: Text( '取消', - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.bold, - color: Color(0xff999999)), + style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: Color(0xff999999)), ), ), ), @@ -347,106 +340,91 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { Widget _createIcon(ShareIconModel item) { return GestureDetector( - child: Container( - width: 60, - child: Column( - children: [ - Container( - width: 40, - height: 40, - child: CachedNetworkImage( - imageUrl: item.icon, - fit: BoxFit.contain, + child: Container( + width: 60, + child: Column( + children: [ + Container( + width: 40, + height: 40, + child: CachedNetworkImage( + imageUrl: item.icon, + fit: BoxFit.contain, + ), ), - ), - Padding( - padding: const EdgeInsets.only(top: 2, bottom: 2), - child: Text( - item.name, - style: TextStyle( - fontSize: 12, color: Color(0xff333333), fontWeight: FontWeight.bold), + Padding( + padding: const EdgeInsets.only(top: 2, bottom: 2), + child: Text( + item.name, + style: TextStyle(fontSize: 12, color: Color(0xff333333), fontWeight: FontWeight.bold), + ), ), - ), - ], + ], + ), ), - ), - onTap: () async { - - Loading.show(context); - - await Future.delayed(Duration(seconds: 2)); - - if(_shareDataModel.image!=null){ - for(var image in _shareDataModel.image){ - File file = await EncodeUtil.compressImage(context,file: File(image), size: 200); - image=file.path; + onTap: () async { + //检查是否有存储权限 + var status = await Permission.storage.status; + if (!status.isGranted) { + status = await Permission.storage.request(); + print(status); + return; } - Loading.dismiss(); - } - - if(_shareDataModel?.poster!=null){ - File file = await EncodeUtil.compressImage(context,images: _shareDataModel?.poster, size: 200); - _shareDataModel.poster=file.readAsBytesSync(); - Loading.dismiss(); - } - + Loading.show(context); - //检查是否有存储权限 - var status = await Permission.storage.status; - if (!status.isGranted) { - status = await Permission.storage.request(); - print(status); - return; - } + ///检查是否选中图片 + if (_shareDataModel?.poster == null && (_shareDataModel?.image == null || _shareDataModel?.image?.length == 0)) { + Fluttertoast.showToast(msg: "请选择需要分享的图片"); + Loading.dismiss(); + return; + } - int count = 0; - if (_shareDataModel.poster != null) { - count++; - } - count += (_shareDataModel?.image?.length ?? 0); - // 多图分享 - if (count > 1) { - _shareMultipleImages(item.type); - return; - } + if (_shareDataModel?.poster != null) { + File file = await EncodeUtil.compressImage(context, images: _shareDataModel?.poster, size: 400); + _shareDataModel.poster = file.readAsBytesSync(); + Loading.dismiss(); + } + int count = 0; + if (_shareDataModel.poster != null) { + count++; + } + count += (_shareDataModel?.image?.length ?? 0); + // 多图分享 + if (count > 1) { + _shareMultipleImages(item.type); + return; + } - if (item.type == 'wx') { - _shareByMob(ShareSDKPlatforms.wechatSession); - } else if (item.type == 'pyq') { - _shareByMob(ShareSDKPlatforms.wechatTimeline); - } else if (item.type == 'qq') { - _shareByMob(ShareSDKPlatforms.qq); - } else if (item.type == 'qq_space') { - _shareByMob(ShareSDKPlatforms.qZone); - } else if (item.type == 'weibo') { - _shareByMob(ShareSDKPlatforms.sina); - } else if (item.type == 'more_setting') { - _shareBySystem(item.type); - } - }, - ); + if (item.type == 'wx') { + _shareByMob(ShareSDKPlatforms.wechatSession); + } else if (item.type == 'pyq') { + _shareByMob(ShareSDKPlatforms.wechatTimeline); + } else if (item.type == 'qq') { + _shareByMob(ShareSDKPlatforms.qq); + } else if (item.type == 'qq_space') { + _shareByMob(ShareSDKPlatforms.qZone); + } else if (item.type == 'weibo') { + _shareByMob(ShareSDKPlatforms.sina); + } else if (item.type == 'more_setting') { + _shareBySystem(item.type); + } + }); } - // mob分享,只能单图分享,多图分享调用系统分享 +// mob分享,只能单图分享,多图分享调用系统分享 void _shareByMob(ShareSDKPlatform plateform) async { - if (isSelectPic && - EmptyUtil.isEmpty(_shareDataModel) && - EmptyUtil.isEmpty(_shareDataModel?.poster) && - EmptyUtil.isEmpty(_shareDataModel?.image)) { + if (isSelectPic && EmptyUtil.isEmpty(_shareDataModel) && EmptyUtil.isEmpty(_shareDataModel?.poster) && EmptyUtil.isEmpty(_shareDataModel?.image)) { Fluttertoast.showToast(msg: '请选择分享图片'); return; } - Loading.show(context); Timer(Duration(milliseconds: 2000), () { Loading.dismiss(); }); - - SSDKMap params; if (_shareDataModel.poster != null) { String path = await _savePoster(); @@ -510,12 +488,9 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { }); } - // 系统分享,只能分享图片或者文字,不能组合分享 +// 系统分享,只能分享图片或者文字,不能组合分享 void _shareBySystem(String type) async { - if (isSelectPic && - EmptyUtil.isEmpty(_shareDataModel) && - EmptyUtil.isEmpty(_shareDataModel?.poster) && - EmptyUtil.isEmpty(_shareDataModel?.image)) { + if (isSelectPic && EmptyUtil.isEmpty(_shareDataModel) && EmptyUtil.isEmpty(_shareDataModel?.poster) && EmptyUtil.isEmpty(_shareDataModel?.image)) { Fluttertoast.showToast(msg: '请选择分享图片'); return; } @@ -539,7 +514,6 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { } else { ShareExtend.share(_shareDataModel.content, 'text'); } - } Future _savePoster() async { @@ -572,7 +546,7 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { return path; } - // 多图分享,调用系统分享 +// 多图分享,调用系统分享 void _shareMultipleImages(String type) async { List paths = List(); String path = await _savePoster();