Weller 4 роки тому
джерело
коміт
8d175e4e9f
14 змінених файлів з 404 додано та 120 видалено
  1. +1
    -1
      .dart_tool/package_config.json
  2. +2
    -2
      example/ios/Runner/AppDelegate.m
  3. +29
    -13
      lib/pages/goods_share_page/goods_share_bloc.dart
  4. +86
    -23
      lib/pages/goods_share_page/goods_share_image/goods_share_image.dart
  5. +5
    -1
      lib/pages/goods_share_page/goods_share_link/goods_share_link.dart
  6. +5
    -1
      lib/pages/goods_share_page/goods_share_miniprogram/goods_share_miniprogram.dart
  7. +23
    -9
      lib/pages/goods_share_page/goods_share_page.dart
  8. +62
    -0
      lib/pages/goods_share_page/models/goods_share_temp_add_model.dart
  9. +3
    -0
      lib/pages/goods_share_page/widgets/goods_share_edit.dart
  10. +55
    -7
      lib/widgets/goods_details/footer/goods_details_footer_widget.dart
  11. +16
    -4
      lib/widgets/home/home_auth/home_auth.dart
  12. +1
    -1
      lib/widgets/share/models/share_data_model.dart
  13. +22
    -0
      lib/widgets/share/models/share_icon_model.dart
  14. +94
    -58
      lib/widgets/share/share_alert.dart

+ 1
- 1
.dart_tool/package_config.json Переглянути файл

@@ -602,7 +602,7 @@
"languageVersion": "2.1"
}
],
"generated": "2020-09-29T09:19:18.536482Z",
"generated": "2020-09-29T09:31:08.197502Z",
"generator": "pub",
"generatorVersion": "2.7.2"
}

+ 2
- 2
example/ios/Runner/AppDelegate.m Переглянути файл

@@ -27,8 +27,8 @@
// 获取设置
- (NSDictionary*)getSetting {
return @{
@"domain": @"http://inapi.izhyin.cn"
//@"domain": @"http://192.168.0.113:5000"
//@"domain": @"http://inapi.izhyin.cn"
@"domain": @"http://192.168.0.113:5000"
};
}



+ 29
- 13
lib/pages/goods_share_page/goods_share_bloc.dart Переглянути файл

@@ -1,15 +1,21 @@
import 'dart:async';

import 'package:zhiying_base_widget/pages/goods_share_page/models/goods_share_temp_add_model.dart';
import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class GoodsShareData {
List<Map<String, dynamic>> tabs;
List<GoodsShareTempDataModel> datas;
}

class GoodsShareBloc extends BlocBase {
List<Map<String, dynamic>> _tabs;
GoodsShareData _data = GoodsShareData();

StreamController<List<Map<String, dynamic>>> _tabController =
StreamController<List<Map<String, dynamic>>>();
StreamController<GoodsShareData> _tabController =
StreamController<GoodsShareData>();

Stream<List<Map<String, dynamic>>> get outData => _tabController.stream;
Stream<GoodsShareData> get outData => _tabController.stream;

@override
void dispose() {
@@ -17,23 +23,33 @@ class GoodsShareBloc extends BlocBase {
_tabController = null;
}

void loadData(String shopType) async {
void loadData(String shopType, Map<String, dynamic> params) async {
var json = await NetUtil.post('/api/v1/share/${shopType}', params: params);
Map<String, dynamic> data = json['data'];
List shareTemp = data['data_list'];
_data.datas = shareTemp.map((item) {
return GoodsShareTempDataModel.fromJson(Map<String, dynamic>.from(item));
}).toList();

NetUtil.request(
'/api/v1/mod/pub.flutter.share?share_type=${shopType.toString()}',
method: NetMethod.GET, onCache: (data) {
_loadData(data);
}, onSuccess: (data) {
_loadData(data);
});
'/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<String, dynamic>.from(data)['mod_list'];
_tabs = list.map((item) {
_data.tabs = list.map((item) {
return Map<String, dynamic>.from(item);
}).toList();
_tabController.add(_tabs);
_tabController.add(_data);
} catch (err) {
Logger.error(err);
}


+ 86
- 23
lib/pages/goods_share_page/goods_share_image/goods_share_image.dart Переглянути файл

@@ -1,15 +1,20 @@
import 'dart:convert' as convert;
import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:save_image/save_image.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/models/goods_share_temp_add_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/utils/image_download_util/image_download_util.dart';
import 'package:zhiying_base_widget/widgets/public/custom_button/custom_bottom.dart';
import 'package:zhiying_base_widget/widgets/public/custom_button/custom_button_model.dart';
import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart';
@@ -17,8 +22,9 @@ import 'package:zhiying_base_widget/widgets/share/share_alert.dart';

class GoodsShareImage extends StatefulWidget {
final Map<String, dynamic> model;
final GoodsShareTempDataModel datas;

const GoodsShareImage(this.model, {Key key}) : super(key: key);
const GoodsShareImage(this.model, this.datas, {Key key}) : super(key: key);

@override
_GoodsShareImageState createState() => _GoodsShareImageState();
@@ -28,6 +34,7 @@ class _GoodsShareImageState extends State<GoodsShareImage> {
GoodsShareImageModel _style;
Map<int, String> _images = Map();
List<Widget> widgets = List();
String _content = '';

// 分享数据
final ShareDataModel _shareModel = ShareDataModel();
@@ -37,6 +44,7 @@ class _GoodsShareImageState extends State<GoodsShareImage> {
String data = widget.model['data'];
var d = convert.jsonDecode(data);
_style = GoodsShareImageModel.fromJson(Map<String, dynamic>.from(d));
_content = widget.datas.shareContent;
super.initState();
}

@@ -48,9 +56,10 @@ class _GoodsShareImageState extends State<GoodsShareImage> {
imgCheck: _style.cssList.unChooseImage,
imgCheckSelected: _style.cssList.chooseImage,
child: GoodsShareEdit(
_style.content,
_content,
onCopyClick: () {
Fluttertoast.showToast(msg: '复制成功');
Clipboard.setData(ClipboardData(text: _content));
Fluttertoast.showToast(msg: '文案已复制');
},
onEditorClick: () {
Fluttertoast.showToast(msg: '正在开发中');
@@ -60,7 +69,7 @@ class _GoodsShareImageState extends State<GoodsShareImage> {
},
),
onSelected: (isSelected) {
_shareModel.content = isSelected ? '' : _style.content;
_shareModel.content = isSelected ? _content : '';
},
));
for (String message in _style.customContent) {
@@ -137,23 +146,34 @@ class _GoodsShareImageState extends State<GoodsShareImage> {
children: <Widget>[
btnCopy == null
? Container()
: Container(
width: 95,
height: 36,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
),
child: CustomButton(btnCopy)),
: GestureDetector(
child: Container(
width: 95,
height: 36,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
),
child: CustomButton(btnCopy)),
onTap: () {
Clipboard.setData(ClipboardData(text: _content));
Fluttertoast.showToast(msg: '文案已复制');
},
),
btnSave == null
? Container()
: Container(
margin: EdgeInsets.only(left: 5),
width: 95,
height: 36,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
: GestureDetector(
child: Container(
margin: EdgeInsets.only(left: 5),
width: 95,
height: 36,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
),
child: CustomButton(btnSave),
),
child: CustomButton(btnSave),
onTap: () {
_saveImages();
},
),
btnShare == null
? Container()
@@ -168,7 +188,7 @@ class _GoodsShareImageState extends State<GoodsShareImage> {
),
child: CustomButton(btnShare)),
onTap: () {
_showShare();
_showShareAlert();
},
),
),
@@ -178,21 +198,64 @@ class _GoodsShareImageState extends State<GoodsShareImage> {
);
}

void _showShare() async {
void _saveImages() async {
List<String> images = List();
for (int index = 0; index < _style.customImage.length; index++) {
if (_images.containsKey(index)) {
images.add(_images[index]);
}
}
if (images.length >= 0) {
if (images.length > 0) {
_shareModel.image = images;
} else {
_shareModel.image = null;
}

if ((_shareModel.image == null || _shareModel.image.length == 0)) {
Fluttertoast.showToast(msg: '请选择要保存的图片');
return;
}

List<String> paths = await ImageDownloadUtil.download(images);
paths.forEach((path) async {
Uint8List data = File(path).readAsBytesSync();
bool isSaveSuccess = await SaveImage.save(imageBytes: data);
if (!isSaveSuccess) {
Fluttertoast.showToast(msg: '保存失败');
return;
}
});
Fluttertoast.showToast(msg: '保存成功');
}

// 弹出分享框
void _showShareAlert() async {
List<String> 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;
} else {
_shareModel.image = null;
}

if ((_shareModel.title == null || _shareModel.title == '') &&
(_shareModel.image == null || _shareModel.image.length == 0) &&
(_shareModel.content == null || _shareModel.content == '') &&
(_shareModel.url == null || _shareModel.url == '')) {
Fluttertoast.showToast(msg: '请选择要分享的内容');
return;
}

showCupertinoModalPopup(
context: context,
builder: (context) => ShareAlert(
_shareModel,
child: GoodsShareAlertContent(),
'pub.flutter.share_icon',
// child: GoodsShareAlertContent(),
),
);
}


+ 5
- 1
lib/pages/goods_share_page/goods_share_link/goods_share_link.dart Переглянути файл

@@ -5,6 +5,7 @@ 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/models/goods_share_temp_add_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';
@@ -18,7 +19,9 @@ import 'package:zhiying_base_widget/widgets/share/share_alert.dart';
class GoodsShareLink extends StatefulWidget {
final Map<String, dynamic> model;

const GoodsShareLink(this.model, {Key key}) : super(key: key);
final GoodsShareTempDataModel datas;

const GoodsShareLink(this.model, this.datas, {Key key}) : super(key: key);

@override
_GoodsShareLinkState createState() => _GoodsShareLinkState();
@@ -172,6 +175,7 @@ class _GoodsShareLinkState extends State<GoodsShareLink> {
context: context,
builder: (context) => ShareAlert(
_shareModel,
'',
child: GoodsShareAlertContent(),
),
);


+ 5
- 1
lib/pages/goods_share_page/goods_share_miniprogram/goods_share_miniprogram.dart Переглянути файл

@@ -1,11 +1,15 @@
import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/pages/goods_share_page/models/goods_share_temp_add_model.dart';
import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_item.dart';
import 'package:zhiying_base_widget/pages/goods_share_page/widgets/goods_share_miniprogram_widget.dart';

class GoodsShareMiniprogram extends StatefulWidget {
final Map<String, dynamic> model;

const GoodsShareMiniprogram(this.model, {Key key}) : super(key: key);
final GoodsShareTempDataModel datas;

const GoodsShareMiniprogram(this.model, this.datas, {Key key})
: super(key: key);

@override
_GoodsShareMiniprogramState createState() => _GoodsShareMiniprogramState();


+ 23
- 9
lib/pages/goods_share_page/goods_share_page.dart Переглянути файл

@@ -1,9 +1,12 @@
import 'dart:convert' as convert;

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/models/goods_share_temp_add_model.dart';
import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

@@ -44,8 +47,12 @@ class _GoodsShareContainerState extends State<_GoodsShareContainer>

@override
void initState() {
String d = widget.model['data'];
Map<String, dynamic> data =
Map<String, dynamic>.from(convert.jsonDecode(d));
Logger.debug(data['share_url_args'].toString());
_bloc = BlocProvider.of<GoodsShareBloc>(context);
_bloc.loadData('taobao');
_bloc.loadData('taobao', data['share_url_args']);
super.initState();
}

@@ -54,30 +61,37 @@ class _GoodsShareContainerState extends State<_GoodsShareContainer>
return Scaffold(
backgroundColor: Color(0xfff8f8f8),
appBar: _createNav(),
body: StreamBuilder<List<Map<String, dynamic>>>(
body: StreamBuilder<GoodsShareData>(
stream: _bloc.outData,
builder: (BuildContext context, AsyncSnapshot snapshot) {
List<Map<String, dynamic>> list = snapshot.data;
if (list == null || list.length == 0) {
GoodsShareData data = snapshot.data;
List<Map<String, dynamic>> list = data?.tabs;
List<GoodsShareTempDataModel> datas = data?.datas;
if (list == null ||
list.length == 0 ||
datas == null ||
datas.length == 0) {
return Container();
}

_tabController = TabController(length: list.length, vsync: this);
_tabs.clear();
_contents.clear();
list.forEach((item) {
for (int i = 0; i < list.length && i < datas.length; i++) {
Map<String, dynamic> item = list[i];
GoodsShareTempDataModel model = datas[i];
_tabs.add(_createTabItem(item['title']));
String mod_name = item['mod_name'];
if (mod_name == 'share_goods_image.taobao') {
_contents.add(GoodsShareImage(item));
_contents.add(GoodsShareImage(item, model));
} else if (mod_name == 'share_goods_link.taobao') {
_contents.add(GoodsShareLink(item));
_contents.add(GoodsShareLink(item, model));
} else if (mod_name == 'share_goods_mini.taobao') {
_contents.add(GoodsShareMiniprogram(item));
_contents.add(GoodsShareMiniprogram(item, model));
} else {
_contents.add(Container());
}
});
}

return Column(
children: <Widget>[


+ 62
- 0
lib/pages/goods_share_page/models/goods_share_temp_add_model.dart Переглянути файл

@@ -0,0 +1,62 @@
class GoodsShareTempDataModel {
String shareContent;
List<GoodsShareTempAddModel> shareTemplate;
String shareTip;
String appUrl;
String miniAppUrl;

GoodsShareTempDataModel(
{this.shareContent,
this.shareTemplate,
this.shareTip,
this.appUrl,
this.miniAppUrl});

GoodsShareTempDataModel.fromJson(Map<String, dynamic> json) {
shareContent = json['share_content'];
if (json['share_template'] != null) {
shareTemplate = new List<GoodsShareTempAddModel>();
json['share_template'].forEach((v) {
shareTemplate.add(new GoodsShareTempAddModel.fromJson(v));
});
}
shareTip = json['share_tip'];
appUrl = json['app_url'];
miniAppUrl = json['mini_app_url'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['share_content'] = this.shareContent;
if (this.shareTemplate != null) {
data['share_template'] =
this.shareTemplate.map((v) => v.toJson()).toList();
}
data['share_tip'] = this.shareTip;
data['app_url'] = this.appUrl;
data['mini_app_url'] = this.miniAppUrl;
return data;
}
}

class GoodsShareTempAddModel {
String name;
String val;
String temp;

GoodsShareTempAddModel({this.name, this.val, this.temp});

GoodsShareTempAddModel.fromJson(Map<String, dynamic> json) {
name = json['name'];
val = json['val'];
temp = json['temp'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['name'] = this.name;
data['val'] = this.val;
data['temp'] = this.temp;
return data;
}
}

+ 3
- 0
lib/pages/goods_share_page/widgets/goods_share_edit.dart Переглянути файл

@@ -5,6 +5,9 @@ class GoodsShareEdit extends StatelessWidget {
final VoidCallback onEditorClick;
final VoidCallback onCopyClick;

// final String imgCheck;
// final String imgCheckSelected;

const GoodsShareEdit(this.message,
{Key key, this.onEditorClick, this.onCopyClick})
: super(key: key);


+ 55
- 7
lib/widgets/goods_details/footer/goods_details_footer_widget.dart Переглянути файл

@@ -1,6 +1,12 @@
import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_alibc/alibc_model.dart';
import 'package:flutter_alibc/flutter_alibc.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import 'package:zhiying_base_widget/pages/goods_share_page/goods_share_page.dart';
import 'package:zhiying_base_widget/widgets/goods_details/footer/bloc/goods_details_footer_bloc.dart';
import 'package:zhiying_base_widget/widgets/goods_details/footer/bloc/goods_details_footer_repository.dart';
@@ -25,13 +31,17 @@ class GoodsDetailsFooterWidget extends StatelessWidget {
create: (_) =>
GoodsDetailsFooterBloc(repository: GoodsDetailsFooterRepository())
..add(GoodsDetailsFooterInitEvent(model: model)),
child: GooddsDetailsFooterContainer(),
child: GooddsDetailsFooterContainer(model),
),
);
}
}

class GooddsDetailsFooterContainer extends StatefulWidget {
final Map<String, dynamic> model;

const GooddsDetailsFooterContainer(this.model, {Key key}) : super(key: key);

@override
_GooddsDetailsFooterContainerState createState() =>
_GooddsDetailsFooterContainerState();
@@ -39,12 +49,16 @@ class GooddsDetailsFooterContainer extends StatefulWidget {

class _GooddsDetailsFooterContainerState
extends State<GooddsDetailsFooterContainer> {
UserInfoModel _user;

/// 打开首页
void _openHome() {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (BuildContext context) => PageFactory.create('homePage', null)),
(Route<dynamic> route) => false,
MaterialPageRoute(
builder: (BuildContext context) =>
PageFactory.create('homePage', null)),
(Route<dynamic> route) => false,
);
}

@@ -53,15 +67,49 @@ class _GooddsDetailsFooterContainerState

/// 分享
void _shareOnClick(GoodsDetailsFooterModel model) {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => GoodsSharePage(model.toJson())));
print(_user?.toString());
if (_user?.token == null || _user.token == '') {
print('need login...');
RouterUtil.goLogin(context);
return;
}
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => GoodsSharePage(widget.model)));
}

/// 自购省
void _savemoneyOnClick() {}
void _savemoneyOnClick(GoodsDetailsFooterModel model) async {
print(_user?.toString());
if (_user?.token == null || _user.token == '') {
print('need login...');
RouterUtil.goLogin(context);
return;
}

String d = widget.model['data'];
Map<String, dynamic> data = jsonDecode(d);

Map shareArgs = data['share_url_args'] ?? {};
String shopType = shareArgs['type'];

if (data.containsKey('buy_url')) {
String url = data['buy_url'];
if (url == null || url == '') {
Fluttertoast.showToast(msg: '购买链接不存在');
return;
}
if (shopType == 'taobao') {
TradeResult result = await FlutterAlibc.openByUrl(url: url);
Logger.debug('${result.errorCode} ${result.errorMessage} ');
} else {
RouterUtil.openWebview(url, context);
}
}
}

@override
Widget build(BuildContext context) {
_user = Provider.of<UserInfoNotifier>(context).userInfo;
return BlocConsumer<GoodsDetailsFooterBloc, GoodsDetailsFooterState>(
listener: (context, state) {},
buildWhen: (prev, current) {
@@ -207,7 +255,7 @@ class _GooddsDetailsFooterContainerState
Widget _getZgsButton(GoodsDetailsFooterModel model) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _savemoneyOnClick(),
onTap: () => _savemoneyOnClick(model),
child: Container(
alignment: Alignment.center,
// padding: const EdgeInsets.only(left: 30, right: 30, top: 5, bottom: 5),


+ 16
- 4
lib/widgets/home/home_auth/home_auth.dart Переглянути файл

@@ -2,6 +2,7 @@ import 'dart:convert' as convert;

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:zhiying_base_widget/widgets/home/home_auth/models/home_auth_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

@@ -9,6 +10,7 @@ class HomeAuth extends StatelessWidget {
final Map<String, dynamic> data;
Map<String, dynamic> _json;
HomeAuthModel _style;
UserInfoModel _user;

HomeAuth(this.data, {Key key}) : super(key: key) {
String d = data['data'];
@@ -18,6 +20,7 @@ class HomeAuth extends StatelessWidget {

@override
Widget build(BuildContext context) {
_user = Provider.of<UserInfoNotifier>(context).userInfo;
return Container(
height: 34,
width: double.infinity,
@@ -28,8 +31,9 @@ class HomeAuth extends StatelessWidget {
boxShadow: [
BoxShadow(
offset: Offset(2, 1), //x,y轴
color: HexColor.fromHex(_style?.taoaboTipShadowColor ?? '767676')
.withAlpha(70), //投影颜色
color:
HexColor.fromHex(_style?.taoaboTipShadowColor ?? '767676')
.withAlpha(70), //投影颜色
blurRadius: 5 //投影距离
)
]),
@@ -60,17 +64,25 @@ class HomeAuth extends StatelessWidget {
padding: EdgeInsets.only(left: 12, right: 12, top: 3, bottom: 3),
margin: EdgeInsets.only(left: 8, right: 8),
decoration: BoxDecoration(
color: HexColor.fromHex(_style?.taoaboTipBtnBgColor ?? 'FF4242'),
color:
HexColor.fromHex(_style?.taoaboTipBtnBgColor ?? 'FF4242'),
borderRadius: BorderRadius.circular(20)),
child: Text(
_style?.taoaboTipBtnText ?? '',
style: TextStyle(
fontSize: 12,
color: HexColor.fromHex(_style?.taoaboTipBtnTextColor ?? 'ffffff'),
color: HexColor.fromHex(
_style?.taoaboTipBtnTextColor ?? 'ffffff'),
),
),
),
onTap: () async {
if (_user?.token == null || _user.token == '') {
print('need login...');
RouterUtil.goLogin(context);
return;
}

bool isAuth = await TaobaoAuth.isAuth();
if (!isAuth) {
TaobaoAuth.auth(context);


+ 1
- 1
lib/widgets/share/models/share_data_model.dart Переглянути файл

@@ -1,7 +1,7 @@
class ShareDataModel {
String title;
String content;
dynamic image;
List image;
String url;

ShareDataModel({


+ 22
- 0
lib/widgets/share/models/share_icon_model.dart Переглянути файл

@@ -0,0 +1,22 @@
// 分享按钮
class ShareIconModel {
String name;
String type;
String icon;

ShareIconModel({this.name, this.type, this.icon});

ShareIconModel.fromJson(Map<String, dynamic> json) {
name = json['name'];
type = json['type'];
icon = json['icon'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['name'] = this.name;
data['type'] = this.type;
data['icon'] = this.icon;
return data;
}
}

+ 94
- 58
lib/widgets/share/share_alert.dart Переглянути файл

@@ -1,19 +1,22 @@
import 'dart:io';
import 'dart:convert';
import 'dart:ui';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:share_extend/share_extend.dart';
import 'package:sharesdk_plugin/sharesdk_plugin.dart';
import 'package:zhiying_base_widget/utils/image_download_util/image_download_util.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_base_widget/widgets/share/models/share_icon_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:share_extend/share_extend.dart';

class ShareAlert extends StatelessWidget {
final String skipIdentifier;
final Widget child;
final ShareDataModel model;

const ShareAlert(this.model, {Key key, this.child}) : super(key: key); // 中间视图
const ShareAlert(this.model, this.skipIdentifier, {Key key, this.child})
: super(key: key); // 中间视图

@override
Widget build(BuildContext context) {
@@ -28,7 +31,7 @@ class ShareAlert extends StatelessWidget {
Expanded(
child: Center(child: child ?? Container()),
),
_ShareAlertContent(this.model),
_ShareAlertContent(this.model, this.skipIdentifier),
],
),
), // 模糊化
@@ -41,10 +44,44 @@ class ShareAlert extends StatelessWidget {
}
}

class _ShareAlertContent extends StatelessWidget {
class _ShareAlertContent extends StatefulWidget {
final ShareDataModel model;
final String skipIdentifier;

const _ShareAlertContent(this.model, this.skipIdentifier, {Key key})
: super(key: key);

@override
_ShareAlertContentState createState() => _ShareAlertContentState();
}

const _ShareAlertContent(this.model, {Key key}) : super(key: key);
class _ShareAlertContentState extends State<_ShareAlertContent> {
List<ShareIconModel> _icons = [];

@override
void initState() {
NetUtil.request('/api/v1/mod/${widget.skipIdentifier}',
method: NetMethod.GET, onCache: (data) {
_parseData(data);
}, onSuccess: (data) {
_parseData(data);
}, onError: (err) {});

super.initState();
}

void _parseData(Map<String, dynamic> data) {
List modList = data['mod_list'];
Map d = modList.first;
if (d != null) {
String dString = d['data'];
List list = jsonDecode(dString);
_icons = list.map((item) {
return ShareIconModel.fromJson(Map<String, dynamic>.from(item));
}).toList();
setState(() {});
}
}

@override
Widget build(BuildContext context) {
@@ -80,7 +117,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(
@@ -115,13 +152,13 @@ class _ShareAlertContent extends StatelessWidget {
return Wrap(
spacing: 10,
runSpacing: 10,
children: List.generate(6, (index) {
return _createIcon();
}),
children: _icons.map((item) {
return _createIcon(item);
}).toList(),
);
}

Widget _createIcon() {
Widget _createIcon(ShareIconModel item) {
return GestureDetector(
child: Container(
width: 60,
@@ -130,14 +167,15 @@ class _ShareAlertContent extends StatelessWidget {
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.redAccent),
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),
@@ -148,67 +186,65 @@ class _ShareAlertContent extends StatelessWidget {
),
),
onTap: () {
_shareByMob(SharePlateform.qq);
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();
}
},
);
}

void _shareByMob(SharePlateform plateform) async {
void _shareByMob(ShareSDKPlatform plateform) async {
// dynamic image;
if (widget.model.image != null && widget.model.image.length > 1) {
_shareMultipleImages();
return;
}

//单独公共分享
SSDKMap params = SSDKMap()
..setGeneral(
model.title,
model.content,
model.image,
widget.model.title,
widget.model.content,
widget.model.image,
null,
null,
model.url,
widget.model.url,
null,
null,
null,
null,
SSDKContentTypes.auto,
);
ShareSDKPlatform p = ShareSDKPlatforms.wechatSession;
switch (plateform) {
case SharePlateform.wechatSession:
p = ShareSDKPlatforms.wechatSession;
break;
case SharePlateform.wechatTimeline:
p = ShareSDKPlatforms.wechatTimeline;
break;
case SharePlateform.qq:
p = ShareSDKPlatforms.qq;
break;
case SharePlateform.qqZone:
p = ShareSDKPlatforms.qZone;
break;
case SharePlateform.sina:
p = ShareSDKPlatforms.sina;
break;
}
if (model.image is List && (model.image as List).length > 1) {
List<String> paths = await ImageDownloadUtil.download(model.image);
ShareExtend.shareMultiple(
paths, "image", subject: "");
return;
}

SharesdkPlugin.share(p, params, (SSDKResponseState state, Map userdata,
Map contentEntity, SSDKError error) {
SharesdkPlugin.share(plateform, params, (SSDKResponseState state,
Map userdata, Map contentEntity, SSDKError error) {
Logger.debug('${state}, ${error.rawData}');
});
}

// 多图分享
_shareMultipleImages() async {
// List<Asset> assetList = await MultiImagePicker.pickImages(maxImages: 5);
// var imageList = List<String>();
// 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");
// 系统分享,只能分享图片或者文字,不能组合分享
void _shareBySystem() async {
if (widget.model.image.length >= 1) {
_shareMultipleImages();
return;
} else {
ShareExtend.share(widget.model.content, 'text');
}
}

// 多图分享,调用系统分享
void _shareMultipleImages() async {
List<String> paths = await ImageDownloadUtil.download(widget.model.image);
ShareExtend.shareMultiple(paths, "image", subject: "");
}
}

Завантаження…
Відмінити
Зберегти