You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
187 lines
6.9 KiB
Dart
187 lines
6.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
import 'package:mc_common_app/models/advertisment_models/ad_details_model.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
import 'package:mc_common_app/view_models/ad_view_model.dart';
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class BuildAdsList extends StatelessWidget {
|
|
final List<AdDetailsModel> adsList;
|
|
final ScrollPhysics? scrollPhysics;
|
|
final bool isAdsFragment;
|
|
final bool shouldShowAdStatus;
|
|
|
|
const BuildAdsList({
|
|
Key? key,
|
|
required this.adsList,
|
|
this.scrollPhysics,
|
|
required this.shouldShowAdStatus,
|
|
this.isAdsFragment = false,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (isAdsFragment && adsList.isEmpty) {
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
"No Ads to show.".toText(fontSize: 16, color: MyColors.lightTextColor),
|
|
],
|
|
);
|
|
}
|
|
return ListView.builder(
|
|
itemCount: adsList.length,
|
|
shrinkWrap: true,
|
|
physics: scrollPhysics,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 8),
|
|
child: AdCard(
|
|
adDetails: adsList[index],
|
|
isAdsFragment: isAdsFragment,
|
|
shouldShowAdStatus: shouldShowAdStatus,
|
|
),
|
|
).onPress(() {
|
|
navigateWithName(context, AppRoutes.adsDetailView, arguments: adsList[index]);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
class AdCard extends StatelessWidget {
|
|
final AdDetailsModel adDetails;
|
|
final bool isAdsFragment;
|
|
final bool shouldShowAdStatus;
|
|
|
|
const AdCard({Key? key, required this.adDetails, required this.isAdsFragment, required this.shouldShowAdStatus}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Image.network(
|
|
adDetails.vehicle!.image!.first.imageUrl!,
|
|
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
|
|
return const SizedBox(
|
|
width: 80,
|
|
height: 80,
|
|
child: Icon(Icons.error_outline),
|
|
);
|
|
},
|
|
width: 80,
|
|
height: 80,
|
|
fit: BoxFit.cover,
|
|
),
|
|
12.width,
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
if (shouldShowAdStatus) ...[
|
|
Utils.statusContainerChip(text: adDetails.statuslabel!, chipColor: Utils.getChipColorByAdStatus(adDetails.adPostStatus!)),
|
|
],
|
|
(adDetails.vehicle!.vehicleTitle ?? "").toText(fontSize: 16, isBold: true),
|
|
Row(
|
|
children: [
|
|
"Model:".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
2.width,
|
|
(adDetails.vehicle!.modelyear!.label ?? "").toText(),
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
"Mileage:".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
2.width,
|
|
(adDetails.vehicle!.mileage!.mileageEnd ?? "").toText(),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
(adDetails.vehicle!.cityName ?? "").toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
adDetails.createdOn != null
|
|
? DateTime.parse(adDetails.createdOn!).getTimeAgo().toText(
|
|
color: MyColors.lightTextColor,
|
|
)
|
|
: const SizedBox(),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
8.height,
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
(adDetails.vehicle!.demandAmount!.toInt().toString()).toText(fontSize: 16, isBold: true),
|
|
2.width,
|
|
"SAR".toText(
|
|
color: MyColors.lightTextColor,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Icon(Icons.arrow_forward)
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (false)
|
|
Container(
|
|
height: 100,
|
|
alignment: Alignment.center,
|
|
color: MyColors.white.withOpacity(0.9),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
MyAssets.reservedConeIcon.buildSvg(),
|
|
5.width,
|
|
"Reserved".toText(
|
|
color: MyColors.darkPrimaryColor,
|
|
fontSize: 17,
|
|
isBold: true,
|
|
)
|
|
],
|
|
),
|
|
)
|
|
else
|
|
const SizedBox(),
|
|
],
|
|
).toWhiteContainer(width: double.infinity, allPading: 12, margin: const EdgeInsets.symmetric(horizontal: 21));
|
|
}
|
|
}
|