diff --git a/lib/model/common/img_model.dart b/lib/model/common/img_model.dart index e8a9dd2c..7614a251 100644 --- a/lib/model/common/img_model.dart +++ b/lib/model/common/img_model.dart @@ -15,6 +15,12 @@ class ImgModel { sort = json['sort']; } + static String first(List models) { + if (models == null) return ''; + if (models.isEmpty) return ''; + return models.first.url ?? ''; + } + Map toJson() { final Map data = new Map(); data['url'] = this.url; diff --git a/lib/model/manager/voting_detail_model.dart b/lib/model/manager/voting_detail_model.dart index 47e5e2e2..1d52902e 100644 --- a/lib/model/manager/voting_detail_model.dart +++ b/lib/model/manager/voting_detail_model.dart @@ -9,6 +9,12 @@ class VotingDetailModel { List imgUrls; List appVoteCandidateVos; + String get firstImage { + if (imgUrls == null) return ''; + if (imgUrls.isEmpty) return ''; + return imgUrls.first.url ?? ''; + } + VotingDetailModel( {this.id, this.title, diff --git a/lib/pages/event_activity/event_voting_page.dart b/lib/pages/event_activity/event_voting_page.dart index 2c6085ce..2af5ae42 100644 --- a/lib/pages/event_activity/event_voting_page.dart +++ b/lib/pages/event_activity/event_voting_page.dart @@ -59,9 +59,11 @@ class _EventVotingPageState extends State { width: double.infinity, child: ClipRect( child: FadeInImage.assetNetwork( - placeholder: R.ASSETS_IMAGES_LOGO_PNG, - image: API.image( - model.imgUrls.isNotEmpty ? model.imgUrls.first.url : '')), + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: API.image( + model.imgUrls.isNotEmpty ? model.imgUrls.first.url : ''), + fit: BoxFit.cover, + ), ), ), Padding( diff --git a/lib/pages/event_activity/voting_detail_page.dart b/lib/pages/event_activity/voting_detail_page.dart index 15a54e65..5d92488f 100644 --- a/lib/pages/event_activity/voting_detail_page.dart +++ b/lib/pages/event_activity/voting_detail_page.dart @@ -1,3 +1,4 @@ +import 'package:akuCommunity/model/common/img_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -122,8 +123,12 @@ class _VotingDetailPageState extends State { child: ClipRRect( borderRadius: BorderRadius.circular(4.w), child: FadeInImage.assetNetwork( - placeholder: R.ASSETS_IMAGES_LOGO_PNG, - image: API.image(model.imgUrls.first.url)), + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: API.image( + ImgModel.first(model.imgUrls), + ), + fit: BoxFit.cover, + ), ), ), 30.w.widthBox, @@ -213,15 +218,11 @@ class _VotingDetailPageState extends State { children: [ _model.title.text.black.size(32.sp).bold.maxLines(2).make(), 44.w.heightBox, - SizedBox( - width: double.infinity, - height: 228.w, - child: ClipRRect( - borderRadius: BorderRadius.circular(8.w), - child: FadeInImage.assetNetwork( - placeholder: R.ASSETS_IMAGES_LOGO_PNG, - image: API.image(_model.imgUrls.first.url), - ), + ClipRRect( + borderRadius: BorderRadius.circular(8.w), + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP, + image: API.image(_model.firstImage), ), ), 44.w.heightBox, diff --git a/lib/pages/manager_func.dart b/lib/pages/manager_func.dart index e1f532b9..a3fcae7a 100644 --- a/lib/pages/manager_func.dart +++ b/lib/pages/manager_func.dart @@ -169,11 +169,11 @@ class ManagerFunc { } static Future voteDetail(int id) async { - BaseModel baseModel = await NetUtil().get(API.manager.voteDetail, - params: { - 'voteId': 1, - }, - showMessage: false); + BaseModel baseModel = await NetUtil().get( + API.manager.voteDetail, + params: {'voteId': id}, + showMessage: false, + ); return VotingDetailModel.fromJson(baseModel.data); }