@@ -8,9 +8,6 @@ import 'package:freecodecamp/ui/views/news/news-feed/news_feed_viewmodel.dart';
8
8
9
9
import 'package:http/http.dart' as http;
10
10
import 'package:flutter_dotenv/flutter_dotenv.dart' ;
11
-
12
- import 'dart:developer' as dev;
13
-
14
11
import 'package:stacked_services/stacked_services.dart' ;
15
12
16
13
class TutorialList extends StatefulWidget {
@@ -37,7 +34,6 @@ class TutorialList extends StatefulWidget {
37
34
final http.Response response = await http.get (Uri .parse (url));
38
35
39
36
if (response.statusCode == 200 ) {
40
- dev.log (url);
41
37
var tutorialJson = json.decode (response.body)['posts' ];
42
38
for (int i = 0 ; i < tutorialJson? .length; i++ ) {
43
39
tutorials.add (Tutorial .fromJson (tutorialJson[i]));
@@ -72,36 +68,39 @@ class TutorialListState extends State<TutorialList> {
72
68
@override
73
69
Widget build (BuildContext context) {
74
70
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
+ ),
88
96
),
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
+ );
105
104
}
106
105
}
107
106
@@ -117,39 +116,47 @@ class TileLayout extends StatelessWidget {
117
116
double imgSize = MediaQuery .of (context).size.width * 0.25 ;
118
117
119
118
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,
131
148
),
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,
139
152
),
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
+ ),
153
160
);
154
161
}
155
162
}
0 commit comments