Merge branch 'mirza_dev' of http://34.17.52.79/Haroon6138/car_provider_app into faiz_dev
# Conflicts: # lib/views/dashboard/fragments/ads_fragment.dart # pubspec.lockaamir_dev
commit
0599bed068
@ -1,27 +0,0 @@
|
|||||||
|
|
||||||
import 'package:mc_common_app/api/api_client.dart';
|
|
||||||
import 'package:mc_common_app/classes/app_state.dart';
|
|
||||||
import 'package:mc_common_app/classes/consts.dart';
|
|
||||||
import 'package:mc_common_app/config/dependencies.dart';
|
|
||||||
import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart';
|
|
||||||
import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart';
|
|
||||||
|
|
||||||
|
|
||||||
abstract class SubscriptionRepo {
|
|
||||||
Future<SubscriptionModel> getAllSubscriptions(String? serviceProviderID);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SubscriptionRepoImp extends SubscriptionRepo {
|
|
||||||
@override
|
|
||||||
Future<SubscriptionModel> getAllSubscriptions(String? serviceProviderID) async {
|
|
||||||
String t = AppState().getUser.data!.accessToken ?? "";
|
|
||||||
Map<String, String> queryParameters = {};
|
|
||||||
if (serviceProviderID != null) {
|
|
||||||
queryParameters = {
|
|
||||||
"ID": serviceProviderID,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return await injector.get<ApiClient>().getJsonForObject((json) => SubscriptionModel.fromJson(json), ApiConsts.getAllSubscriptions, token: t, queryParameters: queryParameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
|
|
||||||
import 'package:car_provider_app/repositories/subscription_repo.dart';
|
|
||||||
import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart';
|
|
||||||
import 'package:mc_common_app/utils/enums.dart';
|
|
||||||
import 'package:mc_common_app/view_models/base_view_model.dart';
|
|
||||||
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
||||||
|
|
||||||
class SubscriptionsVM extends BaseVM {
|
|
||||||
final SubscriptionRepo subscriptionRepo;
|
|
||||||
|
|
||||||
SubscriptionsVM({required this.subscriptionRepo});
|
|
||||||
|
|
||||||
//All Subscriptions
|
|
||||||
int selectedIndex = 0;
|
|
||||||
late DropValue selectedMothlyTab;
|
|
||||||
List<DropValue> monthlyTabs = [];
|
|
||||||
late SubscriptionModel allSubscriptions;
|
|
||||||
List<Subscription> tempSubscriptions = [];
|
|
||||||
|
|
||||||
//My Subscriptions
|
|
||||||
|
|
||||||
//All Subscriptions
|
|
||||||
getAllAvailableSubscriptions(String? serviceProviderID) async {
|
|
||||||
selectedIndex = 0;
|
|
||||||
setState(ViewState.busy);
|
|
||||||
allSubscriptions = await subscriptionRepo.getAllSubscriptions(serviceProviderID);
|
|
||||||
if (allSubscriptions.messageStatus == 1) {
|
|
||||||
monthlyTabs.clear();
|
|
||||||
var idSet = <int>{};
|
|
||||||
for (var d in allSubscriptions.data ?? []) {
|
|
||||||
if (idSet.add(d.durationDays ?? 0)) {
|
|
||||||
monthlyTabs.add(DropValue(d.durationDays, _convertDaysToMonths(d.durationDays ?? 0), ""));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
monthlyTabs.sort((a, b) => a.value.compareTo(b.value));
|
|
||||||
selectedMothlyTab = monthlyTabs.first;
|
|
||||||
filterSubscriptions();
|
|
||||||
setState(ViewState.idle);
|
|
||||||
} else {
|
|
||||||
setState(ViewState.error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String _convertDaysToMonths(int days) {
|
|
||||||
final int months = days ~/ 30;
|
|
||||||
final int remainingDays = days % 30;
|
|
||||||
|
|
||||||
String _result = months > 0 ? '$months Month${months > 1 ? 's' : ''}${remainingDays > 0 ? ' & ' : ''}' : '';
|
|
||||||
_result += remainingDays > 0 ? '$remainingDays Day${remainingDays > 1 ? 's' : ''}' : '';
|
|
||||||
return _result;
|
|
||||||
}
|
|
||||||
|
|
||||||
filterSubscriptions() {
|
|
||||||
tempSubscriptions.clear();
|
|
||||||
for (var element in allSubscriptions.data!) {
|
|
||||||
if (selectedMothlyTab.id == element.durationDays) {
|
|
||||||
tempSubscriptions.add(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//My Subscriptions
|
|
||||||
getMySubscriptions(String? serviceProviderID) async {
|
|
||||||
selectedIndex = 0;
|
|
||||||
setState(ViewState.busy);
|
|
||||||
allSubscriptions = await subscriptionRepo.getAllSubscriptions(serviceProviderID);
|
|
||||||
if (allSubscriptions.messageStatus == 1) {
|
|
||||||
// allSubscriptions.data!.sort((a, b) => a.value.compareTo(b.value));
|
|
||||||
setState(ViewState.idle);
|
|
||||||
} else {
|
|
||||||
setState(ViewState.error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
||||||
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
||||||
|
import 'package:mc_common_app/theme/colors.dart';
|
||||||
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
||||||
|
|
||||||
|
class DegradePackageSheet extends StatelessWidget {
|
||||||
|
const DegradePackageSheet({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
"Deactivate the branches & users".toText(
|
||||||
|
fontSize: 18,
|
||||||
|
isBold: true,
|
||||||
|
),
|
||||||
|
"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.lightTextColor,
|
||||||
|
),
|
||||||
|
12.height,
|
||||||
|
showBranchList(),
|
||||||
|
12.height,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget showBranchList() {
|
||||||
|
return ListView.separated(
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
customCheckBox(true),
|
||||||
|
12.width,
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
"Olaya Branch".toText(
|
||||||
|
fontSize: 16,
|
||||||
|
isBold: true,
|
||||||
|
),
|
||||||
|
"3 Users".toText(
|
||||||
|
fontSize: 10,
|
||||||
|
color: MyColors.lightTextColor,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.keyboard_arrow_down,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
showUser("Mirza"),
|
||||||
|
12.height,
|
||||||
|
showUser("Shafique"),
|
||||||
|
],
|
||||||
|
).toContainer(
|
||||||
|
isShadowEnabled: true,
|
||||||
|
borderRadius: 0,
|
||||||
|
paddingAll: 12,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
separatorBuilder: (context, index) {
|
||||||
|
return 12.height;
|
||||||
|
},
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount: 2,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget showUser(String user) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
width: 24,
|
||||||
|
),
|
||||||
|
customCheckBox(false),
|
||||||
|
12.width,
|
||||||
|
user.toText(fontSize: 14),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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,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,89 @@
|
|||||||
|
import 'package:car_provider_app/views/subscriptions/sheet/degrage_package_sheet.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
||||||
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
||||||
|
import 'package:mc_common_app/theme/colors.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/extensions/extensions_widget.dart';
|
||||||
|
|
||||||
|
class SelectPackageSheet extends StatelessWidget {
|
||||||
|
const SelectPackageSheet({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
"When do you want to upgrade".toText(
|
||||||
|
fontSize: 19,
|
||||||
|
isBold: true,
|
||||||
|
),
|
||||||
|
12.height,
|
||||||
|
showPackage(),
|
||||||
|
12.height,
|
||||||
|
showPackage(),
|
||||||
|
12.height,
|
||||||
|
ShowFillButton(
|
||||||
|
title: "Upgrade",
|
||||||
|
maxWidth: double.infinity,
|
||||||
|
onPressed: () {
|
||||||
|
showMyBottomSheet(context, child: const DegradePackageSheet());
|
||||||
|
},
|
||||||
|
),
|
||||||
|
12.height,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget showPackage() {
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Checkbox(
|
||||||
|
value: false,
|
||||||
|
onChanged: (v) {},
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
"Now".toText(
|
||||||
|
fontSize: 16,
|
||||||
|
isBold: true,
|
||||||
|
),
|
||||||
|
"Your subscription will upgrade now. Affecting from 23 January, 2024"
|
||||||
|
.toText(
|
||||||
|
fontSize: 12,
|
||||||
|
color: MyColors.lightTextColor,
|
||||||
|
),
|
||||||
|
12.height,
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
"175".toText(
|
||||||
|
fontSize: 26,
|
||||||
|
isBold: true,
|
||||||
|
),
|
||||||
|
2.width,
|
||||||
|
"SAR".toText(
|
||||||
|
color: MyColors.lightTextColor,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
).toContainer(isShadowEnabled: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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