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.
car_customer_app/lib/views/dashboard/fragments/ads_fragment.dart

119 lines
4.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:mc_common_app/classes/app_state.dart';
3 years ago
import 'package:mc_common_app/config/routes.dart';
import 'package:mc_common_app/extensions/int_extensions.dart';
import 'package:mc_common_app/theme/colors.dart';
import 'package:mc_common_app/utils/navigator.dart';
import 'package:mc_common_app/view_models/ad_view_model.dart';
import 'package:mc_common_app/views/advertisement/ads_list.dart';
3 years ago
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
import 'package:mc_common_app/widgets/common_widgets/categories_list.dart';
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
import 'package:provider/provider.dart';
class AdsFragment extends StatelessWidget {
AdsFragment({Key? key}) : super(key: key);
3 years ago
Future<void> onRefreshAds(BuildContext context) async {
AdVM adVM = context.read<AdVM>();
await adVM.getExploreAds();
await adVM.getMyAds();
}
@override
Widget build(BuildContext context) {
3 years ago
return Scaffold(
body: Container(
color: MyColors.backgroundColor,
width: double.infinity,
height: double.infinity,
child: Column(
children: [
16.height,
Consumer(
builder: (BuildContext context, AdVM adVM, Widget? child) {
return Column(
children: [
Row(
children: [
Expanded(
child: ShowFillButton(
isFilled: adVM.isExploreAdsTapped,
maxHeight: 55,
title: "Explore Ads",
txtColor: adVM.isExploreAdsTapped ? MyColors.white : MyColors.darkTextColor,
onPressed: () {
print("ads: ${AppState().getUser.data!.accessToken}");
adVM.updateIsExploreAds(true);
},
),
),
12.width,
Expanded(
child: ShowFillButton(
isFilled: !adVM.isExploreAdsTapped,
txtColor: !adVM.isExploreAdsTapped ? MyColors.white : MyColors.darkTextColor,
maxHeight: 55,
title: "My Ads",
onPressed: () {
adVM.updateIsExploreAds(false);
},
),
),
],
).horPaddingMain(),
if (adVM.isExploreAdsTapped && adVM.exploreAds.isNotEmpty) ...[
16.height,
FiltersList(filterList: adVM.exploreAdsFilterOptions, onFilterTapped: (index, selectedFilterId) => adVM.applyFilterOnExploreAds(index: index), needLeftPadding: false)
.paddingOnly(left: 21),
],
if (!adVM.isExploreAdsTapped && adVM.myAds.isNotEmpty) ...[
16.height,
FiltersList(
filterList: adVM.myAdsFilterOptions,
onFilterTapped: (index, selectedFilterId) => adVM.applyFilterOnMyAds(index: index, selectedFilterId: selectedFilterId),
needLeftPadding: false)
.paddingOnly(left: 21),
],
],
);
},
3 years ago
),
16.height,
3 years ago
Expanded(
child: RefreshIndicator(
onRefresh: () => onRefreshAds(context),
child: Consumer(
builder: (BuildContext context, AdVM adVM, Widget? child) {
return BuildAdsList(
isAdsFragment: true,
shouldShowAdStatus: !adVM.isExploreAdsTapped,
adsList: adVM.isExploreAdsTapped && adVM.exploreAdsFilteredList.isNotEmpty
? adVM.exploreAdsFilteredList
: !adVM.isExploreAdsTapped && adVM.myAdsFilteredList.isNotEmpty
? adVM.myAdsFilteredList
: [],
);
},
),
),
)
3 years ago
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
context.read<AdVM>().getVehicleTypes();
3 years ago
navigateWithName(context, AppRoutes.createAdView);
},
backgroundColor: MyColors.darkPrimaryColor,
child: Icon(
Icons.add,
color: MyColors.white,
),
),
);
}
}