pd-android-app/lib/screens/kyc/kyc_retailer_info_screen.dart

628 lines
31 KiB
Dart

import 'package:cheminova/controller/kyc_controller.dart';
import 'package:cheminova/models/kyc_model.dart';
import 'package:cheminova/widgets/input_field.dart';
import 'package:cheminova/widgets/my_drawer.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 'package:intl/intl.dart';
import '../../controller/cart_controller.dart';
import 'kyc_retailer_details_screen.dart';
class KycRetailerInfoScreen extends StatefulWidget {
KycModel? kycModel;
KycRetailerInfoScreen({super.key, this.kycModel});
@override
State<KycRetailerInfoScreen> createState() => _KycRetailerInfoScreenState();
}
class _KycRetailerInfoScreenState extends State<KycRetailerInfoScreen> {
final _searchController = TextEditingController();
final List<String> _filterList = ["Order Status", "Date Range"];
final KycController _kycController = Get.put(KycController());
final CartController _cartController = Get.put(CartController());
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
String selectedStatus = "All"; // Default selected status
@override
void initState() {
super.initState();
getKycData();
}
Future<void> _onRefresh() async {
await getKycData();
await Future.delayed(Duration(seconds: 1));
}
Future<void> getKycData() async {
await _kycController.fetchKycData();
print("kyc successfully");
}
String capitalizeFirstLetter(String text) {
if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1).toLowerCase();
}
String formatDate(String apiDate) {
DateTime parsedDate = DateTime.parse(apiDate);
String formattedDate = DateFormat('dd-MMM-yyyy').format(parsedDate);
return formattedDate;
}
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.transparent,
elevation: 0,
leading: Builder(
builder: (context) {
return GestureDetector(
onTap: () => Scaffold.of(context).openDrawer(),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: SvgPicture.asset('assets/svg/menu.svg'),
),
);
},
),
actions: [
GestureDetector(
onTap: () => Get.back(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SvgPicture.asset('assets/svg/back_arrow.svg'),
),
),
],
title: const Text("Kyc Management"),
),
drawer: MyDrawer(),
body: Stack(
fit: StackFit.expand,
children: [
Image.asset('assets/images/image_1.png', fit: BoxFit.cover),
SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: _onRefresh,
color: Colors.black,
backgroundColor: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
InputField(
hintText: "Search Order",
labelText: "Search Order",
controller: _searchController,
),
SizedBox(height: Get.height * 0.035),
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: const EdgeInsets.all(12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: Get.height * 0.05,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text(
"Kyc Status: ",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(width: 10), // Space between label and dropdown
Expanded(
child: DropdownButtonFormField<String>(
value: selectedStatus,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white, // White background
contentPadding: EdgeInsets.symmetric(
vertical: 10, horizontal: 12),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey,
width: 1,
),
),
),
items: [
"All",
"new",
"approved",
"reject"
].map((String status) {
return DropdownMenuItem<String>(
value: status,
child: Text(capitalizeFirstLetter(status)),
);
}).toList(),
onChanged: (newValue) {
setState(() {
selectedStatus = newValue!;
});
},
),
),
],
),
),
SizedBox(
height: Get.height * 0.6,
child: Obx(() {
// Filter the list based on the selected status
List<KycModel> filteredOrders =
selectedStatus == "All"
? _kycController.kycList
: _kycController.kycList
.where((order) =>
order.status ==
selectedStatus)
.toList();
return ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: filteredOrders.length,
itemBuilder: (context, index) {
final order = filteredOrders[index];
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 8),
child: Card(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Padding(
padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Text(
"Order ID: ",
style: GoogleFonts
.roboto(
fontSize: 14,
fontWeight:
FontWeight
.bold)),
Text("${order.id}")
],
),
),
Padding(
padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 0),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
"Product Names: ",
style:
GoogleFonts.roboto(
fontSize: 14,
fontWeight:
FontWeight.bold,
),
),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
Text(
'${capitalizeFirstLetter(order!.tradeName.toString())}',
textAlign:
TextAlign.left,
style: GoogleFonts
.roboto(
fontSize: 14,
),
),
],
),
),
],
),
),
Padding(
padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Text(
"Order Date: ",
style: GoogleFonts
.roboto(
fontSize: 14,
fontWeight:
FontWeight
.bold)),
Text(formatDate(
"${order.createdAt}"))
],
),
),
Padding(
padding:
const EdgeInsets.fromLTRB(
16, 8, 8, 8),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Text("Status: ",
style: GoogleFonts
.roboto(
fontSize: 14,
fontWeight:
FontWeight
.bold)),
Text(capitalizeFirstLetter(
"${order.status}"))
],
),
),
SizedBox(
width: Get.width * 0.4,
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () => Get.to(() =>
KycRetailerDetailScreen(
kycModel:
_kycController
.kycList[
index])),
style:
ElevatedButton.styleFrom(
foregroundColor:
Colors.white,
backgroundColor:
const Color(
0xFF004791),
shape:
RoundedRectangleBorder(
borderRadius:
BorderRadius
.circular(
10)),
),
child: Text("View Details"),
),
),
),
],
),
),
);
},
);
}),
),
],
),
),
),
],
),
),
),
),
),
],
),
);
}
}
// import 'package:cheminova/controller/kyc_controller.dart';
// import 'package:cheminova/models/kyc_model.dart';
// import 'package:cheminova/widgets/input_field.dart';
// import 'package:cheminova/widgets/my_drawer.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 'package:intl/intl.dart';
// import '../../controller/cart_controller.dart';
// import 'kyc_retailer_details_screen.dart';
//
//
// class KycRetailerInfoScreen extends StatefulWidget {
//
// KycModel? kycModel;
// KycRetailerInfoScreen({super.key, this.kycModel});
//
// @override
// State<KycRetailerInfoScreen> createState() => _KycRetailerInfoScreenState();
// }
//
// class _KycRetailerInfoScreenState extends State<KycRetailerInfoScreen> {
// final _searchController = TextEditingController();
// final List<String> _filterList = ["Order Status", "Date Range"];
//
// final KycController _kycController = Get.put(KycController());
// final CartController _cartController = Get.put(CartController());
// final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
// GlobalKey<RefreshIndicatorState>();
//
// @override
// void initState() {
// super.initState();
// getKycData();
// }
//
// Future<void> _onRefresh() async {
// await getKycData();
// await Future.delayed(Duration(seconds: 1));
// }
//
// Future<void> getKycData() async {
// await _kycController.fetchKycData();
// print("kyc successfully");
// }
//
// String capitalizeFirstLetter(String text) {
// if (text.isEmpty) return text;
// return text[0].toUpperCase() + text.substring(1).toLowerCase();
// }
//
// String formatDate(String apiDate) {
// DateTime parsedDate = DateTime.parse(apiDate);
// String formattedDate = DateFormat('dd-MMM-yyyy').format(parsedDate);
// return formattedDate;
// }
//
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// extendBodyBehindAppBar: true,
// appBar: AppBar(
// centerTitle: true,
// backgroundColor: Colors.transparent,
// elevation: 0,
// leading: Builder(
// builder: (context) {
// return GestureDetector(
// onTap: () => Scaffold.of(context).openDrawer(),
// child: Padding(
// padding: const EdgeInsets.all(16.0),
// child: SvgPicture.asset('assets/svg/menu.svg'),
// ),
// );
// },
// ),
// actions: [
// GestureDetector(
// onTap: () => Get.back(),
// child: Padding(
// padding: const EdgeInsets.all(8.0),
// child: SvgPicture.asset('assets/svg/back_arrow.svg'),
// ),
// ),
// ],
// title: const Text("Kyc Management"),
// ),
// drawer: MyDrawer(),
// body: Stack(
// fit: StackFit.expand,
// children: [
// Image.asset('assets/images/image_1.png', fit: BoxFit.cover),
// SafeArea(
// child: SingleChildScrollView(
// child: Padding(
// padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
// child: RefreshIndicator(
// key: _refreshIndicatorKey,
// onRefresh: _onRefresh,
// color: Colors.black,
// backgroundColor: Colors.white,
// child: Column(
// mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// InputField(
// hintText: "Search Order",
// labelText: "Search Order",
// controller: _searchController,
// ),
// SizedBox(height: Get.height * 0.035),
// 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: const EdgeInsets.all(12.0),
// child: Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// SizedBox(
// height: Get.height * 0.05,
// child: ListView.builder(
// shrinkWrap: true,
// scrollDirection: Axis.horizontal,
// itemCount: _filterList.length,
// itemBuilder: (context, index) => Padding(
// padding: const EdgeInsets.symmetric(horizontal: 4),
// child: Chip(
// label: Text(
// _filterList[index],
// style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w500),
// ),
// ),
// ),
// ),
// ),
// SizedBox(
// height: Get.height * 0.6,
// child: Obx(() {
// // // Use a set to keep track of unique order IDs
// // final Set<String> uniqueOrderIds = {};
// // final List<PlacedOrderList> uniqueOrders = [];
// //
// // for (var order in _kycController.kycList) {
// // if (uniqueOrderIds.add(order.id)) {
// // uniqueOrders.add(order);
// // }
// // }
//
// return ListView.builder(
// padding: EdgeInsets.zero,
// shrinkWrap: true,
// itemCount: _kycController.kycList.length,
// itemBuilder: (context, index) {
// final order = _kycController.kycList[index];
// return Padding(
// padding: const EdgeInsets.symmetric(vertical: 8),
// child: Card(
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Padding(
// padding: const EdgeInsets.fromLTRB(16, 8, 8, 0),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)),
// Text("${order.id}")
// ],
// ),
// ),
// Padding(
// padding: const EdgeInsets.fromLTRB(16, 8, 8, 0),
// child: Row(
// crossAxisAlignment: CrossAxisAlignment.start, // Aligns the Column to the top of the Text
// children: [
// Text(
// "Product Names: ",
// style: GoogleFonts.roboto(
// fontSize: 14,
// fontWeight: FontWeight.bold,
// ),
// ),
// Expanded(
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start, // Aligns text to the right within the Column
// children: [
//
// Text(
// '${capitalizeFirstLetter(order!.tradeName.toString())}', // Adds index and trims whitespace
// textAlign: TextAlign.left, // Aligns text to the right
// style: GoogleFonts.roboto(
// fontSize: 14,
// ),
// ),
// ],
// ),
// ),
// ],
// ),
// ),
//
//
// Padding(
// padding: const EdgeInsets.fromLTRB(16, 8, 8, 0),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// Text("Order Date: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)),
// Text(formatDate("${order.createdAt}"))
// ],
// ),
// ),
// Padding(
// padding: const EdgeInsets.fromLTRB(16, 8, 8, 8),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// Text("Status: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)),
// Text(capitalizeFirstLetter("${order.status}"))
// ],
// ),
// ),
// SizedBox(
// width: Get.width * 0.4,
// child: Padding(
// padding: const EdgeInsets.all(8.0),
// child: ElevatedButton(
// onPressed: ()=>
// Get.to(() => KycRetailerDetailScreen(
// kycModel: _kycController.kycList[index])),
// style: ElevatedButton.styleFrom(
// foregroundColor: Colors.white,
// backgroundColor: const Color(0xFF004791),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(10)),
// ),
// child: Text("View Details", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)),
// ),
// ),
// )
// ],
// ),
// ),
// );
// },
// );
// }),
// )
// ],
// ),
// ),
// ),
// ],
// ),
// ),
// ),
// ),
// ),
// ],
// ),
// );
// }
// }
//