You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
346 lines
13 KiB
346 lines
13 KiB
7 months ago
|
import 'dart:convert';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:healthcare_user/common/settings.dart';
|
||
|
import 'package:healthcare_user/common/zoom_image.dart';
|
||
|
import 'package:healthcare_user/models/cart_items_model.dart';
|
||
|
import 'package:healthcare_user/models/get_all_offers_model.dart';
|
||
|
import 'package:healthcare_user/models/get_connected_doctors_model.dart';
|
||
|
import 'package:healthcare_user/models/get_offer_details_model.dart';
|
||
|
import 'package:healthcare_user/my_connections/add-doctor.dart';
|
||
|
import 'package:healthcare_user/orders/cart-items.dart';
|
||
|
|
||
|
import '../models/get_all_quotations.dart';
|
||
|
|
||
|
class CartItems extends StatefulWidget {
|
||
|
var myObject;
|
||
|
CartItems({this.myObject});
|
||
|
|
||
|
@override
|
||
|
State<CartItems> createState() => _CartItemsState();
|
||
|
}
|
||
|
|
||
|
class _CartItemsState extends State<CartItems>
|
||
|
with TickerProviderStateMixin {
|
||
|
late TabController _controller;
|
||
|
bool isDataLoading = false;
|
||
|
bool isOffersLoading = false;
|
||
|
bool isSereverIssue = false;
|
||
|
String bookingId='';
|
||
|
String totalCartPrice='';
|
||
|
String totalCartPriceAfterDiscount='';
|
||
|
|
||
|
final List<Tab> topTabs = <Tab>[
|
||
|
Tab(
|
||
|
child: Text(
|
||
|
'Pending',
|
||
|
style: TextStyle(fontSize: 14),
|
||
|
)),
|
||
|
Tab(
|
||
|
child: Text(
|
||
|
'Completed',
|
||
|
style: TextStyle(fontSize: 14),
|
||
|
)),
|
||
|
];
|
||
|
List<CartItemsModel> cartItemsList = [];
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
_controller = TabController(vsync: this, length: topTabs.length);
|
||
|
getAllCartItems();
|
||
|
super.initState();
|
||
|
}
|
||
|
|
||
|
Future<void> getAllCartItems() async {
|
||
|
isDataLoading = true;
|
||
|
try {
|
||
|
var payload = new Map<String, dynamic>();
|
||
|
payload["pharmacyId"] = widget.myObject.pharmacyId;
|
||
|
payload["customerId"] =AppSettings.customerId;
|
||
|
var response = await AppSettings.getAllCartItems(widget.myObject.bookingId,payload);
|
||
|
|
||
|
setState(() {
|
||
|
cartItemsList =
|
||
|
((jsonDecode(response)['data'][0]['items']) as List).map((dynamic model) {
|
||
|
return CartItemsModel.fromJson(model);
|
||
|
}).toList();
|
||
|
cartItemsList = cartItemsList.reversed.toList();
|
||
|
bookingId=jsonDecode(response)['data'][0]['bookingId'];
|
||
|
totalCartPrice=jsonDecode(response)['data'][0]['totalCartPrice'].toString();
|
||
|
totalCartPriceAfterDiscount=jsonDecode(response)['data'][0]['totalCartPriceAfterDiscount'].toString();
|
||
|
isDataLoading = false;
|
||
|
});
|
||
|
} catch (e) {
|
||
|
setState(() {
|
||
|
isDataLoading = false;
|
||
|
isSereverIssue = true;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Widget _cartItems() {
|
||
|
if (cartItemsList.length != 0) {
|
||
|
return Column(
|
||
|
children: [
|
||
|
Expanded(child: ListView.builder(
|
||
|
padding: EdgeInsets.all(0),
|
||
|
itemCount: cartItemsList.length,
|
||
|
itemBuilder: (BuildContext context, int index) {
|
||
|
return GestureDetector(
|
||
|
onTap: () async{
|
||
|
|
||
|
},
|
||
|
child: Card(
|
||
|
//color: prescriptionsList[index].cardColor,
|
||
|
child: Padding(
|
||
|
padding: EdgeInsets.all(10),
|
||
|
child: Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||
|
children: [
|
||
|
Row(
|
||
|
children: [
|
||
|
Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text(
|
||
|
'Medicine Name',
|
||
|
style: labelTextStyle(),
|
||
|
),
|
||
|
SizedBox(
|
||
|
height:
|
||
|
MediaQuery.of(context).size.height * .01,
|
||
|
),
|
||
|
Text(
|
||
|
'Quantity',
|
||
|
style: labelTextStyle(),
|
||
|
),
|
||
|
SizedBox(
|
||
|
height:
|
||
|
MediaQuery.of(context).size.height * .01,
|
||
|
),
|
||
|
Text(
|
||
|
'Price',
|
||
|
style: labelTextStyle(),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: MediaQuery.of(context).size.width * .01,
|
||
|
),
|
||
|
Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text(
|
||
|
':',
|
||
|
style: labelTextStyle(),
|
||
|
),
|
||
|
SizedBox(
|
||
|
height:
|
||
|
MediaQuery.of(context).size.height * .01,
|
||
|
),
|
||
|
Text(
|
||
|
':',
|
||
|
style: labelTextStyle(),
|
||
|
),
|
||
|
SizedBox(
|
||
|
height:
|
||
|
MediaQuery.of(context).size.height * .01,
|
||
|
),
|
||
|
Text(
|
||
|
':',
|
||
|
style: labelTextStyle(),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: MediaQuery.of(context).size.width * .01,
|
||
|
),
|
||
|
Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text(
|
||
|
cartItemsList[index]
|
||
|
.medicine_name
|
||
|
.toString()
|
||
|
.toUpperCase(),
|
||
|
style: valuesTextStyle()),
|
||
|
SizedBox(
|
||
|
height:
|
||
|
MediaQuery.of(context).size.height * .01,
|
||
|
),
|
||
|
Text(
|
||
|
cartItemsList[index].quantity,
|
||
|
style: valuesTextStyle(),
|
||
|
),
|
||
|
SizedBox(
|
||
|
height:
|
||
|
MediaQuery.of(context).size.height * .01,
|
||
|
),
|
||
|
Text(
|
||
|
cartItemsList[index]
|
||
|
.price
|
||
|
,
|
||
|
style: valuesTextStyle(),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
)),
|
||
|
),
|
||
|
);
|
||
|
})),
|
||
|
Container(
|
||
|
width:double.infinity,
|
||
|
height: MediaQuery.of(context).size.height * .06,
|
||
|
child: ElevatedButton(
|
||
|
style: ElevatedButton.styleFrom(
|
||
|
primary: buttonColors, // background
|
||
|
onPrimary: Colors.black, // foreground
|
||
|
),
|
||
|
onPressed: () async {
|
||
|
|
||
|
},
|
||
|
child: Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text('Total cart price: $totalCartPrice'),
|
||
|
Text('Total cart price after discount: $totalCartPriceAfterDiscount'),
|
||
|
],
|
||
|
),
|
||
|
)),
|
||
|
SizedBox(height:MediaQuery.of(context).size.height * .02,),
|
||
|
Container(
|
||
|
width:double.infinity,
|
||
|
height: MediaQuery.of(context).size.height * .06,
|
||
|
child: ElevatedButton(
|
||
|
style: ElevatedButton.styleFrom(
|
||
|
primary: buttonColors, // background
|
||
|
onPrimary: Colors.black, // foreground
|
||
|
),
|
||
|
onPressed: () async {
|
||
|
AppSettings.preLoaderDialog(context);
|
||
|
bool isOnline = await AppSettings.internetConnectivity();
|
||
|
if(isOnline){
|
||
|
var payload = new Map<String, dynamic>();
|
||
|
|
||
|
payload["user"] = {"profile": {"firstName": AppSettings.userName.toString(),
|
||
|
"lastName": '',
|
||
|
"contactNumber": AppSettings.phoneNumber.toString(),
|
||
|
"address1": AppSettings.userAddress.toString(),
|
||
|
"address2": AppSettings.detailedAddress.toString(),
|
||
|
"country": ''
|
||
|
},};
|
||
|
payload["pharmacies"] = [
|
||
|
{
|
||
|
"pharmacyId": widget.myObject.pharmacyId.toString(),
|
||
|
"pharmacyname": widget.myObject.pharmacyName.toString(),
|
||
|
"phone":widget.myObject.pharmacyContactNumber.toString(),
|
||
|
"profile": "?"
|
||
|
}
|
||
|
];
|
||
|
payload["prescriptionPicture"] =
|
||
|
{
|
||
|
"pictureUrl": [
|
||
|
"string"
|
||
|
]
|
||
|
};
|
||
|
payload["amount"] =
|
||
|
{
|
||
|
"biddingAmount": totalCartPriceAfterDiscount!='null'?int.parse(totalCartPriceAfterDiscount):0,
|
||
|
"totalAmount": totalCartPrice!='null'?int.parse(totalCartPrice):0,
|
||
|
"discountAmount":0,
|
||
|
};
|
||
|
|
||
|
bool orderStatus = await AppSettings.orderNow(payload,widget.myObject.bookingId);
|
||
|
|
||
|
try {
|
||
|
if(orderStatus){
|
||
|
Navigator.of(context, rootNavigator: true).pop();
|
||
|
AppSettings.longSuccessToast("order placed successfully");
|
||
|
|
||
|
|
||
|
}
|
||
|
else{
|
||
|
Navigator.of(context, rootNavigator: true).pop();
|
||
|
AppSettings.longFailedToast("failed to order");
|
||
|
}
|
||
|
} catch (exception) {
|
||
|
print(exception);
|
||
|
Navigator.of(context, rootNavigator: true).pop();
|
||
|
AppSettings.longFailedToast("failed to order");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else{
|
||
|
Navigator.of(context,rootNavigator: true).pop();
|
||
|
AppSettings.longFailedToast(
|
||
|
"Please check your internet");
|
||
|
}
|
||
|
},
|
||
|
child: Text('Order now'),
|
||
|
)),
|
||
|
],
|
||
|
);
|
||
|
} else {
|
||
|
return Center(
|
||
|
child: Padding(
|
||
|
padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
children: [
|
||
|
SizedBox(
|
||
|
height: MediaQuery.of(context).size.height * .25,
|
||
|
),
|
||
|
Text('No Cart items found'),
|
||
|
SizedBox(
|
||
|
height: 20,
|
||
|
),
|
||
|
CircleAvatar(
|
||
|
backgroundColor: primaryColor,
|
||
|
radius: 40,
|
||
|
child: IconButton(
|
||
|
iconSize: 40,
|
||
|
icon: const Icon(
|
||
|
Icons.info,
|
||
|
color: Colors.white,
|
||
|
),
|
||
|
onPressed: () async {},
|
||
|
),
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
title: Text('Cart Items'),
|
||
|
backgroundColor: primaryColor,
|
||
|
),
|
||
|
body: Container(
|
||
|
child: Padding(
|
||
|
padding: EdgeInsets.all(10),
|
||
|
child: isDataLoading
|
||
|
? Center(
|
||
|
child: CircularProgressIndicator(
|
||
|
color: primaryColor,
|
||
|
strokeWidth: 5.0,
|
||
|
),
|
||
|
)
|
||
|
: _cartItems(),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|