社区页面爱心按钮,头像显示逻辑更改

hmxc
张萌 4 years ago
parent 718615a66c
commit 2bd339a3bc

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

@ -1,7 +1,3 @@
import 'dart:io';
import 'package:akuCommunity/pages/home/home_page.dart';
import 'package:akuCommunity/pages/sign/sign_in_page.dart';
import 'package:akuCommunity/pages/tab_navigator.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:ani_route/ani_route.dart';

@ -86,7 +86,8 @@ class _TabListState extends State<TabList> with AutomaticKeepAliveClientMixin {
'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=107966910,699677438&fm=26&gp=0.jpg',
'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3011269428,2056805718&fm=26&gp=0.jpg'
],
'isLike':false
'isLike':false,
'avatar':Image.asset('assets/example/touxiang1.png'),
},
{
'name': '马泽鹏',
@ -95,7 +96,8 @@ class _TabListState extends State<TabList> with AutomaticKeepAliveClientMixin {
'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3445658157,2379681095&fm=26&gp=0.jpg',
'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3539674557,3804837870&fm=26&gp=0.jpg',
],
'isLike':true
'isLike':true,
'avatar':Image.asset('assets/example/touxiang2.png')
},
{
'name': '王管事',
@ -104,7 +106,8 @@ class _TabListState extends State<TabList> with AutomaticKeepAliveClientMixin {
'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2446247351,2922660058&fm=26&gp=0.jpg',
'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1601274815221&di=3a50314a4d2c7188f6003f67d24177c2&imgtype=0&src=http%3A%2F%2Fimg1.cache.netease.com%2Fcatchpic%2F6%2F62%2F620DAF59053DF902F1D991EDBF14FD26.gif',
],
'isLike':false
'isLike':false,
'avatar':Image.asset('assets/example/touxiang3.jpeg')
},
];
@ -155,6 +158,7 @@ class _TabListState extends State<TabList> with AutomaticKeepAliveClientMixin {
content: _newsList[index]['content'],
imageUrl: _newsList[index]['imageUrl'],
isLike: _newsList[index]['isLike'],
avatar:_newsList[index]['avatar']
)
: widget.index == 1
? TopicCard(

@ -1,3 +1,4 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
@ -5,13 +6,15 @@ import 'package:flutter_icons/flutter_icons.dart';
import 'package:akuCommunity/utils/screenutil.dart';
import 'package:akuCommunity/widget/expandable_text.dart';
import 'package:akuCommunity/widget/image_grid.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class TrendCard extends StatefulWidget {
final String name;
final String content;
final List<String> imageUrl;
final bool isLike;
TrendCard({Key key, this.name, this.content, this.imageUrl, this.isLike})
final Image avatar;
TrendCard({Key key, this.name, this.content, this.imageUrl, this.isLike, this.avatar})
: super(key: key);
@override
@ -19,6 +22,12 @@ class TrendCard extends StatefulWidget {
}
class _TrendCardState extends State<TrendCard> {
bool _isLike;
@override
void initState() {
super.initState();
_isLike=widget.isLike??false;
}
void _showDialog(String url) {
showCupertinoDialog(
context: context,
@ -294,7 +303,7 @@ class _TrendCardState extends State<TrendCard> {
);
}
Widget _columnCard(String name, String content, bool isLike) {
Widget _columnCard(String name, String content,Image avatar) {
return Stack(
children: [
Column(
@ -303,10 +312,10 @@ class _TrendCardState extends State<TrendCard> {
children: [
Row(
children: [
Image.asset(
'assets/example/touxiang1.png',
height: Screenutil.length(86),
width: Screenutil.length(86),
Container(
width: 86.w,
height: 86.w,
child: avatar,
),
SizedBox(width: Screenutil.length(9)),
Column(
@ -356,12 +365,15 @@ class _TrendCardState extends State<TrendCard> {
bottom: 0,
child: InkWell(
onTap: () {
isLike = !isLike;
setState(() {
_isLike = !_isLike;
});
},
child: Icon(
isLike ? AntDesign.heart : AntDesign.hearto,
_isLike ? AntDesign.heart : AntDesign.hearto,
color:
isLike ? Color(0xffff6666) : Color(0xffd8d8d8),
_isLike ? Color(0xffff6666) : Color(0xffd8d8d8),
size: Screenutil.size(36),
),
),
@ -419,7 +431,7 @@ class _TrendCardState extends State<TrendCard> {
bottom: Screenutil.length(22),
right: Screenutil.length(32),
),
child: _columnCard(widget.name, widget.content, widget.isLike),
child: _columnCard(widget.name, widget.content,widget.avatar)
);
}
}

@ -116,40 +116,29 @@ class MarketCartPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
child: MarketCartAppBar(),
preferredSize: Size.fromHeight(kToolbarHeight),
),
body: FutureBuilder(
future: _getCartInfo(context),
builder: (BuildContext context, snapshot) {
if (snapshot.hasData) {
// List cartList = Provider.of<CartProvidde>(context).cartList;
return Stack(
children: [
Consumer<CartProvidde>(
builder: (context, model, child) {
List cartList = model.cartList;
return ListView.builder(
itemCount: cartList.length,
itemBuilder: (BuildContext context, int index) {
return MarketCartCard(
cartItem: cartList[index],
);
});
},
),
Positioned(
bottom: 0,
child: MarketCartBottomBar(),
),
],
);
} else {
return Text('正在加载中');
}
},
),
);
appBar: PreferredSize(
child: MarketCartAppBar(),
preferredSize: Size.fromHeight(kToolbarHeight),
),
body: Stack(
children: [
Consumer<CartProvidde>(
builder: (context, model, child) {
List cartList = model.cartList;
return ListView.builder(
itemCount: cartList.length,
itemBuilder: (BuildContext context, int index) {
return MarketCartCard(
cartItem: cartList[index],
);
});
},
),
Positioned(
bottom: 0,
child: MarketCartBottomBar(),
),
],
));
}
}

@ -12,8 +12,6 @@ class CartProvidde with ChangeNotifier {
int allGoodsCount = 0;
bool isAllCheck = true;
save(itemid, itemtitle, count, itemprice, itempic) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
cartString = prefs.getString("cartString");
@ -60,7 +58,7 @@ class CartProvidde with ChangeNotifier {
getCartInfo() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
cartString = prefs.getString("cartInfo");
cartList = [];
// cartList = [];
if (cartString == null) {
cartList = [];
} else {
@ -85,21 +83,24 @@ class CartProvidde with ChangeNotifier {
///
deleteGoods(String itemid) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
cartString = prefs.getString("cartInfo");
List<Map> tempList = (json.decode(cartString.toString()) as List).cast();
int tempIndex = 0;
int deleteIndex = 0;
tempList.forEach((item) {
if (item["itemid"] == itemid) {
deleteIndex = tempIndex;
}
tempIndex++;
});
tempList.removeAt(deleteIndex);
cartString = json.encode(tempList).toString();
prefs.setString("cartInfo", cartString);
await getCartInfo();
// SharedPreferences prefs = await SharedPreferences.getInstance();
// cartString = prefs.getString("cartInfo");
// List<Map> tempList = (json.decode(cartString.toString()) as List).cast();
// int tempIndex = 0;
// int deleteIndex = 0;
// tempList.forEach((item) {
// if (item["itemid"] == itemid) {
// deleteIndex = tempIndex;
// }
// tempIndex++;
// });
// tempList.removeAt(deleteIndex);
// cartString = json.encode(tempList).toString();
// prefs.setString("cartInfo", cartString);
// await getCartInfo();
cartList.removeWhere((element) => element.itemid == itemid);
notifyListeners();
}
///

Loading…
Cancel
Save