|
|
@@ -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<ShareAlertSelect> { |
|
|
|
ShareSelectPicModel selectPicModel; |
|
|
|
GlobalKey _globalKey = GlobalKey(); |
|
|
|
|
|
|
|
List<int> 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<ShareAlertSelect> { |
|
|
|
Map d = modList.first; |
|
|
|
if (d != null) { |
|
|
|
String dString = d['data']; |
|
|
|
_iconModel = |
|
|
|
ShareAlertModel.fromJson(Map<String, dynamic>.from(jsonDecode(dString))); |
|
|
|
_iconModel = ShareAlertModel.fromJson(Map<String, dynamic>.from(jsonDecode(dString))); |
|
|
|
|
|
|
|
setState(() {}); |
|
|
|
} |
|
|
@@ -89,8 +87,15 @@ class _ShareAlertSelectState extends State<ShareAlertSelect> { |
|
|
|
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<ShareAlertSelect> { |
|
|
|
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<ShareAlertSelect> { |
|
|
|
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<ShareAlertSelect> { |
|
|
|
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<ShareAlertSelect> { |
|
|
|
), |
|
|
|
) |
|
|
|
: 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: <Widget>[ |
|
|
|
Container( |
|
|
|
width: 40, |
|
|
|
height: 40, |
|
|
|
child: CachedNetworkImage( |
|
|
|
imageUrl: item.icon, |
|
|
|
fit: BoxFit.contain, |
|
|
|
child: Container( |
|
|
|
width: 60, |
|
|
|
child: Column( |
|
|
|
children: <Widget>[ |
|
|
|
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<String> _savePoster() async { |
|
|
@@ -572,7 +546,7 @@ class _ShareAlertContentState extends State<_ShareAlertContent> { |
|
|
|
return path; |
|
|
|
} |
|
|
|
|
|
|
|
// 多图分享,调用系统分享 |
|
|
|
// 多图分享,调用系统分享 |
|
|
|
void _shareMultipleImages(String type) async { |
|
|
|
List<String> paths = List(); |
|
|
|
String path = await _savePoster(); |
|
|
|