Skip to content

Commit b95d94c

Browse files
committed
'解决第一次加载数据后列表不渲染问题'
1 parent 9fde5ec commit b95d94c

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

lib/widgets/FirstScreen/HotProduct.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class HotProduct extends StatelessWidget {
1616
@override
1717
Widget build(BuildContext context) {
1818
final homeStore = Provider.of<HomeStore>(context);
19-
List<CommonData> hotBooksData = homeStore.hotBooksData?.data;
2019

2120
return Column(
2221
children: <Widget>[
@@ -37,7 +36,9 @@ class HotProduct extends StatelessWidget {
3736
Container(
3837
width: MediaQuery.of(context).size.width,
3938
child: Observer(
40-
builder: (_) => hotBooksData == null
39+
builder: (_) {
40+
List<CommonData> hotBooksData = homeStore.hotBooksData?.data;
41+
return hotBooksData == null
4142
? Text("正在获取数据")
4243
: Wrap(
4344
// spacing: 20.0,
@@ -50,7 +51,8 @@ class HotProduct extends StatelessWidget {
5051
imageUrl: data.bookImage,
5152
author: data.author))
5253
.toList(),
53-
),
54+
);
55+
},
5456
),
5557
),
5658
],

lib/widgets/FirstScreen/PopularBooks.dart

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class PopularBooks extends StatelessWidget {
1313
@override
1414
Widget build(BuildContext context) {
1515
final homeStore = Provider.of<HomeStore>(context);
16-
List<CommonData> popularBookData = homeStore.recommendData?.data;
1716
return Column(
1817
children: <Widget>[
1918
SizedBox(
@@ -34,22 +33,25 @@ class PopularBooks extends StatelessWidget {
3433
height: 32.0,
3534
),
3635
Observer(
37-
builder: (_) => popularBookData == null
38-
? Text("正在获取数据")
39-
: Container(
40-
height: 140.0,
41-
child: ListView(
42-
scrollDirection: Axis.horizontal,
43-
children: popularBookData
44-
.map((CommonData data) => Container(
45-
margin: EdgeInsets.only(right: 16.0),
46-
child: CommonBookCard(
47-
title: data.title,
48-
bookImage: data.bookImage,
49-
description:data.description.trimLeft(),
50-
)))
51-
.toList()),
52-
),
36+
builder: (_) {
37+
List<CommonData> popularBookData = homeStore.recommendData?.data;
38+
return popularBookData == null
39+
? Text("正在获取数据")
40+
: Container(
41+
height: 140.0,
42+
child: ListView(
43+
scrollDirection: Axis.horizontal,
44+
children: popularBookData
45+
.map((CommonData data) => Container(
46+
margin: EdgeInsets.only(right: 16.0),
47+
child: CommonBookCard(
48+
title: data.title,
49+
bookImage: data.bookImage,
50+
description: data.description.trimLeft(),
51+
)))
52+
.toList()),
53+
);
54+
},
5355
),
5456
],
5557
);

lib/widgets/FirstScreen/Recommend.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class Recommend extends StatelessWidget {
2424
@override
2525
Widget build(BuildContext context) {
2626
final homeStore = Provider.of<HomeStore>(context);
27-
List<CommonData> recommendData = homeStore.recommendData?.data;
28-
return Observer(
29-
builder: (_) => recommendData == null
27+
return Observer(builder: (_) {
28+
List<CommonData> recommendData = homeStore.recommendData?.data;
29+
return recommendData == null
3030
? Text("正在获取数据")
3131
: Column(
3232
children: <Widget>[
@@ -46,11 +46,12 @@ class Recommend extends StatelessWidget {
4646
margin: EdgeInsets.only(top: 40.0, bottom: 18.0),
4747
child: ListView(
4848
scrollDirection: Axis.horizontal,
49-
children: cardList(recommendData),
49+
children: cardList(homeStore.recommendData?.data),
5050
),
5151
)
5252
],
53-
));
53+
);
54+
});
5455
}
5556
}
5657

0 commit comments

Comments
 (0)