|
1 | 1 | import 'package:algolia_helper_flutter/algolia_helper_flutter.dart'; |
| 2 | +import 'package:cached_network_image/cached_network_image.dart'; |
2 | 3 | import 'package:flutter/material.dart'; |
3 | 4 | import 'package:freecodecamp/extensions/i18n_extension.dart'; |
| 5 | +import 'package:freecodecamp/ui/views/news/news-feed/news_feed_viewmodel.dart'; |
4 | 6 | import 'package:freecodecamp/ui/views/news/news-search/news_search_viewmodel.dart'; |
5 | 7 | import 'package:stacked/stacked.dart'; |
6 | 8 |
|
@@ -98,26 +100,132 @@ class NewsSearchView extends StatelessWidget { |
98 | 100 | itemCount: currentData.length, |
99 | 101 | separatorBuilder: (context, int i) => |
100 | 102 | const Divider( |
101 | | - color: Color.fromRGBO(0x42, 0x42, 0x55, 1), |
102 | | - thickness: 2, |
103 | | - height: 5, |
| 103 | + color: Color.fromRGBO(0x2A, 0x2A, 0x40, 1), |
| 104 | + thickness: 1, |
| 105 | + height: 1, |
104 | 106 | ), |
105 | 107 | itemBuilder: (context, index) { |
106 | | - return ListTile( |
107 | | - title: Text( |
108 | | - currentData[index]['title'], |
109 | | - maxLines: 2, |
110 | | - overflow: TextOverflow.ellipsis, |
111 | | - style: TextStyle( |
112 | | - color: |
113 | | - Colors.white.withValues(alpha: 0.87), |
| 108 | + final item = currentData[index]; |
| 109 | + final String? featureImage = item['featureImage']; |
| 110 | + final String title = item['title'] ?? ''; |
| 111 | + final String? authorName = item['author']?['name']; |
| 112 | + final String? authorImage = item['author']?['profileImage']; |
| 113 | + final String? publishedAt = item['publishedAt']; |
| 114 | + |
| 115 | + return InkWell( |
| 116 | + onTap: () => model.navigateToTutorial( |
| 117 | + item['objectID'] ?? '', |
| 118 | + item['slug'] ?? '', |
| 119 | + ), |
| 120 | + child: Padding( |
| 121 | + padding: const EdgeInsets.symmetric( |
| 122 | + vertical: 12, |
| 123 | + horizontal: 16, |
| 124 | + ), |
| 125 | + child: Row( |
| 126 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 127 | + children: [ |
| 128 | + ClipRRect( |
| 129 | + borderRadius: BorderRadius.circular(8), |
| 130 | + child: SizedBox( |
| 131 | + width: 120, |
| 132 | + height: 80, |
| 133 | + child: featureImage != null |
| 134 | + ? CachedNetworkImage( |
| 135 | + imageUrl: featureImage, |
| 136 | + fit: BoxFit.cover, |
| 137 | + placeholder: (context, url) => |
| 138 | + Container( |
| 139 | + color: const Color(0xFF2A2A40), |
| 140 | + ), |
| 141 | + errorWidget: (context, url, error) => |
| 142 | + Image.asset( |
| 143 | + 'assets/images/freecodecamp-banner.png', |
| 144 | + fit: BoxFit.cover, |
| 145 | + ), |
| 146 | + ) |
| 147 | + : Image.asset( |
| 148 | + 'assets/images/freecodecamp-banner.png', |
| 149 | + fit: BoxFit.cover, |
| 150 | + ), |
| 151 | + ), |
| 152 | + ), |
| 153 | + const SizedBox(width: 12), |
| 154 | + Expanded( |
| 155 | + child: Column( |
| 156 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 157 | + children: [ |
| 158 | + Text( |
| 159 | + title, |
| 160 | + maxLines: 2, |
| 161 | + overflow: TextOverflow.ellipsis, |
| 162 | + style: const TextStyle( |
| 163 | + fontSize: 16, |
| 164 | + fontWeight: FontWeight.w500, |
| 165 | + height: 1.3, |
| 166 | + ), |
| 167 | + ), |
| 168 | + const SizedBox(height: 8), |
| 169 | + Row( |
| 170 | + children: [ |
| 171 | + if (authorImage != null) |
| 172 | + ClipRRect( |
| 173 | + borderRadius: |
| 174 | + BorderRadius.circular(12), |
| 175 | + child: CachedNetworkImage( |
| 176 | + imageUrl: authorImage, |
| 177 | + width: 24, |
| 178 | + height: 24, |
| 179 | + fit: BoxFit.cover, |
| 180 | + errorWidget: |
| 181 | + (context, url, error) => |
| 182 | + Image.asset( |
| 183 | + 'assets/images/placeholder-profile-img.png', |
| 184 | + width: 24, |
| 185 | + height: 24, |
| 186 | + ), |
| 187 | + ), |
| 188 | + ) |
| 189 | + else |
| 190 | + Image.asset( |
| 191 | + 'assets/images/placeholder-profile-img.png', |
| 192 | + width: 24, |
| 193 | + height: 24, |
| 194 | + ), |
| 195 | + const SizedBox(width: 8), |
| 196 | + Expanded( |
| 197 | + child: Text( |
| 198 | + authorName ?? '', |
| 199 | + maxLines: 1, |
| 200 | + overflow: TextOverflow.ellipsis, |
| 201 | + style: TextStyle( |
| 202 | + fontSize: 13, |
| 203 | + color: Colors.white |
| 204 | + .withValues(alpha: 0.7), |
| 205 | + ), |
| 206 | + ), |
| 207 | + ), |
| 208 | + ], |
| 209 | + ), |
| 210 | + if (publishedAt != null) |
| 211 | + Padding( |
| 212 | + padding: const EdgeInsets.only(top: 4), |
| 213 | + child: Text( |
| 214 | + NewsFeedViewModel.parseDate( |
| 215 | + publishedAt), |
| 216 | + style: TextStyle( |
| 217 | + fontSize: 12, |
| 218 | + color: Colors.white |
| 219 | + .withValues(alpha: 0.5), |
| 220 | + ), |
| 221 | + ), |
| 222 | + ), |
| 223 | + ], |
| 224 | + ), |
| 225 | + ), |
| 226 | + ], |
114 | 227 | ), |
115 | 228 | ), |
116 | | - onTap: () => { |
117 | | - model.navigateToTutorial( |
118 | | - currentData[index]['objectID'], |
119 | | - currentData[index]['slug']), |
120 | | - }, |
121 | 229 | ); |
122 | 230 | }, |
123 | 231 | ), |
|
0 commit comments