|
1 | | -import 'dart:io'; |
2 | | - |
| 1 | +import 'package:cached_network_image/cached_network_image.dart'; |
| 2 | +import 'package:find_room/app/app_locale_bloc.dart'; |
3 | 3 | import 'package:find_room/bloc/bloc_provider.dart'; |
| 4 | +import 'package:find_room/generated/i18n.dart'; |
4 | 5 | import 'package:find_room/pages/detail/related/related_rooms_tab_bloc.dart'; |
5 | 6 | import 'package:find_room/pages/detail/related/related_rooms_tab_state.dart'; |
6 | 7 | import 'package:flutter/material.dart'; |
| 8 | +import 'package:intl/intl.dart'; |
7 | 9 |
|
8 | 10 | class RelatedRoomsTabPage extends StatefulWidget { |
9 | 11 | const RelatedRoomsTabPage({Key key}) : super(key: key); |
@@ -42,6 +44,33 @@ class _RelatedRoomsTabPageState extends State<RelatedRoomsTabPage> { |
42 | 44 | error: state.error, |
43 | 45 | ); |
44 | 46 | } |
| 47 | + |
| 48 | + if (state.items.isEmpty) { |
| 49 | + return Container( |
| 50 | + constraints: BoxConstraints.expand(), |
| 51 | + child: Center( |
| 52 | + child: Column( |
| 53 | + mainAxisAlignment: MainAxisAlignment.center, |
| 54 | + children: <Widget>[ |
| 55 | + Icon( |
| 56 | + Icons.home, |
| 57 | + size: 48, |
| 58 | + color: Theme.of(context).accentColor, |
| 59 | + ), |
| 60 | + const SizedBox(height: 8), |
| 61 | + Text( |
| 62 | + 'Empty related rooms', |
| 63 | + style: Theme.of(context) |
| 64 | + .textTheme |
| 65 | + .title |
| 66 | + .copyWith(fontSize: 15), |
| 67 | + ), |
| 68 | + ], |
| 69 | + ), |
| 70 | + ), |
| 71 | + ); |
| 72 | + } |
| 73 | + |
45 | 74 | return RefreshIndicator( |
46 | 75 | child: ListView.builder( |
47 | 76 | physics: AlwaysScrollableScrollPhysics(), |
@@ -117,63 +146,141 @@ class ListItemWidget extends StatelessWidget { |
117 | 146 |
|
118 | 147 | @override |
119 | 148 | Widget build(BuildContext context) { |
| 149 | + final currentLocale = |
| 150 | + BlocProvider.of<LocaleBloc>(context).locale$.value.languageCode; |
| 151 | + final subTitle14 = |
| 152 | + Theme.of(context).textTheme.subtitle.copyWith(fontSize: 14); |
| 153 | + final subTitle12 = subTitle14.copyWith(fontSize: 12); |
| 154 | + |
| 155 | + final imageW = 64 * 1.5; |
| 156 | + final imageH = 96 * 1.5; |
| 157 | + |
120 | 158 | return Container( |
121 | 159 | margin: const EdgeInsets.all(4), |
122 | | - padding: const EdgeInsets.all(12), |
123 | 160 | decoration: BoxDecoration( |
124 | 161 | color: Theme.of(context).canvasColor, |
125 | 162 | borderRadius: BorderRadius.circular(12), |
126 | 163 | boxShadow: [ |
127 | 164 | BoxShadow( |
128 | | - blurRadius: 16, |
| 165 | + blurRadius: 8, |
129 | 166 | offset: Offset(0, 4), |
130 | | - color: Colors.grey.shade600, |
| 167 | + color: Colors.grey.shade400, |
131 | 168 | ) |
132 | 169 | ], |
133 | 170 | ), |
134 | | - child: Row( |
135 | | - children: <Widget>[ |
136 | | - Container( |
137 | | - decoration: BoxDecoration(shape: BoxShape.circle, boxShadow: [ |
138 | | - BoxShadow( |
139 | | - blurRadius: 10, |
140 | | - offset: Offset(2, 2), |
141 | | - color: Colors.grey.shade500, |
142 | | - spreadRadius: 1) |
143 | | - ]), |
144 | | - child: ClipOval( |
145 | | - child: Image.network( |
146 | | - '', |
147 | | - width: 64, |
148 | | - height: 64, |
149 | | - fit: BoxFit.cover, |
150 | | - ), |
151 | | - ), |
152 | | - ), |
153 | | - SizedBox( |
154 | | - width: 16, |
155 | | - ), |
156 | | - Expanded( |
157 | | - child: Column( |
158 | | - crossAxisAlignment: CrossAxisAlignment.stretch, |
159 | | - children: <Widget>[ |
160 | | - Text( |
161 | | - '${item.id} ${item.id}', |
162 | | - textAlign: TextAlign.left, |
163 | | - style: Theme.of(context).textTheme.title, |
164 | | - ), |
165 | | - SizedBox( |
166 | | - height: 8, |
| 171 | + child: Material( |
| 172 | + child: InkWell( |
| 173 | + onTap: () { |
| 174 | + Navigator.pushNamed( |
| 175 | + context, |
| 176 | + '/room_detail', |
| 177 | + arguments: item.id, |
| 178 | + ); |
| 179 | + }, |
| 180 | + child: Row( |
| 181 | + children: <Widget>[ |
| 182 | + ClipRRect( |
| 183 | + borderRadius: BorderRadius.circular(12), |
| 184 | + child: CachedNetworkImage( |
| 185 | + imageUrl: item.imageUrl ?? '', |
| 186 | + width: imageW, |
| 187 | + height: imageH, |
| 188 | + fit: BoxFit.cover, |
| 189 | + placeholder: (_, __) => Container( |
| 190 | + width: imageW, |
| 191 | + height: imageH, |
| 192 | + child: Center( |
| 193 | + child: CircularProgressIndicator( |
| 194 | + strokeWidth: 2, |
| 195 | + ), |
| 196 | + ), |
| 197 | + ), |
| 198 | + errorWidget: (_, __, ___) => Center( |
| 199 | + child: Container( |
| 200 | + width: imageW, |
| 201 | + height: imageH, |
| 202 | + child: Column( |
| 203 | + mainAxisAlignment: MainAxisAlignment.center, |
| 204 | + children: <Widget>[ |
| 205 | + Icon(Icons.error_outline), |
| 206 | + Text( |
| 207 | + 'Error', |
| 208 | + style: subTitle12, |
| 209 | + ), |
| 210 | + ], |
| 211 | + ), |
| 212 | + ), |
| 213 | + ), |
167 | 214 | ), |
168 | | - Text( |
169 | | - item.id, |
170 | | - textAlign: TextAlign.left, |
171 | | - style: Theme.of(context).textTheme.subtitle, |
| 215 | + ), |
| 216 | + SizedBox( |
| 217 | + width: 16, |
| 218 | + ), |
| 219 | + Expanded( |
| 220 | + child: Column( |
| 221 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 222 | + mainAxisSize: MainAxisSize.max, |
| 223 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 224 | + children: <Widget>[ |
| 225 | + Text( |
| 226 | + item.title, |
| 227 | + maxLines: 2, |
| 228 | + textAlign: TextAlign.start, |
| 229 | + overflow: TextOverflow.ellipsis, |
| 230 | + style: Theme.of(context).textTheme.title.copyWith( |
| 231 | + fontSize: 16, |
| 232 | + fontWeight: FontWeight.bold, |
| 233 | + ), |
| 234 | + ), |
| 235 | + Text( |
| 236 | + '${item.districtName} - ${item.address}', |
| 237 | + maxLines: 2, |
| 238 | + textAlign: TextAlign.start, |
| 239 | + overflow: TextOverflow.ellipsis, |
| 240 | + style: subTitle14, |
| 241 | + ), |
| 242 | + SizedBox( |
| 243 | + height: 4, |
| 244 | + ), |
| 245 | + Text( |
| 246 | + item.price, |
| 247 | + maxLines: 1, |
| 248 | + textAlign: TextAlign.start, |
| 249 | + overflow: TextOverflow.ellipsis, |
| 250 | + style: Theme.of(context).textTheme.subtitle.copyWith( |
| 251 | + fontSize: 15, |
| 252 | + color: Theme.of(context).accentColor, |
| 253 | + fontWeight: FontWeight.bold, |
| 254 | + ), |
| 255 | + ), |
| 256 | + SizedBox( |
| 257 | + height: 4, |
| 258 | + ), |
| 259 | + Text( |
| 260 | + S.of(context).created_date(DateFormat.yMMMd(currentLocale) |
| 261 | + .add_Hm() |
| 262 | + .format(item.createdTime)), |
| 263 | + maxLines: 1, |
| 264 | + textAlign: TextAlign.start, |
| 265 | + overflow: TextOverflow.ellipsis, |
| 266 | + style: subTitle12, |
| 267 | + ), |
| 268 | + Text( |
| 269 | + S.of(context).last_updated_date( |
| 270 | + DateFormat.yMMMd(currentLocale) |
| 271 | + .add_Hm() |
| 272 | + .format(item.createdTime)), |
| 273 | + maxLines: 1, |
| 274 | + textAlign: TextAlign.start, |
| 275 | + overflow: TextOverflow.ellipsis, |
| 276 | + style: subTitle12, |
| 277 | + ), |
| 278 | + ], |
172 | 279 | ), |
173 | | - ], |
174 | | - ), |
| 280 | + ), |
| 281 | + ], |
175 | 282 | ), |
176 | | - ], |
| 283 | + ), |
177 | 284 | ), |
178 | 285 | ); |
179 | 286 | } |
|
0 commit comments