更新社区点赞显示问题

hmxc
小赖 4 years ago
parent 6baeb68cbf
commit d6a4d5acf6

@ -1,17 +1,18 @@
class ImgModel { class ImgModel {
String url; String url;
String size; String size;
int longs; double longs;
int paragraph; double paragraph;
int sort; int sort;
double get aspect => paragraph / longs;
ImgModel({this.url, this.size, this.longs, this.paragraph, this.sort}); ImgModel({this.url, this.size, this.longs, this.paragraph, this.sort});
ImgModel.fromJson(Map<String, dynamic> json) { ImgModel.fromJson(Map<String, dynamic> json) {
url = json['url']; url = json['url'];
size = json['size']; size = json['size'];
longs = json['longs']; longs = json['longs'] + .0;
paragraph = json['paragraph']; paragraph = json['paragraph'] + .0;
sort = json['sort']; sort = json['sort'];
} }
@ -21,6 +22,12 @@ class ImgModel {
return models.first.url ?? ''; return models.first.url ?? '';
} }
static ImgModel firstModel(List<ImgModel> models) {
if (models == null) return null;
if (models.isEmpty) return null;
return models.first;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>(); final Map<String, dynamic> data = new Map<String, dynamic>();
data['url'] = this.url; data['url'] = this.url;

@ -36,6 +36,7 @@ class MyCommunityViewState extends State<MyCommunityView>
}, },
builder: (items) { builder: (items) {
return ListView.separated( return ListView.separated(
padding: EdgeInsets.symmetric(vertical: 10.w),
itemBuilder: (context, index) { itemBuilder: (context, index) {
final MyEventItemModel model = items[index]; final MyEventItemModel model = items[index];
MyEventItemModel preModel; MyEventItemModel preModel;

@ -62,6 +62,7 @@ class _ChatCardState extends State<ChatCard> {
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
minWidth: 0,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.w), borderRadius: BorderRadius.circular(8.w),
), ),
@ -92,6 +93,7 @@ class _ChatCardState extends State<ChatCard> {
_buildMoreButton() { _buildMoreButton() {
return Builder(builder: (context) { return Builder(builder: (context) {
final userProvider = Provider.of<UserProvider>(context);
return MaterialButton( return MaterialButton(
elevation: 0, elevation: 0,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
@ -131,6 +133,18 @@ class _ChatCardState extends State<ChatCard> {
showMessage: true, showMessage: true,
); );
setState(() { setState(() {
if (widget.model.isLike == 0) {
widget.model.likeNames.add(
LikeNames(
id: Random().nextInt(1000),
name: userProvider.userInfoModel.nickName,
),
);
} else {
widget.model.likeNames.removeWhere((element) =>
element.name ==
userProvider.userInfoModel.nickName);
}
widget.model.isLike = widget.model.isLike =
(widget.model.isLike == 1) ? 0 : 1; (widget.model.isLike == 1) ? 0 : 1;
}); });

Loading…
Cancel
Save