Pārlūkot izejas kodu

1.更新分享图片的清晰度

tags/0.0.7
“yanghuaxuan” pirms 3 gadiem
vecāks
revīzija
bd352fd7ae
5 mainītis faili ar 136 papildinājumiem un 153 dzēšanām
  1. +3
    -3
      example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java
  2. +40
    -32
      example/lib/main.dart
  3. +1
    -1
      lib/pages/goods_share_page/goods_share_image/goods_share_image.dart
  4. +2
    -1
      lib/pages/mine_detail_page/mine_detail_page.dart
  5. +90
    -116
      lib/widgets/share/share_alert_select.dart

+ 3
- 3
example/android/app/src/main/java/cn/zhios/zhiying_base_widget_example/MainActivity.java Parādīt failu

@@ -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;


+ 40
- 32
example/lib/main.dart Parādīt failu

@@ -88,39 +88,47 @@ class _MyAppState extends State<MyApp> {
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: <String, WidgetBuilder>{
'/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<Locale> 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: <String, WidgetBuilder>{
'/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<Locale> supportedLocales) {
print("change language ${locale.toString()}");
return locale;
},
home: LaunchPage(
// builder: (context) => HomePage(),
),
),
),
);


+ 1
- 1
lib/pages/goods_share_page/goods_share_image/goods_share_image.dart Parādīt failu

@@ -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();
}


+ 2
- 1
lib/pages/mine_detail_page/mine_detail_page.dart Parādīt failu

@@ -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);
}
}


+ 90
- 116
lib/widgets/share/share_alert_select.dart Parādīt failu

@@ -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();


Notiek ielāde…
Atcelt
Saglabāt