Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当全部上拉加载完全部分页数据后,onLoad加载状态一直存在怎么隐藏状态 #876

Open
kinmonkey7 opened this issue Nov 30, 2024 · 0 comments

Comments

@kinmonkey7
Copy link

class ConcernPage extends StatefulWidget {
const ConcernPage({super.key});

@OverRide
State createState() => _ConcernPageState();
}

class _ConcernPageState extends State {
List? data;
bool isLoadingMore = false;
int page = 1;

Future getList({bool isRefresh = true}) async {
try {
final List response =
await getFollowList({'page': page, 'size': 3});
setState(() {
if (isRefresh) {
data =
response.map((item) => FollowListModel.fromJson(item)).toList();
} else {
data!.addAll(
response.map((item) => FollowListModel.fromJson(item)).toList());
}
});
} catch (e) {
print(e);
} finally {
if (!isRefresh) {
setState(() {
isLoadingMore = false;
});
}
}
}

@OverRide
void initState() {
getList();
super.initState();
}

@OverRide
Widget build(BuildContext context) {
return EasyRefresh(
onRefresh: () async {
page = 1;
await getList(isRefresh: true);
},
onLoad: () async {
if (!isLoadingMore) {
setState(() {
isLoadingMore = true;
page++;
});
await getList(isRefresh: false);
}
},
child: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
itemCount: data?.length ?? 0,
itemBuilder: (BuildContext context, int index) {
final item = data![index];
return Container(
margin: const EdgeInsets.only(bottom: 12),
child: ListTile(
leading: GestureDetector(
onTap: () async {
SharedPreferences prefs =
await SharedPreferences.getInstance();
await prefs.setString('orgUuid', item.uuid.toString());
Navigator.pushNamed(context, '/others_home_page');
},
child: ClipRRect(
borderRadius: BorderRadius.circular(24.r), // 半径设置为宽高的一半,即为圆形
child: AvatarView(
width: 48.r,
height: 48.r,
text: item.title,
url: item.avatar,
),
),
),
tileColor: const Color(0xffffffff),
title: Text(item.title),
subtitle: Text(item.desc ?? ''),
trailing: OutlinedButton(
onPressed: () async {
try {
final data = await updateFollow({
'follow_org_uuid': item.uuid,
'follow_from': item.followNums
});
setState(() {
item.followStatus = data['status'];
});
} catch (e) {
print(e);
}
},
style: OutlinedButton.styleFrom(
minimumSize: const Size(30, 20),
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
side: BorderSide(
color: item.followStatus == 0
? const Color(0xffD92D2C)
: const Color(0xff7F828A),
),
),
child: Text(
item.followStatus == 0 ? '关注' : '已关注',
style: TextStyle(
color: item.followStatus == 0
? const Color(0xffD92D2C)
: const Color(0xff7F828A),
),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
);
},
),
);
}
}
当全部上拉加载完全部分页数据后,加载状态一直存在怎么隐藏状态
Snipaste_2024-11-30_23-42-50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant