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.
103 lines
3.8 KiB
Dart
103 lines
3.8 KiB
Dart
import 'package:mc_common_app/view_models/ad_view_model.dart';
|
|
import 'package:mc_common_app/views/advertisement/ads_list.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
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/widgets/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/categories_list.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class AdsFragment extends StatelessWidget {
|
|
AdsFragment({Key? key}) : super(key: key);
|
|
|
|
Future<void> onRefreshAds(BuildContext context) async {
|
|
AdVM adVM = context.read<AdVM>();
|
|
await adVM.getAllAds();
|
|
await adVM.getMyAds();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (adVM.isExploreAdsTapped) ...[
|
|
16.height,
|
|
FiltersList(filterList: adVM.adsFilterOptions, onFilterTapped: (index) => adVM.applyFilterOnAds(index: index), needLeftPadding: false),
|
|
],
|
|
],
|
|
);
|
|
},
|
|
),
|
|
16.height,
|
|
Expanded(
|
|
child: RefreshIndicator(
|
|
onRefresh: () => onRefreshAds(context),
|
|
child: Consumer(
|
|
builder: (BuildContext context, AdVM adVM, Widget? child) {
|
|
return BuildAdsList(
|
|
adsList: adVM.isExploreAdsTapped && adVM.adsFilteredList.isNotEmpty ? adVM.adsFilteredList : adVM.myAds,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
context.read<AdVM>().getVehicleTypes();
|
|
|
|
navigateWithName(context, AppRoutes.createAdView);
|
|
},
|
|
backgroundColor: MyColors.darkPrimaryColor,
|
|
child: Icon(
|
|
Icons.add,
|
|
color: MyColors.white,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|