|
|
|
|
@ -3,20 +3,20 @@ 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/widgets/button/show_fill_button.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/common_widgets/ads_list.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:mc_common_app/views/advertisement/ads_list.dart';
|
|
|
|
|
|
|
|
|
|
class AdsFragment extends StatefulWidget {
|
|
|
|
|
AdsFragment({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<AdsFragment> createState() => _AdsFragmentState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AdsFragmentState extends State<AdsFragment> {
|
|
|
|
|
bool isExploreAdsTapped = true;
|
|
|
|
|
class AdsFragment extends StatelessWidget {
|
|
|
|
|
AdsFragment({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
bool isMyAdsTapped = false;
|
|
|
|
|
Future<void> onRefreshAds(BuildContext context) async {
|
|
|
|
|
AdVM adVM = context.read<AdVM>();
|
|
|
|
|
await adVM.getAllAds();
|
|
|
|
|
await adVM.getMyAds();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
@ -28,51 +28,48 @@ class _AdsFragmentState extends State<AdsFragment> {
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
16.height,
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowFillButton(
|
|
|
|
|
isFilled: isExploreAdsTapped,
|
|
|
|
|
maxHeight: 55,
|
|
|
|
|
title: "Explore Ads",
|
|
|
|
|
txtColor: isExploreAdsTapped ? MyColors.white : MyColors.darkTextColor,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
if (!isExploreAdsTapped) {
|
|
|
|
|
isExploreAdsTapped = true;
|
|
|
|
|
isMyAdsTapped = false;
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
12.width,
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowFillButton(
|
|
|
|
|
isFilled: isMyAdsTapped,
|
|
|
|
|
txtColor: isMyAdsTapped ? MyColors.white : MyColors.darkTextColor,
|
|
|
|
|
maxHeight: 55,
|
|
|
|
|
title: "My Ads",
|
|
|
|
|
onPressed: () {
|
|
|
|
|
if (!isMyAdsTapped) {
|
|
|
|
|
isMyAdsTapped = true;
|
|
|
|
|
isExploreAdsTapped = false;
|
|
|
|
|
}
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
Consumer(
|
|
|
|
|
builder: (BuildContext context, AdVM adVM, Widget? child) {
|
|
|
|
|
return Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowFillButton(
|
|
|
|
|
isFilled: adVM.isExploreAdsTapped,
|
|
|
|
|
maxHeight: 55,
|
|
|
|
|
title: "Explore Ads",
|
|
|
|
|
txtColor: adVM.isExploreAdsTapped ? MyColors.white : MyColors.darkTextColor,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
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);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
24.height,
|
|
|
|
|
Expanded(
|
|
|
|
|
child: BuildAdsList(
|
|
|
|
|
count: 20,
|
|
|
|
|
onAdPressed: () {
|
|
|
|
|
navigateWithName(
|
|
|
|
|
context,
|
|
|
|
|
AppRoutes.adsDetailView,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: RefreshIndicator(
|
|
|
|
|
onRefresh: () => onRefreshAds(context),
|
|
|
|
|
child: Consumer(
|
|
|
|
|
builder: (BuildContext context, AdVM adVM, Widget? child) {
|
|
|
|
|
return BuildAdsList(
|
|
|
|
|
adsList: adVM.isExploreAdsTapped ? adVM.allAds : adVM.myAds,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -80,6 +77,8 @@ class _AdsFragmentState extends State<AdsFragment> {
|
|
|
|
|
),
|
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
context.read<AdVM>().getVehicleTypes();
|
|
|
|
|
|
|
|
|
|
navigateWithName(context, AppRoutes.createAdView);
|
|
|
|
|
},
|
|
|
|
|
backgroundColor: MyColors.darkPrimaryColor,
|
|
|
|
|
|