Skip to content

Commit dfa971e

Browse files
authored
fix: author profile tutorial list widget (#872)
1 parent 1f49dd5 commit dfa971e

File tree

1 file changed

+71
-64
lines changed

1 file changed

+71
-64
lines changed

mobile-app/lib/ui/widgets/tutorial_list_widget.dart

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import 'package:freecodecamp/ui/views/news/news-feed/news_feed_viewmodel.dart';
88

99
import 'package:http/http.dart' as http;
1010
import 'package:flutter_dotenv/flutter_dotenv.dart';
11-
12-
import 'dart:developer' as dev;
13-
1411
import 'package:stacked_services/stacked_services.dart';
1512

1613
class TutorialList extends StatefulWidget {
@@ -37,7 +34,6 @@ class TutorialList extends StatefulWidget {
3734
final http.Response response = await http.get(Uri.parse(url));
3835

3936
if (response.statusCode == 200) {
40-
dev.log(url);
4137
var tutorialJson = json.decode(response.body)['posts'];
4238
for (int i = 0; i < tutorialJson?.length; i++) {
4339
tutorials.add(Tutorial.fromJson(tutorialJson[i]));
@@ -72,36 +68,39 @@ class TutorialListState extends State<TutorialList> {
7268
@override
7369
Widget build(BuildContext context) {
7470
return FutureBuilder<List<Tutorial>>(
75-
future: widget.fetchList(),
76-
builder: (context, snapshot) {
77-
if (snapshot.hasData) {
78-
dev.log(snapshot.data!.length.toString());
79-
return Column(
80-
children: [
81-
Row(
82-
children: [
83-
TileLayout(
84-
widget: widget,
85-
snapshot: snapshot,
86-
),
87-
],
71+
future: widget.fetchList(),
72+
builder: (context, snapshot) {
73+
if (snapshot.hasData) {
74+
return Column(
75+
children: [
76+
Row(
77+
children: [
78+
TileLayout(
79+
widget: widget,
80+
snapshot: snapshot,
81+
),
82+
],
83+
),
84+
if (snapshot.data!.length > 5)
85+
Container(
86+
padding: const EdgeInsets.all(4.0),
87+
margin: const EdgeInsets.only(bottom: 48),
88+
child: ListTile(
89+
title: const Text('Show more tutorials'),
90+
tileColor: const Color(0xFF0a0a23),
91+
trailing: const Icon(Icons.arrow_forward_ios_outlined),
92+
onTap: () {
93+
widget.navigateToFeed();
94+
},
95+
),
8896
),
89-
snapshot.data!.length > 5
90-
? ListTile(
91-
title: const Text('Show more tutorials'),
92-
tileColor: const Color(0xFF0a0a23),
93-
trailing: const Icon(Icons.arrow_forward_ios_outlined),
94-
onTap: () {
95-
widget.navigateToFeed();
96-
},
97-
)
98-
: Container()
99-
],
100-
);
101-
} else {
102-
return const CircularProgressIndicator();
103-
}
104-
});
97+
],
98+
);
99+
} else {
100+
return const CircularProgressIndicator();
101+
}
102+
},
103+
);
105104
}
106105
}
107106

@@ -117,39 +116,47 @@ class TileLayout extends StatelessWidget {
117116
double imgSize = MediaQuery.of(context).size.width * 0.25;
118117

119118
return Expanded(
120-
child: ListView.builder(
121-
physics: const NeverScrollableScrollPhysics(),
122-
shrinkWrap: true,
123-
itemCount: snapshot.data!.length > 5 ? 5 : snapshot.data?.length,
124-
itemBuilder: (context, index) {
125-
Tutorial tutorial = snapshot.data![index];
126-
return ListTile(
127-
title: Text(
128-
tutorial.title,
129-
maxLines: 1,
130-
overflow: TextOverflow.ellipsis,
119+
child: ListView.separated(
120+
physics: const NeverScrollableScrollPhysics(),
121+
separatorBuilder: (context, index) => const SizedBox(
122+
height: 4,
123+
),
124+
shrinkWrap: true,
125+
padding: const EdgeInsets.all(4),
126+
itemCount: snapshot.data!.length > 5 ? 5 : snapshot.data?.length ?? 1,
127+
itemBuilder: (context, index) {
128+
Tutorial tutorial = snapshot.data![index];
129+
return ListTile(
130+
title: Text(
131+
tutorial.title,
132+
maxLines: 2,
133+
overflow: TextOverflow.ellipsis,
134+
),
135+
tileColor: const Color(0xFF0a0a23),
136+
isThreeLine: true,
137+
contentPadding: const EdgeInsets.symmetric(
138+
horizontal: 10,
139+
vertical: 10,
140+
),
141+
subtitle: Text(
142+
NewsFeedViewModel.parseDate(tutorial.createdAt),
143+
),
144+
trailing: Container(
145+
constraints: BoxConstraints(
146+
minWidth: imgSize,
147+
maxWidth: imgSize,
131148
),
132-
tileColor: const Color(0xFF0a0a23),
133-
contentPadding:
134-
const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
135-
horizontalTitleGap: 10,
136-
subtitle: Text(
137-
NewsFeedViewModel.parseDate(tutorial.createdAt),
138-
style: const TextStyle(height: 2),
149+
child: Image.network(
150+
tutorial.featureImage,
151+
fit: BoxFit.cover,
139152
),
140-
trailing: Container(
141-
constraints:
142-
BoxConstraints(minWidth: imgSize, maxWidth: imgSize),
143-
child: Image.network(
144-
tutorial.featureImage,
145-
fit: BoxFit.cover,
146-
),
147-
),
148-
onTap: () {
149-
widget.navigateToTutorial(tutorial.id, tutorial.title);
150-
},
151-
);
152-
}),
153+
),
154+
onTap: () {
155+
widget.navigateToTutorial(tutorial.id, tutorial.title);
156+
},
157+
);
158+
},
159+
),
153160
);
154161
}
155162
}

0 commit comments

Comments
 (0)