subscription 4.0
parent
9824303de1
commit
178789fa38
@ -0,0 +1,294 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mc_common_app/classes/app_state.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/general_models/m_response.dart';
|
||||||
|
import 'package:mc_common_app/models/subscriptions_models/branch_user_selection_model.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/utils/utils.dart';
|
||||||
|
import 'package:mc_common_app/view_models/payment_view_model.dart';
|
||||||
|
import 'package:mc_common_app/view_models/subscriptions_view_model.dart';
|
||||||
|
import 'package:mc_common_app/views/payments/payment_methods_view.dart';
|
||||||
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
||||||
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class DowngradeDataSheet extends StatefulWidget {
|
||||||
|
Subscription subscription;
|
||||||
|
|
||||||
|
DowngradeDataSheet(this.subscription, {super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DowngradeDataSheet> createState() => _DowngradeDataSheetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DowngradeDataSheetState extends State<DowngradeDataSheet> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
context.read<SubscriptionsVM>().getSPBranchUser_Get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: MediaQuery.of(context).size.height / 1.2,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
"Deactivate the branches & users".toText(
|
||||||
|
fontSize: 19,
|
||||||
|
isBold: true,
|
||||||
|
),
|
||||||
|
8.height,
|
||||||
|
"To select this subscription you need to deactivate your branches and users as this package only supports 1 branch and 2 users per branch. You can reactivate these branches later after upgrading the package"
|
||||||
|
.toText(
|
||||||
|
fontSize: 14,
|
||||||
|
color: MyColors.textColor,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Consumer<SubscriptionsVM>(
|
||||||
|
builder: (BuildContext context, model, Widget? child) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: model.branchSelectionList == null
|
||||||
|
? const Center(child: CircularProgressIndicator())
|
||||||
|
: ListView.separated(
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return showBranchItem(
|
||||||
|
model, model.branchSelectionList![index]);
|
||||||
|
},
|
||||||
|
separatorBuilder: (context, index) {
|
||||||
|
return 12.height;
|
||||||
|
},
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
itemCount: model.branchSelectionList?.length ?? 0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ShowFillButton(
|
||||||
|
title: "Next",
|
||||||
|
maxWidth: double.infinity,
|
||||||
|
margin: const EdgeInsets.all(12),
|
||||||
|
onPressed: () async {
|
||||||
|
List<int> listOfBranches = [];
|
||||||
|
List<int> listOfUsers = [];
|
||||||
|
for (var element in model.branchSelectionList!) {
|
||||||
|
if (element.isSelected) {
|
||||||
|
listOfBranches.add(element.branchId);
|
||||||
|
} else {
|
||||||
|
for (var element in element.usersList) {
|
||||||
|
if (element.isSelected) {
|
||||||
|
listOfUsers.add(element.userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print("opoewww");
|
||||||
|
print(jsonEncode(listOfBranches));
|
||||||
|
if (listOfBranches.isNotEmpty ||
|
||||||
|
listOfUsers.isNotEmpty) {
|
||||||
|
navigateTo(
|
||||||
|
context,
|
||||||
|
PaymentMethodsView(
|
||||||
|
paymentType: PaymentTypes.subscription,
|
||||||
|
onTempContinue: () async {
|
||||||
|
Utils.showLoading(context);
|
||||||
|
MResponse response =
|
||||||
|
await model.payForSubscription(
|
||||||
|
widget.subscription.id!,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
widget.subscription.price.toString(),
|
||||||
|
isDegrade: true,
|
||||||
|
listOfBranches: listOfBranches,
|
||||||
|
listOfUsers: listOfUsers,
|
||||||
|
);
|
||||||
|
Utils.hideLoading(context);
|
||||||
|
|
||||||
|
if (response.messageStatus == 1) {
|
||||||
|
if(response.message!.contains("Your current sub-users are not")){
|
||||||
|
Utils.showToast(response.message.toString());
|
||||||
|
context.read<SubscriptionsVM>().getMySubscriptions(
|
||||||
|
AppState()
|
||||||
|
.getUser
|
||||||
|
.data
|
||||||
|
?.userInfo
|
||||||
|
?.providerId
|
||||||
|
.toString() ??
|
||||||
|
"");
|
||||||
|
pop(context);
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
context
|
||||||
|
.read<PaymentVM>()
|
||||||
|
.updateOrderProviderSubscriptionId(
|
||||||
|
id: response.data);
|
||||||
|
|
||||||
|
// Utils.showToast(
|
||||||
|
// "Subscriptions is successfully updated");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Utils.showToast(response.message.toString());
|
||||||
|
context.read<SubscriptionsVM>().getMySubscriptions(
|
||||||
|
AppState()
|
||||||
|
.getUser
|
||||||
|
.data
|
||||||
|
?.userInfo
|
||||||
|
?.providerId
|
||||||
|
.toString() ??
|
||||||
|
"");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget showBranchItem(SubscriptionsVM viewModel, BranchSelectionModel model) {
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
customCheckBox(model.isSelected).onPress(() {
|
||||||
|
model.isSelected = !model.isSelected;
|
||||||
|
if (model.isSelected) {
|
||||||
|
for (var element in model.usersList) {
|
||||||
|
element.isSelected = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var element in model.usersList) {
|
||||||
|
element.isSelected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.isOpend = true;
|
||||||
|
viewModel.setState(ViewState.idle);
|
||||||
|
}),
|
||||||
|
12.width,
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
model.branchName.toText(
|
||||||
|
fontSize: 18,
|
||||||
|
isBold: true,
|
||||||
|
),
|
||||||
|
("${model.usersList.length} Users").toText(
|
||||||
|
fontSize: 10,
|
||||||
|
color: MyColors.lightTextColor,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
model.isOpend
|
||||||
|
? Icons.keyboard_arrow_up_rounded
|
||||||
|
: Icons.keyboard_arrow_down_rounded,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (model.isOpend) 12.height,
|
||||||
|
if (model.isOpend)
|
||||||
|
ListView.separated(
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
customCheckBox(model.usersList[index].isSelected),
|
||||||
|
8.width,
|
||||||
|
model.usersList[index].userName.toText(
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).onPress(() {
|
||||||
|
// for (int i = 0; i < model.usersList.length; i++) {
|
||||||
|
// if (i != index) {
|
||||||
|
// model.usersList[index].isSelected = false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
model.usersList[index].isSelected =
|
||||||
|
!model.usersList[index].isSelected;
|
||||||
|
viewModel.setState(ViewState.idle);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
separatorBuilder: (context, index) {
|
||||||
|
return 12.height;
|
||||||
|
},
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount: model.usersList.length,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).onPress(() {
|
||||||
|
model.isOpend = !model.isOpend;
|
||||||
|
viewModel.setState(ViewState.idle);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
).toWhiteContainer(
|
||||||
|
width: double.infinity,
|
||||||
|
pading: const EdgeInsets.all(12),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget customCheckBox(bool isChecked) {
|
||||||
|
return SizedBox(
|
||||||
|
height: 18,
|
||||||
|
width: 18,
|
||||||
|
child: isChecked
|
||||||
|
? const Icon(
|
||||||
|
Icons.done,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 14,
|
||||||
|
)
|
||||||
|
: const SizedBox(),
|
||||||
|
).toContainer(
|
||||||
|
isEnabledBorder: true,
|
||||||
|
paddingAll: 0,
|
||||||
|
borderRadius: 0,
|
||||||
|
borderWidget: 1,
|
||||||
|
borderColor: MyColors.primaryColor,
|
||||||
|
backgroundColor: isChecked ? MyColors.primaryColor : Colors.transparent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,199 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mc_common_app/classes/app_state.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/general_models/m_response.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/date_helper.dart';
|
||||||
|
import 'package:mc_common_app/utils/enums.dart';
|
||||||
|
import 'package:mc_common_app/utils/navigator.dart';
|
||||||
|
import 'package:mc_common_app/utils/utils.dart';
|
||||||
|
import 'package:mc_common_app/view_models/payment_view_model.dart';
|
||||||
|
import 'package:mc_common_app/view_models/subscriptions_view_model.dart';
|
||||||
|
import 'package:mc_common_app/views/payments/payment_methods_view.dart';
|
||||||
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
||||||
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class UpgradePackageSheet extends StatefulWidget {
|
||||||
|
Subscription subscription;
|
||||||
|
|
||||||
|
UpgradePackageSheet(this.subscription, {super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<UpgradePackageSheet> createState() => _UpgradePackageSheetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UpgradePackageSheetState extends State<UpgradePackageSheet> {
|
||||||
|
bool isNowSelected = true;
|
||||||
|
String price = "0";
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
// TODO: implement initState
|
||||||
|
super.initState();
|
||||||
|
calculateUpgradePrice();
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateUpgradePrice() {
|
||||||
|
context.read<SubscriptionsVM>().calculationUpgradePrice(
|
||||||
|
AppState().getUser.data?.userInfo?.providerId.toString() ?? "",
|
||||||
|
widget.subscription.id.toString(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.only(left: 21, right: 21, bottom: 21, top: 4),
|
||||||
|
child: Consumer<SubscriptionsVM>(builder: (context, model, _) {
|
||||||
|
if (model.state == ViewState.busy) {
|
||||||
|
return SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: MediaQuery.of(context).size.height / 2,
|
||||||
|
child: const Center(child: CircularProgressIndicator()),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (isNowSelected) {
|
||||||
|
price = model.newPrice.toString();
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
"When do you want to upgrade".toText(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
12.height,
|
||||||
|
packageItem(
|
||||||
|
"Now",
|
||||||
|
("Your subscription will upgrade now. Affecting from ${DateHelper.formatAsLongDate(widget.subscription.dateEnd!)}"),
|
||||||
|
model.newPrice.toString(),
|
||||||
|
isNowSelected,
|
||||||
|
).onPress(() {
|
||||||
|
setState(() {
|
||||||
|
price = model.newPrice.toString();
|
||||||
|
isNowSelected = true;
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
6.height,
|
||||||
|
packageItem(
|
||||||
|
"Upgrade after current expiry",
|
||||||
|
("Your subscription will upgrade after you current subscription will end. Affecting from 27 January, 2024 ${DateHelper.formatAsLongDate(widget.subscription.dateEnd!)}"),
|
||||||
|
widget.subscription.price.toString(),
|
||||||
|
isNowSelected ? false : true,
|
||||||
|
).onPress(() {
|
||||||
|
price = widget.subscription.price.toString();
|
||||||
|
setState(() {
|
||||||
|
isNowSelected = false;
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
12.height,
|
||||||
|
ShowFillButton(
|
||||||
|
title: "Upgrade",
|
||||||
|
maxWidth: double.infinity,
|
||||||
|
onPressed: () async {
|
||||||
|
navigateTo(
|
||||||
|
context,
|
||||||
|
PaymentMethodsView(
|
||||||
|
paymentType: PaymentTypes.subscription,
|
||||||
|
onTempContinue: () async {
|
||||||
|
Utils.showLoading(context);
|
||||||
|
MResponse mResponse = await model.payForSubscription(
|
||||||
|
widget.subscription.id!,
|
||||||
|
isNowSelected,
|
||||||
|
false,
|
||||||
|
price);
|
||||||
|
Utils.hideLoading(context);
|
||||||
|
if (mResponse.messageStatus == 1) {
|
||||||
|
context
|
||||||
|
.read<PaymentVM>()
|
||||||
|
.updateOrderProviderSubscriptionId(
|
||||||
|
id: mResponse.data);
|
||||||
|
|
||||||
|
// Utils.showToast(
|
||||||
|
// "Subscriptions is successfully updated");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Utils.showToast(mResponse.message.toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget packageItem(
|
||||||
|
String title, String description, String price, bool isSelected) {
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.done,
|
||||||
|
size: 14,
|
||||||
|
color: Colors.white,
|
||||||
|
).toContainer(
|
||||||
|
isEnabledBorder: true,
|
||||||
|
backgroundColor:
|
||||||
|
isSelected ? MyColors.primaryColor : Colors.transparent,
|
||||||
|
borderColor: MyColors.primaryColor,
|
||||||
|
borderWidget: 1,
|
||||||
|
borderRadius: 0,
|
||||||
|
paddingAll: 2,
|
||||||
|
),
|
||||||
|
12.width,
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
title.toText(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
4.height,
|
||||||
|
if (widget.subscription.dateEnd != null)
|
||||||
|
description.toText(
|
||||||
|
fontSize: 12,
|
||||||
|
color: MyColors.lightTextColor,
|
||||||
|
),
|
||||||
|
10.height,
|
||||||
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
price.toText(fontSize: 24, isBold: true),
|
||||||
|
2.width,
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 2),
|
||||||
|
child: "SAR".toText(
|
||||||
|
fontSize: 16,
|
||||||
|
isBold: true,
|
||||||
|
color: MyColors.lightTextColor),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).toContainer(
|
||||||
|
isShadowEnabled: true,
|
||||||
|
paddingAll: 16,
|
||||||
|
borderRadius: 0,
|
||||||
|
borderColor: isSelected ? MyColors.primaryColor : Colors.transparent,
|
||||||
|
isEnabledBorder: true,
|
||||||
|
borderWidget: 2,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue