From 015f1f34242152a24ee2e96f6c1963b6d0941a05 Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Tue, 29 Sep 2020 14:16:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dart_tool/package_config.json | 8 +- example/ios/Podfile.lock | 6 + .../goods_share_page/goods_share_bloc.dart | 41 ++++ .../goods_share_image/goods_share_image.dart | 194 ++++++++++++++++-- .../goods_share_image_model.dart | 134 ++++++++++++ .../goods_share_link/goods_share_link.dart | 11 +- .../goods_share_miniprogram.dart | 11 +- .../goods_share_page/goods_share_page.dart | 170 ++++++--------- .../models/goods_share_style_model.dart | 55 +++++ .../models/goods_share_temp_editor_model.dart | 54 +++++ .../models/goods_share_temp_model.dart | 21 ++ .../widgets/goods_share_image.dart | 29 +++ .../widgets/goods_share_item.dart | 95 ++++++--- .../goods_share_temp_util.dart | 9 + .../footer/goods_details_footer_widget.dart | 8 +- .../public/custom_button/custom_bottom.dart | 20 ++ .../custom_button/custom_button_model.dart | 40 ++++ lib/widgets/share/share_alert.dart | 24 ++- pubspec.yaml | 2 + 19 files changed, 775 insertions(+), 157 deletions(-) create mode 100644 lib/pages/goods_share_page/goods_share_bloc.dart create mode 100644 lib/pages/goods_share_page/goods_share_image/goods_share_image_model.dart create mode 100644 lib/pages/goods_share_page/models/goods_share_style_model.dart create mode 100644 lib/pages/goods_share_page/models/goods_share_temp_editor_model.dart create mode 100644 lib/pages/goods_share_page/models/goods_share_temp_model.dart create mode 100644 lib/pages/goods_share_page/widgets/goods_share_image.dart create mode 100644 lib/utils/goods_share_temp_util/goods_share_temp_util.dart create mode 100644 lib/widgets/public/custom_button/custom_bottom.dart create mode 100644 lib/widgets/public/custom_button/custom_button_model.dart diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index ed99d49..46b14a5 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -379,6 +379,12 @@ "packageUri": "lib/", "languageVersion": "2.1" }, + { + "name": "share_extend", + "rootUri": "file:///Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/share_extend-1.1.9", + "packageUri": "lib/", + "languageVersion": "2.0" + }, { "name": "shared_preferences", "rootUri": "file:///Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/shared_preferences-0.5.12", @@ -590,7 +596,7 @@ "languageVersion": "2.1" } ], - "generated": "2020-09-28T02:48:13.803350Z", + "generated": "2020-09-29T06:14:15.252464Z", "generator": "pub", "generatorVersion": "2.7.2" } diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index b005bc5..e34fb9b 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -103,6 +103,8 @@ PODS: - save_image (0.0.1): - Flutter - securityGuard (5.4.191) + - share_extend (0.0.1): + - Flutter - shared_preferences (0.0.1): - Flutter - shared_preferences_linux (0.0.1): @@ -184,6 +186,7 @@ DEPENDENCIES: - path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`) - path_provider_windows (from `.symlinks/plugins/path_provider_windows/ios`) - save_image (from `.symlinks/plugins/save_image/ios`) + - share_extend (from `.symlinks/plugins/share_extend/ios`) - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) - shared_preferences_linux (from `.symlinks/plugins/shared_preferences_linux/ios`) - shared_preferences_macos (from `.symlinks/plugins/shared_preferences_macos/ios`) @@ -255,6 +258,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/path_provider_windows/ios" save_image: :path: ".symlinks/plugins/save_image/ios" + share_extend: + :path: ".symlinks/plugins/share_extend/ios" shared_preferences: :path: ".symlinks/plugins/shared_preferences/ios" shared_preferences_linux: @@ -315,6 +320,7 @@ SPEC CHECKSUMS: Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 save_image: 1d4bdcb69832f573215c0e2971fe9e572dfc1c84 securityGuard: 9c04c44a3b663f36e15064042abfc107fa07133c + share_extend: b6748dc53695587891126a89533b862b92548c7b shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d shared_preferences_linux: afefbfe8d921e207f01ede8b60373d9e3b566b78 shared_preferences_macos: f3f29b71ccbb56bf40c9dd6396c9acf15e214087 diff --git a/lib/pages/goods_share_page/goods_share_bloc.dart b/lib/pages/goods_share_page/goods_share_bloc.dart new file mode 100644 index 0000000..87f0b7d --- /dev/null +++ b/lib/pages/goods_share_page/goods_share_bloc.dart @@ -0,0 +1,41 @@ +import 'dart:async'; + +import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class GoodsShareBloc extends BlocBase { + List> _tabs; + + StreamController>> _tabController = + StreamController>>(); + + Stream>> get outData => _tabController.stream; + + @override + void dispose() { + _tabController.close(); + _tabController = null; + } + + void loadData(String shopType) async { + NetUtil.request( + '/api/v1/mod/pub.flutter.share?share_type=${shopType.toString()}', + method: NetMethod.GET, onCache: (data) { + _loadData(data); + }, onSuccess: (data) { + _loadData(data); + }); + } + + void _loadData(dynamic data) { + try { + List list = Map.from(data)['mod_list']; + _tabs = list.map((item) { + return Map.from(item); + }).toList(); + _tabController.add(_tabs); + } catch (err) { + Logger.error(err); + } + } +} 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 e4abacc..d7863de 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 @@ -1,45 +1,199 @@ +import 'dart:convert' as convert; + +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:zhiying_base_widget/pages/goods_share_page/goods_share_editor/goods_share_editor.dart'; +import 'package:zhiying_base_widget/pages/goods_share_page/goods_share_image/goods_share_image_model.dart'; import 'package:zhiying_base_widget/pages/goods_share_page/widgets/good_share_msg.dart'; +import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_alert_content.dart'; import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_edit.dart'; +import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_image.dart'; import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_item.dart'; +import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart'; +import 'package:zhiying_base_widget/widgets/share/share_alert.dart'; class GoodsShareImage extends StatefulWidget { + final Map model; + + const GoodsShareImage(this.model, {Key key}) : super(key: key); + @override _GoodsShareImageState createState() => _GoodsShareImageState(); } class _GoodsShareImageState extends State { + GoodsShareImageModel _style; + Map _images = Map(); + List widgets = List(); + + // 分享数据 + final ShareDataModel _shareModel = ShareDataModel(); + + @override + void initState() { + String data = widget.model['data']; + var d = convert.jsonDecode(data); + _style = GoodsShareImageModel.fromJson(Map.from(d)); + super.initState(); + } + @override Widget build(BuildContext context) { - return Container( - margin: EdgeInsets.only(top: 10), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, + widgets.clear(); + widgets.add(GoodsShareItem( + imgHeader: _style.cssList.headerImage, + imgCheck: _style.cssList.unChooseImage, + imgCheckSelected: _style.cssList.chooseImage, + child: GoodsShareEdit( + _style.content, + onCopyClick: () { + Fluttertoast.showToast(msg: '复制成功'); + }, + onEditorClick: () { + Navigator.push(context, + MaterialPageRoute(builder: (context) => GoodsShareEditor())); + }, + ), + onSelected: (isSelected) { + _shareModel.content = isSelected ? '' : _style.content; + }, + )); + for (String message in _style.customContent) { + widgets.add( + GoodsShareItem( + imgHeader: _style.cssList.headerImage, + imgCheck: _style.cssList.unChooseImage, + imgCheckSelected: _style.cssList.chooseImage, + enabled: false, + child: GoodsShareMessage(message), + ), + ); + } + for (int index = 0; index < _style.customImage.length; index++) { + String image = _style.customImage[index]; + // 分享图片 + widgets.add( + GoodsShareItem( + imgHeader: _style.cssList.headerImage, + imgCheck: _style.cssList.unChooseImage, + imgCheckSelected: _style.cssList.chooseImage, + enabled: true, + child: GoodsShareImageWidget(image), + onSelected: (isSelected) { + if (_images.containsKey(index)) { + _images.remove(index); + } else { + _images[index] = image; + } + }, + ), + ); + } + + return Column( + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(bottom: 4), + padding: EdgeInsets.only(top: 10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(8), + bottomRight: Radius.circular(8))), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: widgets), + ), + ), + ), + _createBottom(), + ], + ); + } + + Widget _createBottom() { + return SafeArea( + child: Container( + margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 4, bottom: 4), + child: Row( children: [ - GoodsShareItem( - child: GoodsShareEdit( - '至高减600【24期免息】xiaomi/小米10Pro 5G手机骁龙865智能游戏拍照手机官方旗舰店小米10青春正品k305g现货\n\n原价】3999元\n券后价】3989元\n【用智莺生活再省】19.74元\n-------------\n復製(FRH51Lu9hYF),\n用【Tao·寳】下单\n-------------\n商品链接】\nhttp://hsrj3.cn/ps/FRH51Lu9hYF.html)\n', - onCopyClick: () { - Fluttertoast.showToast(msg: '复制成功'); - }, - onEditorClick: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => GoodsShareEditor())); - }, + Container( + width: 95, + height: 36, + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(18), + ), + child: Center( + child: Text( + '仅复制口令', + style: TextStyle(color: Colors.white), + ), + ), + ), + Container( + margin: EdgeInsets.only(left: 5), + width: 95, + height: 36, + decoration: BoxDecoration( + color: Colors.orangeAccent, + borderRadius: BorderRadius.circular(18), + ), + child: Center( + child: Text( + '保存选图', + style: TextStyle(color: Colors.white), + ), ), ), - GoodsShareItem( - child: GoodsShareMessage('点击编辑模板可以自定义分享文案哦😄😄'), + Expanded( + child: GestureDetector( + child: Container( + margin: EdgeInsets.only(left: 5), + // width: 95, + height: 36, + decoration: BoxDecoration( + color: Colors.amber, + borderRadius: BorderRadius.circular(18), + ), + child: Center( + child: Text( + '分享选中素材', + style: TextStyle(color: Colors.white), + ), + ), + ), + onTap: () { + _showShare(); + }, + ), ), ], ), ), ); } + + void _showShare() async { + List images = List(); + for (int index = 0; index < _style.customImage.length; index++) { + if (_images.containsKey(index)) { + images.add(_images[index]); + } + } + if (images.length >= 0) { + _shareModel.image = images; + } + showCupertinoModalPopup( + context: context, + builder: (context) => ShareAlert( + _shareModel, + child: GoodsShareAlertContent(), + ), + ); + } } diff --git a/lib/pages/goods_share_page/goods_share_image/goods_share_image_model.dart b/lib/pages/goods_share_page/goods_share_image/goods_share_image_model.dart new file mode 100644 index 0000000..a463f86 --- /dev/null +++ b/lib/pages/goods_share_page/goods_share_image/goods_share_image_model.dart @@ -0,0 +1,134 @@ +import 'package:zhiying_base_widget/pages/goods_share_page/models/goods_share_style_model.dart'; +import 'package:zhiying_base_widget/pages/goods_share_page/models/goods_share_temp_model.dart'; + +class GoodsShareImageModel { + String content; + String format; + String templateId; + List showFunList; + String isEditTemplate; + List customContent; + List customImage; + GoodsShareStyleModel cssList; + + GoodsShareImageModel( + {this.content, + this.format, + this.templateId, + this.showFunList, + this.isEditTemplate, + this.customContent, + this.customImage, + this.cssList}); + + GoodsShareImageModel.fromJson(Map json) { + content = json['content']; + format = json['format']; + templateId = json['template_id']; + if (json['show_fun_list'] != null) { + showFunList = new List(); + json['show_fun_list'].forEach((v) { + showFunList.add( + new GoodsShareTempModel.fromJson(Map.from(v))); + }); + } + isEditTemplate = json['is_edit_template']; + customContent = json['custom_content'].cast(); + customImage = json['custom_image'].cast(); + cssList = json['css_list'] != null + ? new GoodsShareStyleModel.fromJson(json['css_list']) + : null; + } + + Map toJson() { + final Map data = new Map(); + data['content'] = this.content; + data['format'] = this.format; + data['template_id'] = this.templateId; + if (this.showFunList != null) { + data['show_fun_list'] = this.showFunList.map((v) => v.toJson()).toList(); + } + data['is_edit_template'] = this.isEditTemplate; + data['custom_content'] = this.customContent; + data['custom_image'] = this.customImage; + if (this.cssList != null) { + data['css_list'] = this.cssList.toJson(); + } + return data; + } +} + +class ShareImage { + CopyBtn copyBtn; + CopyBtn saveBtn; + CopyBtn shareBtn; + + ShareImage({this.copyBtn, this.saveBtn, this.shareBtn}); + + ShareImage.fromJson(Map json) { + copyBtn = json['copy_btn'] != null + ? new CopyBtn.fromJson(json['copy_btn']) + : null; + saveBtn = json['save_btn'] != null + ? new CopyBtn.fromJson(json['save_btn']) + : null; + shareBtn = json['share_btn'] != null + ? new CopyBtn.fromJson(json['share_btn']) + : null; + } + + Map toJson() { + final Map data = new Map(); + if (this.copyBtn != null) { + data['copy_btn'] = this.copyBtn.toJson(); + } + if (this.saveBtn != null) { + data['save_btn'] = this.saveBtn.toJson(); + } + if (this.shareBtn != null) { + data['share_btn'] = this.shareBtn.toJson(); + } + return data; + } +} + +class CopyBtn { + String name; + String modName; + String bgType; + String bgColor; + String bgImage; + String textColor; + String smallIcon; + + CopyBtn( + {this.name, + this.modName, + this.bgType, + this.bgColor, + this.bgImage, + this.textColor, + this.smallIcon}); + + CopyBtn.fromJson(Map json) { + name = json['name']; + modName = json['mod_name']; + bgType = json['bg_type']; + bgColor = json['bg_color']; + bgImage = json['bg_image']; + textColor = json['text_color']; + smallIcon = json['small_icon']; + } + + Map toJson() { + final Map data = new Map(); + data['name'] = this.name; + data['mod_name'] = this.modName; + data['bg_type'] = this.bgType; + data['bg_color'] = this.bgColor; + data['bg_image'] = this.bgImage; + data['text_color'] = this.textColor; + data['small_icon'] = this.smallIcon; + return data; + } +} diff --git a/lib/pages/goods_share_page/goods_share_link/goods_share_link.dart b/lib/pages/goods_share_page/goods_share_link/goods_share_link.dart index c371ff3..400f9a5 100644 --- a/lib/pages/goods_share_page/goods_share_link/goods_share_link.dart +++ b/lib/pages/goods_share_page/goods_share_link/goods_share_link.dart @@ -5,6 +5,10 @@ import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_i import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_link_widget.dart'; class GoodsShareLink extends StatefulWidget { + final Map model; + + const GoodsShareLink(this.model, {Key key}) : super(key: key); + @override _GoodsShareLinkState createState() => _GoodsShareLinkState(); } @@ -13,7 +17,12 @@ class _GoodsShareLinkState extends State { @override Widget build(BuildContext context) { return Container( - margin: EdgeInsets.only(top: 10), + margin: EdgeInsets.only(bottom: 4), + padding: EdgeInsets.only(top: 10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(8), bottomRight: Radius.circular(8))), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/pages/goods_share_page/goods_share_miniprogram/goods_share_miniprogram.dart b/lib/pages/goods_share_page/goods_share_miniprogram/goods_share_miniprogram.dart index d6a8969..bce5afb 100644 --- a/lib/pages/goods_share_page/goods_share_miniprogram/goods_share_miniprogram.dart +++ b/lib/pages/goods_share_page/goods_share_miniprogram/goods_share_miniprogram.dart @@ -3,6 +3,10 @@ import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_i import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_miniprogram_widget.dart'; class GoodsShareMiniprogram extends StatefulWidget { + final Map model; + + const GoodsShareMiniprogram(this.model, {Key key}) : super(key: key); + @override _GoodsShareMiniprogramState createState() => _GoodsShareMiniprogramState(); } @@ -11,7 +15,12 @@ class _GoodsShareMiniprogramState extends State { @override Widget build(BuildContext context) { return Container( - margin: EdgeInsets.only(top: 10), + margin: EdgeInsets.only(bottom: 4), + padding: EdgeInsets.only(top: 10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(8), bottomRight: Radius.circular(8))), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/pages/goods_share_page/goods_share_page.dart b/lib/pages/goods_share_page/goods_share_page.dart index 87a2743..c8b74f7 100644 --- a/lib/pages/goods_share_page/goods_share_page.dart +++ b/lib/pages/goods_share_page/goods_share_page.dart @@ -1,37 +1,51 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/pages/goods_share_page/goods_share_bloc.dart'; import 'package:zhiying_base_widget/pages/goods_share_page/goods_share_image/goods_share_image.dart'; import 'package:zhiying_base_widget/pages/goods_share_page/goods_share_link/goods_share_link.dart'; import 'package:zhiying_base_widget/pages/goods_share_page/goods_share_miniprogram/goods_share_miniprogram.dart'; -import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_alert_content.dart'; -import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart'; -import 'package:zhiying_base_widget/widgets/share/share_alert.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; class GoodsSharePage extends StatefulWidget { + final Map model; + + const GoodsSharePage(this.model, {Key key}) : super(key: key); + @override _GoodsSharePageState createState() => _GoodsSharePageState(); } -class _GoodsSharePageState extends State +class _GoodsSharePageState extends State { + @override + Widget build(BuildContext context) { + return BlocProvider( + bloc: GoodsShareBloc(), + child: _GoodsShareContainer(widget.model), + ); + } +} + +class _GoodsShareContainer extends StatefulWidget { + final Map model; + + const _GoodsShareContainer(this.model, {Key key}) : super(key: key); + + @override + _GoodsShareContainerState createState() => _GoodsShareContainerState(); +} + +class _GoodsShareContainerState extends State<_GoodsShareContainer> with TickerProviderStateMixin { + GoodsShareBloc _bloc; TabController _tabController; - List _tabs; - List _contents; + List _tabs = []; + List _contents = []; @override void initState() { - _tabController = TabController(length: 3, vsync: this); - _tabs = [ - _createTabItem('分享图文'), - _createTabItem('分享链接'), - _createTabItem('分享小程序'), - ]; - _contents = [ - GoodsShareImage(), - GoodsShareLink(), - GoodsShareMiniprogram(), - ]; + _bloc = BlocProvider.of(context); + _bloc.loadData('taobao'); super.initState(); } @@ -40,12 +54,36 @@ class _GoodsSharePageState extends State return Scaffold( backgroundColor: Color(0xfff8f8f8), appBar: _createNav(), - body: Column( - children: [ - _createCommission(), - Expanded(child: _createContent()), - _createBottom(), - ], + body: StreamBuilder>>( + stream: _bloc.outData, + builder: (BuildContext context, AsyncSnapshot snapshot) { + List> list = snapshot.data; + if (list == null || list.length == 0) { + return Container(); + } + + _tabController = TabController(length: list.length, vsync: this); + _tabs.clear(); + _contents.clear(); + list.forEach((item) { + _tabs.add(_createTabItem(item['title'])); + String mod_name = item['mod_name']; + if (mod_name == 'share_goods_image.taobao') { + _contents.add(GoodsShareImage(item)); + } else if (mod_name == 'share_goods_link.taobao') { + _contents.add(GoodsShareLink(item)); + } else if (mod_name == 'share_goods_mini.taobao') { + _contents.add(GoodsShareMiniprogram(item)); + } + }); + + return Column( + children: [ + _createCommission(), + Expanded(child: SafeArea(child: _createContent())), + ], + ); + }, ), ); } @@ -122,12 +160,16 @@ class _GoodsSharePageState extends State margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 4, bottom: 4), width: double.infinity, height: double.infinity, - decoration: BoxDecoration( - color: Colors.white, borderRadius: BorderRadius.circular(8)), + // decoration: BoxDecoration( + // color: Colors.white, borderRadius: BorderRadius.circular(8)), child: Column( children: [ Container( height: 40, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(8), topRight: Radius.circular(8))), width: double.infinity, child: TabBar( controller: _tabController, @@ -147,69 +189,6 @@ class _GoodsSharePageState extends State ); } - Widget _createBottom() { - return SafeArea( - child: Container( - margin: EdgeInsets.only(left: 12.5, right: 12.5, top: 4, bottom: 4), - child: Row( - children: [ - Container( - width: 95, - height: 36, - decoration: BoxDecoration( - color: Colors.red, - borderRadius: BorderRadius.circular(18), - ), - child: Center( - child: Text( - '仅复制口令', - style: TextStyle(color: Colors.white), - ), - ), - ), - Container( - margin: EdgeInsets.only(left: 5), - width: 95, - height: 36, - decoration: BoxDecoration( - color: Colors.orangeAccent, - borderRadius: BorderRadius.circular(18), - ), - child: Center( - child: Text( - '保存选图', - style: TextStyle(color: Colors.white), - ), - ), - ), - Expanded( - child: GestureDetector( - child: Container( - margin: EdgeInsets.only(left: 5), - // width: 95, - height: 36, - decoration: BoxDecoration( - color: Colors.amber, - borderRadius: BorderRadius.circular(18), - ), - child: Center( - child: Text( - '分享选中素材', - style: TextStyle(color: Colors.white), - ), - ), - ), - onTap: () { - _showShare(); - }, - ), - ), - ], - ), - ), - ); - } - Widget _createTabItem(String title, {bool isSelected = false}) { return Text( title, @@ -220,19 +199,4 @@ class _GoodsSharePageState extends State ), ); } - - void _showShare() async { - showCupertinoModalPopup( - context: context, - builder: (context) => ShareAlert( - ShareDataModel( - title: 'title', - content: 'content', - image: - 'https://img.alicdn.com/bao/uploaded/i1/2200818126974/O1CN01HvqWcg21O8mq9EPwf_!!0-item_pic.jpg_250x250.jpg', - url: 'http://www.hairuyi.com'), - child: GoodsShareAlertContent(), - ), - ); - } } diff --git a/lib/pages/goods_share_page/models/goods_share_style_model.dart b/lib/pages/goods_share_page/models/goods_share_style_model.dart new file mode 100644 index 0000000..7d409ae --- /dev/null +++ b/lib/pages/goods_share_page/models/goods_share_style_model.dart @@ -0,0 +1,55 @@ +import 'package:zhiying_base_widget/pages/goods_share_page/models/goods_share_temp_editor_model.dart'; + +class GoodsShareStyleModel { + String unChooseColor; + String chooseColor; + String headerImage; + String chooseImage; + String unChooseImage; + String rewardImage; + String rewardText; + Map shareImage; + GoodsShareTempEditorModel editTemplate; + + GoodsShareStyleModel( + {this.unChooseColor, + this.chooseColor, + this.headerImage, + this.chooseImage, + this.unChooseImage, + this.rewardImage, + this.rewardText, + this.shareImage, + this.editTemplate}); + + GoodsShareStyleModel.fromJson(Map json) { + unChooseColor = json['un_choose_color']; + chooseColor = json['choose_color']; + headerImage = json['header_image']; + chooseImage = json['choose_image']; + unChooseImage = json['un_choose_image']; + rewardImage = json['reward_image']; + rewardText = json['reward_text']; + shareImage = json['share_image']; + editTemplate = GoodsShareTempEditorModel.fromJson( + Map.from(json['edit_template'])); + } + + Map toJson() { + final Map data = new Map(); + data['un_choose_color'] = this.unChooseColor; + data['choose_color'] = this.chooseColor; + data['header_image'] = this.headerImage; + data['choose_image'] = this.chooseImage; + data['un_choose_image'] = this.unChooseImage; + data['reward_image'] = this.rewardImage; + data['reward_text'] = this.rewardText; + if (this.shareImage != null) { + data['share_image'] = this.shareImage; + } + if (this.editTemplate != null) { + data['edit_template'] = this.editTemplate.toJson(); + } + return data; + } +} diff --git a/lib/pages/goods_share_page/models/goods_share_temp_editor_model.dart b/lib/pages/goods_share_page/models/goods_share_temp_editor_model.dart new file mode 100644 index 0000000..64b9ebd --- /dev/null +++ b/lib/pages/goods_share_page/models/goods_share_temp_editor_model.dart @@ -0,0 +1,54 @@ +import 'package:zhiying_base_widget/widgets/public/custom_button/custom_button_model.dart'; + +class GoodsShareTempEditorModel { + CustomButtonModel regainDefault; + CustomButtonModel saveTemplate1; + CustomButtonModel previewTemplate; + CustomButtonModel backEdit; + CustomButtonModel saveTemplate2; + + GoodsShareTempEditorModel( + {this.regainDefault, + this.saveTemplate1, + this.previewTemplate, + this.backEdit, + this.saveTemplate2}); + + GoodsShareTempEditorModel.fromJson(Map json) { + regainDefault = json['regain_default'] != null + ? new CustomButtonModel.fromJson(json['regain_default']) + : null; + saveTemplate1 = json['save_template1'] != null + ? new CustomButtonModel.fromJson(json['save_template1']) + : null; + previewTemplate = json['preview_template'] != null + ? new CustomButtonModel.fromJson(json['preview_template']) + : null; + backEdit = json['back_edit'] != null + ? new CustomButtonModel.fromJson(json['back_edit']) + : null; + saveTemplate2 = json['save_template2'] != null + ? new CustomButtonModel.fromJson(json['save_template2']) + : null; + } + + Map toJson() { + final Map data = new Map(); + if (this.regainDefault != null) { + data['regain_default'] = this.regainDefault.toJson(); + } + if (this.saveTemplate1 != null) { + data['save_template1'] = this.saveTemplate1.toJson(); + } + if (this.previewTemplate != null) { + data['preview_template'] = this.previewTemplate.toJson(); + } + if (this.backEdit != null) { + data['back_edit'] = this.backEdit.toJson(); + } + if (this.saveTemplate2 != null) { + data['save_template2'] = this.saveTemplate2.toJson(); + } + return data; + } +} diff --git a/lib/pages/goods_share_page/models/goods_share_temp_model.dart b/lib/pages/goods_share_page/models/goods_share_temp_model.dart new file mode 100644 index 0000000..807a1ce --- /dev/null +++ b/lib/pages/goods_share_page/models/goods_share_temp_model.dart @@ -0,0 +1,21 @@ +class GoodsShareTempModel { + String name; + String val; + String temp; + + GoodsShareTempModel({this.name, this.val, this.temp}); + + GoodsShareTempModel.fromJson(Map json) { + name = json['name']; + val = json['val']; + temp = json['temp']; + } + + Map toJson() { + final Map data = new Map(); + data['name'] = this.name; + data['val'] = this.val; + data['temp'] = this.temp; + return data; + } +} diff --git a/lib/pages/goods_share_page/widgets/goods_share_image.dart b/lib/pages/goods_share_page/widgets/goods_share_image.dart new file mode 100644 index 0000000..b1161df --- /dev/null +++ b/lib/pages/goods_share_page/widgets/goods_share_image.dart @@ -0,0 +1,29 @@ +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; + +class GoodsShareImageWidget extends StatelessWidget { + final String imageUrl; + + const GoodsShareImageWidget(this.imageUrl, {Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + margin: EdgeInsets.only(left: 10, right: 10), + padding: EdgeInsets.only(left: 16, top: 0, right: 16, bottom: 10), + // decoration: BoxDecoration( + // color: Color(0xfff8f8f8), borderRadius: BorderRadius.circular(10)), + width: double.infinity, + child: Align( + alignment: Alignment.topLeft, + child: Container( + width: 95, + child: CachedNetworkImage( + imageUrl: imageUrl ?? '', + fit: BoxFit.fitWidth, + ), + ), + ), + ); + } +} diff --git a/lib/pages/goods_share_page/widgets/goods_share_item.dart b/lib/pages/goods_share_page/widgets/goods_share_item.dart index e126eea..8bffcc9 100644 --- a/lib/pages/goods_share_page/widgets/goods_share_item.dart +++ b/lib/pages/goods_share_page/widgets/goods_share_item.dart @@ -1,37 +1,82 @@ +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; -class GoodsShareItem extends StatelessWidget { +class GoodsShareItem extends StatefulWidget { final Widget child; + final String imgHeader; + final String imgCheck; + final String imgCheckSelected; + final bool isSelected; + final bool enabled; + final ValueChanged onSelected; - const GoodsShareItem({Key key, this.child}) : super(key: key); + const GoodsShareItem({ + Key key, + this.imgHeader = '', + this.imgCheck = '', + this.imgCheckSelected = '', + this.isSelected = false, + this.enabled = true, + this.onSelected, + this.child, + }) : super(key: key); + + @override + _GoodsShareItemState createState() => _GoodsShareItemState(); +} + +class _GoodsShareItemState extends State { + bool _isSelected; + + @override + void initState() { + _isSelected = widget.isSelected; + super.initState(); + } @override Widget build(BuildContext context) { - return Container( - margin: EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - width: 36, - height: 36, - decoration: BoxDecoration( - color: Colors.red, - borderRadius: BorderRadius.circular(18), + return GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + setState(() { + _isSelected = !_isSelected; + }); + if (widget.onSelected != null) { + widget.onSelected(_isSelected); + } + }, + child: Container( + margin: EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 36, + height: 36, + child: ClipRRect( + child: CachedNetworkImage( + imageUrl: widget.imgHeader, + ), + borderRadius: BorderRadius.circular(18), + ), + ), + Expanded( + child: widget.child ?? Container(), ), - ), - Expanded( - child: child ?? Container(), - ), - Container( - width: 18, - height: 18, - decoration: BoxDecoration( - color: Colors.red, - borderRadius: BorderRadius.circular(9), + Container( + width: 18, + height: 18, + child: Visibility( + visible: widget.enabled, + child: CachedNetworkImage( + imageUrl: + _isSelected ? widget.imgCheckSelected : widget.imgCheck, + ), + ), ), - ), - ], + ], + ), ), ); } diff --git a/lib/utils/goods_share_temp_util/goods_share_temp_util.dart b/lib/utils/goods_share_temp_util/goods_share_temp_util.dart new file mode 100644 index 0000000..fb1d7a7 --- /dev/null +++ b/lib/utils/goods_share_temp_util/goods_share_temp_util.dart @@ -0,0 +1,9 @@ +class GoodsShareTempUtil { + String parseTemp(String temp, Map values) { + values.forEach((key, value) { + temp.replaceAll(key, value); + }); + + return temp; + } +} diff --git a/lib/widgets/goods_details/footer/goods_details_footer_widget.dart b/lib/widgets/goods_details/footer/goods_details_footer_widget.dart index c5b37d3..ffafd6b 100644 --- a/lib/widgets/goods_details/footer/goods_details_footer_widget.dart +++ b/lib/widgets/goods_details/footer/goods_details_footer_widget.dart @@ -46,9 +46,9 @@ class _GooddsDetailsFooterContainerState void _collectOnClick() {} /// 分享 - void _shareOnClick() { - Navigator.of(context) - .push(MaterialPageRoute(builder: (context) => GoodsSharePage())); + void _shareOnClick(GoodsDetailsFooterModel model) { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => GoodsSharePage(model.toJson()))); } /// 自购省 @@ -150,7 +150,7 @@ class _GooddsDetailsFooterContainerState /// 分享赚, Widget _getFxzButton(GoodsDetailsFooterModel model) { return GestureDetector( - onTap: () => _shareOnClick(), + onTap: () => _shareOnClick(model), child: Container( alignment: Alignment.center, height: 44, diff --git a/lib/widgets/public/custom_button/custom_bottom.dart b/lib/widgets/public/custom_button/custom_bottom.dart new file mode 100644 index 0000000..b7d8836 --- /dev/null +++ b/lib/widgets/public/custom_button/custom_bottom.dart @@ -0,0 +1,20 @@ +import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/widgets/public/custom_button/custom_button_model.dart'; + +class CustomButton extends StatelessWidget { + final CustomButtonModel style; + final VoidCallback onClick; + + const CustomButton(this.style, {Key key, this.onClick}) : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector( + child: Container( + width: double.infinity, + height: double.infinity, + ), + onTap: onClick, + ); + } +} diff --git a/lib/widgets/public/custom_button/custom_button_model.dart b/lib/widgets/public/custom_button/custom_button_model.dart new file mode 100644 index 0000000..e65d048 --- /dev/null +++ b/lib/widgets/public/custom_button/custom_button_model.dart @@ -0,0 +1,40 @@ +class CustomButtonModel { + String name; + String modName; + String bgType; + String bgColor; + String bgImage; + String textColor; + String smallIcon; + + CustomButtonModel( + {this.name, + this.modName, + this.bgType, + this.bgColor, + this.bgImage, + this.textColor, + this.smallIcon}); + + CustomButtonModel.fromJson(Map json) { + name = json['name']; + modName = json['mod_name']; + bgType = json['bg_type']; + bgColor = json['bg_color']; + bgImage = json['bg_image']; + textColor = json['text_color']; + smallIcon = json['small_icon']; + } + + Map toJson() { + final Map data = new Map(); + data['name'] = this.name; + data['mod_name'] = this.modName; + data['bg_type'] = this.bgType; + data['bg_color'] = this.bgColor; + data['bg_image'] = this.bgImage; + data['text_color'] = this.textColor; + data['small_icon'] = this.smallIcon; + return data; + } +} diff --git a/lib/widgets/share/share_alert.dart b/lib/widgets/share/share_alert.dart index d671c50..eef717d 100644 --- a/lib/widgets/share/share_alert.dart +++ b/lib/widgets/share/share_alert.dart @@ -5,6 +5,7 @@ import 'package:sharesdk_plugin/sharesdk_plugin.dart'; import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart'; import 'package:zhiying_base_widget/widgets/share/models/share_plateform.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; +import 'package:share_extend/share_extend.dart'; class ShareAlert extends StatelessWidget { final Widget child; @@ -77,7 +78,7 @@ class _ShareAlertContent extends StatelessWidget { ), Container( margin: - EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10), + EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10), child: _createIcons(), ), GestureDetector( @@ -164,7 +165,7 @@ class _ShareAlertContent extends StatelessWidget { null, null, null, - SSDKContentTypes.audio, + SSDKContentTypes.auto, ); ShareSDKPlatform p = ShareSDKPlatforms.wechatSession; switch (plateform) { @@ -184,10 +185,29 @@ class _ShareAlertContent extends StatelessWidget { p = ShareSDKPlatforms.sina; break; } + if (model.image is List && (model.image as List).length > 1) { + // p = ShareSDKPlatforms.sina; + // Share.shareFiles(model.image); + ShareExtend.share( + "share text", "text"); + return; + } SharesdkPlugin.share(p, params, (SSDKResponseState state, Map userdata, Map contentEntity, SSDKError error) { Logger.debug('${state}, ${error.rawData}'); }); } + + // 多图分享 + _shareMultipleImages() async { + // List assetList = await MultiImagePicker.pickImages(maxImages: 5); + // var imageList = List(); + // for (var asset in assetList) { + // String path = + // await _writeByteToImageFile(await asset.getByteData(quality: 30)); + // imageList.add(path); + // } + // ShareExtend.shareMultiple(imageList, "image", subject: "share muti image"); + } } diff --git a/pubspec.yaml b/pubspec.yaml index a245a4e..5863e4d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,6 +26,8 @@ dependencies: ref: '1.2.3+1' # mob 分享sdk sharesdk_plugin: ^1.2.8 + # 系统分享 + share_extend: ^1.1.9 dev_dependencies: flutter_test: