pd-android-app/lib/screens/order/order_confermation_screen.dart

246 lines
10 KiB
Dart

import 'package:cheminova/controller/get_order_placed_controller.dart';
import 'package:cheminova/models/product_model.dart';
import 'package:cheminova/utils/show_snackbar.dart';
import 'package:cheminova/widgets/my_drawer.dart';
import 'package:cheminova/widgets/product_card.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import '../../controller/cart_controller.dart';
import '../../controller/place_order_controller.dart';
import '../../models/oder_place_model.dart';
import '../../models/product_model1.dart';
class OrderConfermationScreen extends StatefulWidget {
Product? productModel; // The selected product model
PlacedOrderModel? placedOrder; // The order details after placement
List<Product>? selectedProducts; // List of selected products for the order
// Constructor to initialize the class with optional parameters
OrderConfermationScreen({super.key,this.productModel,this.placedOrder,this.selectedProducts});
@override
State<OrderConfermationScreen> createState() =>
_OrderConfermationScreenState();
}
class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
final CartController _cartController = Get.put(CartController()); // Instance of CartController
// Instance of OrderPlacedController
final OrderPlacedController _placedController = Get.put(OrderPlacedController());
// Instance of GetPlacedOrderController
final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController());
@override
Widget build(BuildContext context) {
final orderItems = _placedController.placedOrder1; // Fetching the placed order details
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: Builder(
builder: (context) {
return GestureDetector(
onTap: () => Scaffold.of(context).openDrawer(), // Open the drawer on tap
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SvgPicture.asset(
'assets/svg/menu.svg',
),
),
);
},
),
actions: [
GestureDetector(
onTap: () => Get.back(), // Go back on tap
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SvgPicture.asset(
'assets/svg/back_arrow.svg',
),
),
),
],
title: const Text(
"Order Confirmation",
),
),
drawer: MyDrawer(),
body: Stack(
fit: StackFit.expand,
children: [
Image.asset(
'assets/images/image_1.png',
fit: BoxFit.cover,
),
SafeArea(
child: Column(
children: [
SizedBox(
height: Get.height * 0.02, // Spacing from the top
),
Card(
margin: const EdgeInsets.symmetric(horizontal: 18),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(19),
side: const BorderSide(color: Color(0xFFFDFDFD)),
),
color: const Color(0xFFB4D1E5).withOpacity(0.9),
child: Padding(
padding: EdgeInsets.all(Get.width * 0.04),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Card(
child: SizedBox(
width: Get.width,
height: Get.height * 0.05,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Order Number:1234",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w400,
),
),
),
),
),
Padding(
padding: EdgeInsets.all(Get.width * 0.02),
child: Text(
'Order Summary',
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: Get.height * 0.22,
child: Padding(
padding: EdgeInsets.all(Get.width * 0.02),
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: _cartController.selectedProducts.length,
itemBuilder: (context, index) =>
ProductCard(
productModel:_cartController.selectedProducts[index],
isCheckout: true,
),
),
),
),
Padding(
padding: EdgeInsets.all(Get.width * 0.02),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Subtotal',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.subtotal.value.toStringAsFixed(2)}'),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('GST',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.gstTotal.value.toStringAsFixed(2)}'),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Total Amount',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.grandTotal.value.toStringAsFixed(2)}'),
],
),
],
),
),
],
),
),
Padding(
padding: EdgeInsets.all(Get.width * 0.02),
child: Text(
'Shipping Information',
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
),
Card(
child: SizedBox(
width: Get.width,
height: Get.height * 0.1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: TextEditingController(
text: widget.placedOrder!.shipTo, // Pre-filling the address
),
decoration: InputDecoration(
hintText: "Address : ${widget.placedOrder!.shipTo}",
hintStyle: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w400,
),
border: OutlineInputBorder(),
),
),
),
]),
),
),
Card(
child: SizedBox(
width: Get.width,
height: Get.height * 0.05,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Estimated Delivery Date: ${widget.placedOrder!.orderItems[0].createdAt}",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w400,
),
),
),
),
),
],
),
),
),
],
),
),
],
),
);
}
}