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.
146 lines
6.3 KiB
Dart
146 lines
6.3 KiB
Dart
import 'dart:async';
|
|
import 'dart:developer';
|
|
import 'package:car_provider_app/views/subscriptions/sheet/upgrade_package_sheet.dart';
|
|
import 'package:car_provider_app/views/subscriptions/widget/my_subscriptions_card.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/view_models/subscriptions_view_model.dart';
|
|
import 'package:mc_common_app/widgets/bottom_sheet.dart';
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
class MySubscriptionsPage extends StatefulWidget {
|
|
const MySubscriptionsPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<MySubscriptionsPage> createState() => _MySubscriptionsPageState();
|
|
}
|
|
|
|
class _MySubscriptionsPageState extends State<MySubscriptionsPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// scheduleMicrotask(() {
|
|
// context.read<SubscriptionsVM>().getMySubscriptionsBySP(AppState().getUser.data?.userInfo?.providerId.toString() ?? "");
|
|
// });
|
|
}
|
|
|
|
onRenewSubscriptionClicked({required Subscription sub}) {
|
|
Subscription subscription = Subscription(
|
|
id: sub.id,
|
|
isMyCurrentPackage: true,
|
|
isExpired: sub.isExpired,
|
|
isActive: sub.isActive,
|
|
isSubscribed: true,
|
|
name: sub.name,
|
|
description: sub.description,
|
|
totalAds: sub.totalAds ?? 0,
|
|
totalBranches: sub.totalBranches ?? 0,
|
|
totalSubUsers: sub.totalSubUsers ?? 0,
|
|
countryId: 1,
|
|
countryName: "KSA",
|
|
currency: "SAR",
|
|
price: sub.price,
|
|
dateEnd: sub.dateEnd,
|
|
dateStart: sub.dateStart,
|
|
serviceProviderId: sub.serviceProviderId,
|
|
subscriptionAppliedId: sub.serviceProviderId,
|
|
);
|
|
return showMyBottomSheet(context, child: UpgradePackageSheet(subscription: subscription, isRenew: true));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(
|
|
title: LocaleKeys.mySubscription.tr(),
|
|
),
|
|
body: SizedBox(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: Consumer<SubscriptionsVM>(builder: (context, model, _) {
|
|
return model.state == ViewState.busy
|
|
? const Center(child: CircularProgressIndicator())
|
|
: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
21.height,
|
|
ListView.separated(
|
|
itemBuilder: (BuildContext context, int index) {
|
|
var sub = model.mySubscriptionsBySp[index];
|
|
return MySubscriptionsCard(
|
|
sub,
|
|
isSubscribed: false,
|
|
backgroundColor: MyColors.darkIconColor,
|
|
isMainPage: model.mySubscriptionsBySp[index].isExpired ?? false,
|
|
onRenewSubscriptionClick: () async {
|
|
onRenewSubscriptionClicked(sub: model.mySubscriptionsBySp[index]);
|
|
},
|
|
onUpgradeSubscriptionClick: () {
|
|
// print(sub.toJson());
|
|
// showMyBottomSheet(
|
|
// context,
|
|
// child: UpgradePackageSheet(
|
|
// Subscription(
|
|
// id: sub.subscriptionID,
|
|
// isMyCurrentPackage: false,
|
|
// isExpired: sub.isExpired,
|
|
// isActive: sub.isActive,
|
|
// isSubscribed: true,
|
|
// name: sub.subscriptionName,
|
|
// description: sub.subscriptionDescription,
|
|
// numberOfAds: sub.totalAds ?? 0,
|
|
// numberOfBranches: sub.totalBranches ?? 0,
|
|
// numberOfSubUsers: sub.totalSubUsers ?? 0,
|
|
// countryId: 1,
|
|
// countryName: "KSA" ,
|
|
// currency: "SAR",
|
|
// price: 0,
|
|
// dateEnd: sub.dateEnd,
|
|
// dateStart: sub.dateStart
|
|
// ),
|
|
// ),
|
|
// );
|
|
},
|
|
);
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return 21.height;
|
|
},
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
itemCount: model.mySubscriptionsBySp.length,
|
|
),
|
|
21.height,
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
ShowFillButton(
|
|
title: LocaleKeys.modifyPackage.tr(),
|
|
maxWidth: double.infinity,
|
|
margin: const EdgeInsets.symmetric(horizontal: 21),
|
|
onPressed: () {
|
|
navigateWithName(context, AppRoutes.subscriptionsPage);
|
|
},
|
|
),
|
|
21.height,
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|