last 16-10-2025

This commit is contained in:
mageshwaran committed 2025-10-16 11:21:52 +05:30
commit 7546b7348c
269 files changed
+36404

No files matched your search

@@ -0,0 +1,350 @@
// ignore: file_names
import 'dart:ui';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:bookmywages/view/user_main_screens/main_contoller.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
class CategoryPage extends ConsumerStatefulWidget {
const CategoryPage({super.key});
@override
ConsumerState<CategoryPage> createState() => _CategoryPageState();
}
class _CategoryPageState extends ConsumerState<CategoryPage> {
final ScrollController _scrollController = ScrollController();
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
void _handleBackNavigation() {
// Use post-frame callback to avoid accessing scaffold geometry during build
WidgetsBinding.instance.addPostFrameCallback((_) {
try {
final indexController = InheritedIndexController.of(context);
indexController?.changeIndex(0);
} catch (e) {
// Handle any potential errors gracefully
debugPrint('Error resetting index: $e');
}
});
}
@override
Widget build(BuildContext context) {
final categoryAsyncValue = ref.watch(categoryListProvider);
return PopScope(
canPop: true,
onPopInvoked: (didPop) {
if (didPop) {
_handleBackNavigation();
}
},
child: Scaffold(
backgroundColor: AppColors.secondprimary,
body: categoryAsyncValue.when(
data: (categories) => _buildSuccessUI(categories),
loading: () => _buildLoadingUI(),
error: (error, _) => _buildErrorUI(error),
),
),
);
}
Widget _buildSuccessUI(List categories) {
return CustomScrollView(
controller: _scrollController,
physics: const BouncingScrollPhysics(),
slivers: [
// Custom App Bar
SliverToBoxAdapter(child: _buildAppBar()),
// Optimized Grid
SliverPadding(
padding: const EdgeInsets.all(16),
sliver: SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 196 / 209,
),
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index >= categories.length) return null;
return _buildCategoryCard(categories[index]);
},
childCount: categories.length,
addAutomaticKeepAlives: false,
addRepaintBoundaries: true,
),
),
),
// Bottom padding
const SliverToBoxAdapter(child: SizedBox(height: 20)),
],
);
}
Widget _buildAppBar() {
return Container(
height: 90,
padding: const EdgeInsets.only(top: 50),
child: Stack(
alignment: Alignment.center,
children: [
const Center(
child: Text(
"Category",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
),
],
),
);
}
Widget _buildCategoryCard(dynamic category) {
return RepaintBoundary(
child: GestureDetector(
onTap: () {
// 🎯 UPDATED: Pass source tab as 2 (Categories tab index)
Get.toNamed(
RouterConts.listservice,
arguments: {
'id': category.id,
'subcategoryId': null,
'service': '0',
'sourceTab': 2, // 🎯 Categories tab is index 2
},
);
},
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Stack(
fit: StackFit.expand,
children: [
_buildCategoryImage(category.imageUrl),
_buildImageOverlay(category.name),
],
),
),
),
),
);
}
Widget _buildCategoryImage(String imageUrl) {
return Image.network(
imageUrl,
fit: BoxFit.cover,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Container(
color: Colors.grey[300],
child: Center(
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
),
),
);
},
errorBuilder: (context, error, stackTrace) => Container(
color: Colors.grey[300],
child: const Center(
child: Icon(Icons.image_not_supported, color: Colors.grey, size: 32),
),
),
cacheWidth: 400,
cacheHeight: 400,
);
}
Widget _buildImageOverlay(String categoryName) {
return Positioned(
bottom: 0,
left: 0,
right: 0,
child: ClipRRect(
borderRadius: const BorderRadius.vertical(bottom: Radius.circular(12)),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
height: 56,
width: 196,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(255, 255, 255, 0.54),
Color.fromRGBO(153, 153, 153, 0.54),
],
),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
child: Center(
child: Text(
categoryName,
style: const TextStyle(
color: Colors.black87,
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14,
height: 1.2,
letterSpacing: 0.5,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
),
),
),
),
);
}
Widget _buildLoadingUI() {
return CustomScrollView(
physics: const NeverScrollableScrollPhysics(),
slivers: [
SliverToBoxAdapter(child: _buildAppBar()),
SliverPadding(
padding: const EdgeInsets.all(16),
sliver: SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 196 / 209,
),
delegate: SliverChildBuilderDelegate(
(context, index) => _buildShimmerCard(),
childCount: 6,
),
),
),
],
);
}
Widget _buildShimmerCard() {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.grey[300],
),
child: Stack(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
gradient: LinearGradient(
colors: [
Colors.grey[300]!,
Colors.grey[100]!,
Colors.grey[300]!,
],
),
),
),
Positioned(
bottom: 12,
left: 12,
right: 12,
child: Container(
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color: Colors.grey[400],
),
),
),
],
),
);
}
Widget _buildErrorUI(Object error) {
return CustomScrollView(
slivers: [
SliverToBoxAdapter(child: _buildAppBar()),
SliverFillRemaining(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error_outline, size: 64, color: Colors.grey[400]),
const SizedBox(height: 16),
Text(
'Oops! Something went wrong',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Colors.grey[600],
),
),
const SizedBox(height: 8),
Text(
'Please check your connection and try again',
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: () {
// Use post-frame callback for state changes
WidgetsBinding.instance.addPostFrameCallback((_) {
ref.invalidate(categoryListProvider);
});
},
icon: const Icon(Icons.refresh),
label: const Text('Retry'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
),
),
),
],
),
),
),
],
);
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,932 @@
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/model/booking_modify_model.dart';
import 'package:bookmywages/model/cancel_booking.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
class ServiceBooking extends ConsumerStatefulWidget {
const ServiceBooking({super.key});
@override
ConsumerState<ServiceBooking> createState() => _ServiceBookingState();
}
class _ServiceBookingState extends ConsumerState<ServiceBooking> {
@override
Widget build(BuildContext context) {
final bookingAsyncValue = ref.watch(userbookinghistorydetailsProvider);
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: bookingAsyncValue.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, stack) => Center(child: Text('Error: $err')),
data: (bookings) {
return ListView.builder(
itemCount: bookings.length,
shrinkWrap: false,
itemBuilder: (context, index) {
final booking = bookings[index];
return Container(
margin: const EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
border: Border.all(color: AppColors.lightGrey),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/// Top Row: ID and "View order"
Padding(
padding: const EdgeInsets.only(
right: 12,
left: 12,
top: 12,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'ID : ${booking.id}',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
// Update the onTap method in the ServiceBooking class
GestureDetector(
onTap: () {
Get.toNamed(
RouterConts.detailserivce,
arguments: booking.serviceId,
);
},
child: Text(
'View order',
style: TextStyle(
color: Colors.blue.shade600,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
const Divider(),
/// Image, Company, and Status
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(12),
child: (booking.images1.isNotEmpty)
? Image.network(
booking.images1[0],
width: 100,
height: 110,
fit: BoxFit.cover,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) {
return child;
}
return Center(
child: CircularProgressIndicator(
value:
loadingProgress
.expectedTotalBytes !=
null
? loadingProgress
.cumulativeBytesLoaded /
(loadingProgress
.expectedTotalBytes ??
1)
: null,
),
);
},
errorBuilder:
(context, error, stackTrace) {
return const Icon(
Icons.error,
size: 100,
);
},
)
: const Icon(
Icons.image_not_supported,
size: 100,
),
),
Positioned(
top: 6,
left: 6,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 6,
height: 6,
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
const SizedBox(width: 4),
const Text(
'Live',
style: TextStyle(
fontSize: 12,
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
const SizedBox(width: 12),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
booking.vendorName ??
'Arun Cleaning Company',
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 16.11,
height: 14.5 / 16.11,
letterSpacing: 0.01 * 16.11,
),
),
const SizedBox(height: 4),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
booking.serviceName ??
'Cleaning service',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w500,
fontSize: 13.91,
height: 1.3,
letterSpacing: 0.01 * 13.91,
color: Color(0xFF5A5A5A),
),
),
),
const SizedBox(width: 10),
// Updated status display code in the ServiceBooking class
Expanded(
child: Container(
width: booking.status == 3
? 70
: booking.status == 1
? 85 // Width for Scheduled
: 77.84, // Width for Pending and other statuses
height: booking.status == 3
? 25
: booking.status == 1
? 25 // Height for Scheduled
: 27.96, // Height for Pending and other statuses
decoration: BoxDecoration(
color: booking.status == 3
? const Color(
0xFFFFEEEE,
) // #FFEEEE for Cancel
: booking.status == 1
? const Color(
0xFFE6F7E6,
) // Light green for Scheduled
: const Color(
0xFFDAE9FF,
), // #DAE9FF for Pending
borderRadius: BorderRadius.circular(
6.05,
), // 6.05px border radius
),
child: Center(
child: Text(
booking.status == 3
? 'Cancel'
: booking.status == 1
? 'Scheduled' // Text for status 1
: 'Pending', // Text for other statuses
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontSize: 10.92,
fontWeight: FontWeight.w400,
color: booking.status == 3
? const Color(
0xFFFF0000,
) // Red color for Cancel
: booking.status == 1
? const Color(
0xFF2E8B57,
) // Green color for Scheduled
: const Color(
0xFF0066FF,
), // Blue color for Pending
letterSpacing: 1.0,
height: 0.98,
),
),
),
),
),
],
),
const SizedBox(height: 6),
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(
color: AppColors.lightGrey,
),
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 15,
backgroundImage:
booking.profilePic != null &&
booking.profilePic!.isNotEmpty
? NetworkImage(
booking.profilePic.toString(),
)
: null,
child:
booking.profilePic == null ||
booking.profilePic!.isEmpty
? const Icon(
Icons.person,
size: 20,
)
: null,
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
booking.vendorName ??
'no data',
style: const TextStyle(
fontFamily:
'Gilroy-Medium',
fontWeight:
FontWeight.w600,
fontSize: 11,
height: 10.65 / 11.84,
letterSpacing: 0,
color: Color(
0xFF353434,
),
),
overflow:
TextOverflow.visible,
),
),
const Icon(
Icons.star,
color: Colors.orange,
size: 15,
),
const SizedBox(width: 4),
// Fixed: Changed to properly handle isRated as an integer
Text(
'${booking.isRated}',
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily:
'SF UI Display',
fontWeight:
FontWeight.w800,
fontSize: 10,
height: 12.5 / 8.82,
letterSpacing: -0.31,
),
),
],
),
SizedBox(height: 7),
Text(
booking.categoryName,
style: const TextStyle(
fontFamily: 'Gilroy-Regular',
fontWeight: FontWeight.w400,
fontSize: 11.84,
height: 10.65 / 11.84,
letterSpacing: 0,
color: Color(0xFF717171),
),
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
),
],
),
),
],
),
),
const SizedBox(height: 16),
/// Date / Time / Hours
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Date :',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
const SizedBox(height: 10),
Text(
booking.serviceDate ?? 'April 23, 2024',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Time :',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
const SizedBox(height: 10),
Text(
booking.serviceTime ?? '12:00 PM',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Working hours :',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
SizedBox(height: 10),
Text(
booking.workingHours,
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
],
),
),
const SizedBox(height: 20),
/// Canceled Booking Button
/// Buttons Section - Modified for Scheduled Status
booking.status != 3
? Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 10,
),
child: Row(
mainAxisAlignment: booking.status == 1
? MainAxisAlignment
.end // Align to the right for Scheduled status
: MainAxisAlignment
.spaceBetween, // Normal alignment for other statuses
children: [
// Only show Modification button if status is NOT Scheduled (status 1)
booking.status != 1
? Expanded(
child: SizedBox(
height: 42,
child: ElevatedButton(
onPressed: () {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => Dialog(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
20,
),
),
child: Container(
width: double.maxFinite,
decoration: BoxDecoration(
color: AppColors
.secondprimary,
borderRadius:
BorderRadius.circular(
16,
),
),
child:
BookingModificationDialog(
id: booking.id
.toString(),
serviceId: booking
.serviceId
.toString(),
),
),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(
0xFF0066FF,
),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(20),
),
),
child: const FittedBox(
child: Text(
"Modification",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w800,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0.289,
color: Colors.white,
),
),
),
),
),
)
: const SizedBox.shrink(), // Empty space when Scheduled
booking.status != 1
? const SizedBox(width: 8)
: const SizedBox.shrink(),
// Cancel Button - Always visible
GestureDetector(
onTap: () async {
final data = CancelBookingRequest(
id: booking.id.toString(),
serviceId: booking.serviceId.toString(),
type: booking.type == 0
? "0"
: booking.type.toString(),
);
try {
// Call the cancel API
await ref.read(
cancelbookingProvider(data).future,
);
// Show success message
Fluttertoast.showToast(
msg: 'Booking cancelled successfully',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
);
// Refresh the booking history data
ref.invalidate(
userbookinghistorydetailsProvider,
);
} catch (e) {
// Show error message
Fluttertoast.showToast(
msg: 'Failed to cancel booking: $e',
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
},
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
decoration: BoxDecoration(
color: Colors.red.shade50,
borderRadius: BorderRadius.circular(20),
),
child: const Text(
'Cancel Booking',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
)
: const SizedBox.shrink(),
const SizedBox(height: 20),
],
),
);
},
);
},
),
),
);
}
// Updated _loadBookingImage and related methods to handle images properly
// Check if URL is likely to cause a 500 error
}
class BookingModificationDialog extends ConsumerStatefulWidget {
final String id;
final String serviceId;
const BookingModificationDialog({
super.key,
required this.id,
required this.serviceId,
});
@override
_BookingModificationDialogState createState() =>
_BookingModificationDialogState();
}
class _BookingModificationDialogState
extends ConsumerState<BookingModificationDialog> {
int selectedDateIndex = 0;
int selectedTimeIndex = 0;
DateTime currentMonth = DateTime.now();
late List<DateTime> dateList;
List<String> times = [];
@override
void initState() {
super.initState();
_generateDateList();
_generateTimes();
}
void _generateDateList() {
final firstDay = DateTime(currentMonth.year, currentMonth.month, 1);
final lastDay = DateTime(currentMonth.year, currentMonth.month + 1, 0);
dateList = List.generate(
lastDay.day,
(index) => firstDay.add(Duration(days: index)),
);
selectedDateIndex = 0;
}
void _generateTimes() {
times = [];
for (int hour = 0; hour < 24; hour++) {
for (int minute = 0; minute < 60; minute += 30) {
final time = DateTime(0, 0, 0, hour, minute);
times.add(DateFormat('h:mm a').format(time));
}
}
}
void _goToPreviousMonth() {
final newMonth = DateTime(currentMonth.year, currentMonth.month - 1);
if (newMonth.isBefore(
DateTime(DateTime.now().year, DateTime.now().month, 1),
)) {
return;
}
setState(() {
currentMonth = newMonth;
_generateDateList();
});
}
void _goToNextMonth() {
setState(() {
currentMonth = DateTime(currentMonth.year, currentMonth.month + 1);
_generateDateList();
});
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
top: 20,
left: 20,
right: 20,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Booking Modification',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Change Date',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
Icon(Icons.calendar_today),
],
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: _goToPreviousMonth,
icon: Icon(Icons.arrow_back_ios),
),
Text(
DateFormat('MMMM yyyy').format(currentMonth),
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
IconButton(
onPressed: _goToNextMonth,
icon: Icon(Icons.arrow_forward_ios),
),
],
),
SizedBox(height: 10),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(dateList.length, (index) {
final date = dateList[index];
final dayLabel =
'${DateFormat('E').format(date)}\n${DateFormat('d').format(date)}';
final isSelected = selectedDateIndex == index;
return GestureDetector(
onTap: () {
setState(() {
selectedDateIndex = index;
});
},
child: Container(
margin: EdgeInsets.symmetric(horizontal: 5),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: isSelected ? Colors.blue : Colors.grey.shade200,
borderRadius: BorderRadius.circular(20),
),
child: Text(
dayLabel,
textAlign: TextAlign.center,
style: TextStyle(
color: isSelected ? Colors.white : Colors.black,
fontWeight: FontWeight.bold,
),
),
),
);
}),
),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Change Time',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
Icon(Icons.access_time),
],
),
SizedBox(height: 10),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.generate(times.length, (index) {
final isSelected = selectedTimeIndex == index;
return GestureDetector(
onTap: () {
setState(() {
selectedTimeIndex = index;
});
},
child: Container(
margin: EdgeInsets.symmetric(horizontal: 5),
padding: EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
decoration: BoxDecoration(
color: isSelected ? Colors.blue : Colors.grey.shade200,
borderRadius: BorderRadius.circular(30),
),
child: Text(
times[index],
style: TextStyle(
color: isSelected ? Colors.white : Colors.black,
fontWeight: FontWeight.bold,
),
),
),
);
}),
),
),
SizedBox(height: 20),
// GestureDetector(
// onTap: () {
// Navigator.pop(context);
// },
// child: Container(
// width: double.infinity,
// padding: EdgeInsets.all(15),
// decoration: BoxDecoration(
// color: Colors.red.shade50,
// borderRadius: BorderRadius.circular(15),
// ),
// child: Center(
// child: Text(
// 'Cancel the Booking',
// style: TextStyle(
// color: Colors.red,
// fontWeight: FontWeight.bold,
// fontSize: 16,
// ),
// ),
// ),
// ),
// ),
SizedBox(height: 20),
ElevatedButton(
onPressed: () async {
final selectedDate = DateFormat(
'yyyy-MM-dd',
).format(dateList[selectedDateIndex]);
final selectedTime = times[selectedTimeIndex];
final model = BookingModifyModel(
id: widget.id,
serviceId: widget.serviceId,
servicedate: selectedDate,
servicetime: selectedTime,
);
final result = await ref
.read(modifybookingProvider(model).future)
.catchError((e) {
Fluttertoast.showToast(
msg: 'Error: ${e.toString()}',
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
return false;
});
if (result) {
Fluttertoast.showToast(
msg: 'Booking modified successfully',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
);
Navigator.pop(context);
ref.invalidate(userbookinghistorydetailsProvider);
} else {
Fluttertoast.showToast(
msg: 'Failed to modify booking',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
padding: EdgeInsets.symmetric(horizontal: 100, vertical: 15),
),
child: Text('Save', style: TextStyle(fontSize: 18)),
),
SizedBox(height: 20),
],
),
),
);
}
}
@@ -0,0 +1,460 @@
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
// Make sure to import your custom colors and dialog widget
// Assuming this exists
class CanceledPage extends ConsumerWidget {
// Changed to ConsumerWidget
const CanceledPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
// Added WidgetRef parameter
final bookingAsyncValue = ref.watch(userbookinghistorydetailsProvider);
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: bookingAsyncValue.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, stack) => Center(child: Text('Error: $err')),
data: (bookings) {
// Filter only canceled bookings (status == 3)
final canceledBookings =
bookings.where((booking) => booking.status == 3).toList();
if (canceledBookings.isEmpty) {
return const Center(
child: Text(
'No canceled bookings found',
style: TextStyle(fontSize: 16),
),
);
}
return ListView.builder(
itemCount: canceledBookings.length,
shrinkWrap: false,
itemBuilder: (context, index) {
final booking = canceledBookings[index];
return Container(
margin: const EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
border: Border.all(color: AppColors.lightGrey),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/// Top Row: ID and "View order"
Padding(
padding: const EdgeInsets.only(
right: 12,
left: 12,
top: 12,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'ID : ${booking.id}',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
],
),
),
const Divider(),
/// Image, Company, and Status
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(12),
child:
(booking.images1.isNotEmpty)
? Image.network(
booking.images1[0],
width: 100,
height: 110,
fit: BoxFit.cover,
loadingBuilder: (
context,
child,
loadingProgress,
) {
if (loadingProgress == null) {
return child;
}
return Center(
child: CircularProgressIndicator(
value:
loadingProgress
.expectedTotalBytes !=
null
? loadingProgress
.cumulativeBytesLoaded /
(loadingProgress
.expectedTotalBytes ??
1)
: null,
),
);
},
errorBuilder: (
context,
error,
stackTrace,
) {
return const Icon(
Icons.error,
size: 100,
);
},
)
: const Icon(
Icons.image_not_supported,
size: 100,
),
),
Positioned(
top: 6,
left: 6,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 6,
height: 6,
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
const SizedBox(width: 4),
const Text(
'Live',
style: TextStyle(
fontSize: 12,
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
const SizedBox(width: 12),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
booking.vendorName ?? 'No vendor name',
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 16.11,
height: 14.5 / 16.11,
letterSpacing: 0.01 * 16.11,
),
),
const SizedBox(height: 4),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
booking.serviceName ??
'No service name',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w500,
fontSize: 13.91,
height: 12.52 / 13.91,
letterSpacing: 0.01 * 13.91,
color: Color(0xFF5A5A5A),
),
),
const SizedBox(width: 10),
Container(
width: 70,
height: 25,
decoration: BoxDecoration(
color: const Color(0xFFFFEEEE),
borderRadius: BorderRadius.circular(
6.05,
),
),
child: Center(
child: Text(
'Cancel',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontSize: 10.92,
fontWeight: FontWeight.w400,
color: const Color(0xFFFF0000),
letterSpacing: 1.0,
height: 0.98,
),
),
),
),
],
),
const SizedBox(height: 6),
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(
color: AppColors.lightGrey,
),
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 15,
backgroundImage:
booking.profilePic != null &&
booking
.profilePic!
.isNotEmpty
? NetworkImage(
booking.profilePic!,
)
: null,
child:
booking.profilePic == null ||
booking
.profilePic!
.isEmpty
? const Icon(
Icons.person,
size: 20,
)
: null,
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
booking.vendorName ??
'No data',
style: const TextStyle(
fontFamily:
'Gilroy-Medium',
fontWeight:
FontWeight.w600,
fontSize: 11,
height: 10.65 / 11.84,
letterSpacing: 0,
color: Color(
0xFF353434,
),
),
overflow:
TextOverflow.ellipsis,
),
),
const Icon(
Icons.star,
color: Colors.orange,
size: 15,
),
const SizedBox(width: 4),
Text(
'${booking.isRated ?? '0.0'}',
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily:
'SF UI Display',
fontWeight:
FontWeight.w800,
fontSize: 10,
height: 12.5 / 8.82,
letterSpacing: -0.31,
),
),
],
),
const SizedBox(height: 7),
Text(
booking.categoryName ??
'No category',
style: const TextStyle(
fontFamily: 'Gilroy-Regular',
fontWeight: FontWeight.w400,
fontSize: 11.84,
height: 10.65 / 11.84,
letterSpacing: 0,
color: Color(0xFF717171),
),
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
),
],
),
),
],
),
),
const SizedBox(height: 16),
/// Date / Time / Hours
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Date :',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
const SizedBox(height: 10),
Text(
booking.cancelDate != null
? _formatDate(booking.cancelDate)
: 'No date',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Time :',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
const SizedBox(height: 10),
Text(
booking.cancelDate != null
? DateFormat('h:mm a').format(
DateTime.parse(booking.cancelDate),
)
: 'No time',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Working hours :',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
const SizedBox(height: 10),
Text(
booking.workingHours ?? 'No hours',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
],
),
),
const SizedBox(height: 20),
],
),
);
},
);
},
),
),
);
}
String _formatDate(String dateString) {
try {
return DateFormat('dd/MM/yyyy').format(DateTime.parse(dateString));
} catch (e) {
return dateString; // Fallback: return the original string if parsing fails
}
}
}
@@ -0,0 +1,446 @@
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
// Make sure to import your custom colors and dialog widget
// Assuming this exists
class CompletedPage extends ConsumerWidget {
// Changed to ConsumerWidget
const CompletedPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
// Added WidgetRef parameter
final bookingAsyncValue = ref.watch(userbookinghistorydetailsProvider);
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: bookingAsyncValue.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, stack) => Center(child: Text('Error: $err')),
data: (bookings) {
// Filter only canceled bookings (status == 3)
final canceledBookings =
bookings.where((booking) => booking.status == 1).toList();
if (canceledBookings.isEmpty) {
return const Center(
child: Text(
'No canceled bookings found',
style: TextStyle(fontSize: 16),
),
);
}
return ListView.builder(
itemCount: canceledBookings.length,
shrinkWrap: false,
itemBuilder: (context, index) {
final booking = canceledBookings[index];
return Container(
margin: const EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
border: Border.all(color: AppColors.lightGrey),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/// Top Row: ID and "View order"
Padding(
padding: const EdgeInsets.only(
right: 12,
left: 12,
top: 12,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'ID : ${booking.id}',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
],
),
),
const Divider(),
/// Image, Company, and Status
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(12),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child:
booking.images1.isNotEmpty
? Image.network(
booking.images1[0],
width: 100,
height: 110,
fit: BoxFit.cover,
loadingBuilder: (
context,
child,
loadingProgress,
) {
if (loadingProgress == null) {
return child;
} else {
return Center(
child: CircularProgressIndicator(
value:
loadingProgress
.expectedTotalBytes !=
null
? loadingProgress
.cumulativeBytesLoaded /
(loadingProgress
.expectedTotalBytes ??
1)
: null,
),
);
}
},
errorBuilder: (
context,
error,
stackTrace,
) {
return const Icon(
Icons.error,
size: 100,
);
},
)
: const Icon(
Icons.image_not_supported,
size: 100,
),
),
),
Positioned(
top: 6,
left: 6,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 6,
height: 6,
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
const SizedBox(width: 4),
const Text(
'Live',
style: TextStyle(
fontSize: 12,
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
const SizedBox(width: 12),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
booking.vendorName ?? 'No vendor name',
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 16.11,
height: 14.5 / 16.11,
letterSpacing: 0.01 * 16.11,
),
),
const SizedBox(height: 4),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
booking.serviceName ??
'No service name',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w500,
fontSize: 13.91,
height: 12.52 / 13.91,
letterSpacing: 0.01 * 13.91,
color: Color(0xFF5A5A5A),
),
),
const SizedBox(width: 10),
Container(
width: 70,
height: 25,
decoration: BoxDecoration(
color: const Color(0xffFFEEDB),
borderRadius: BorderRadius.circular(
6.05,
),
),
child: Center(
child: Text(
'Completed',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontSize: 10.92,
fontWeight: FontWeight.w400,
color: const Color(0xffFF8515),
letterSpacing: 1.0,
height: 0.98,
),
),
),
),
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
'Date :',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
const SizedBox(height: 10),
Text(
booking.serviceDate != null
? _formatDate(
booking.serviceDate,
)
: 'No date',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
'Time :',
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
const SizedBox(height: 10),
Text(
booking.serviceDate != null
? DateFormat('h:mm a').format(
DateTime.parse(
booking.serviceDate,
),
)
: 'No time',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
],
),
],
),
),
],
),
),
const SizedBox(height: 16),
/// Date / Time / Hours
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
"Mobile number : ",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
SizedBox(width: 7),
Text(
booking.mobileNumber,
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
SizedBox(height: 10),
Row(
children: [
Text(
"E-mail ID :",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
SizedBox(width: 7),
Text(
booking.email,
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
SizedBox(height: 10),
Row(
children: [
Text(
"Address : ",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
SizedBox(width: 7),
Text(
booking.address,
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
SizedBox(height: 10),
Text(
"Message : ",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
SizedBox(height: 7),
Text(
booking.message,
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 14.45,
height: 13 / 14.45,
letterSpacing: 0,
),
),
],
),
),
const SizedBox(height: 20),
],
),
);
},
);
},
),
),
);
}
String _formatDate(String dateString) {
try {
return DateFormat('dd/MM/yyyy').format(DateTime.parse(dateString));
} catch (e) {
return dateString; // Fallback: return the original string if parsing fails
}
}
}
@@ -0,0 +1,376 @@
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
class EnquriyPage extends ConsumerStatefulWidget {
const EnquriyPage({super.key});
@override
ConsumerState<EnquriyPage> createState() => _EnquriyPageState();
}
class _EnquriyPageState extends ConsumerState<EnquriyPage> {
int? expandedIndex;
@override
Widget build(BuildContext context) {
final enquiryListAsync = ref.watch(enquriylistProvider);
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: enquiryListAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(child: Text('Error: $error')),
data: (enquiries) => SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: List.generate(enquiries.length, (index) {
final enquiry = enquiries[index];
final isExpanded = expandedIndex == index;
return SizedBox(
width: double.infinity,
child: Column(
children: [
Container(
margin: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 16,
),
decoration: BoxDecoration(
color: AppColors.secondprimary,
borderRadius: BorderRadius.circular(11),
border: Border.all(
color: const Color(0xFFE8E8E8),
width: 1,
),
boxShadow: const [
BoxShadow(
color: Color(0x66AEAEAE),
offset: Offset(0, 2),
blurRadius: 4,
),
],
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: (enquiry.images1.isEmpty)
? Container(
width: 89,
height: 64,
color: Colors.grey[300],
child: Icon(
Icons.image,
color: Colors.grey[600],
),
)
: Image.network(
enquiry.images1.first,
width: 89,
height: 64,
fit: BoxFit.cover,
errorBuilder:
(context, error, stackTrace) =>
Container(
width: 89,
height: 64,
color: Colors.grey[300],
child: Icon(
Icons.broken_image,
color: Colors.grey[600],
),
),
),
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
enquiry.vendorName ?? 'vendorName',
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 16,
height: 18.14 / 16,
letterSpacing: 0.16,
color: Colors.black,
),
),
const SizedBox(height: 12),
GestureDetector(
onTap: () {
setState(() {
expandedIndex = isExpanded
? null
: index;
});
},
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
enquiry.serviceName,
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 16.11,
height: 17.3 / 16.11,
letterSpacing: 0.1611,
color: Colors.black,
),
),
),
const SizedBox(width: 4),
Flex(
direction: Axis.horizontal,
mainAxisSize: MainAxisSize.min,
children: [
Text(
isExpanded
? "View Less"
: "View More",
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 13.15,
height: 5.71 / 13.15,
color: Color(0xFFFF3D00),
),
),
const SizedBox(width: 5),
Icon(
isExpanded
? Icons.keyboard_arrow_up
: Icons
.keyboard_arrow_down,
color: const Color(
0xffFF3D00,
),
),
],
),
],
),
),
],
),
),
],
),
],
),
),
),
if (isExpanded)
Container(
width: double.infinity,
margin: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.43),
border: Border.all(
color: const Color(0xFFE8E8E8),
width: 0.82,
),
boxShadow: const [
BoxShadow(
color: Color(0xA9A9A940),
blurRadius: 3.29,
offset: Offset(0, 0.82),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text.rich(
TextSpan(
children: [
const TextSpan(
text: "Name : ",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 13,
height: 1.239,
),
),
TextSpan(
text: enquiry.name ?? 'No Name',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 13,
height: 1.239,
color: Color(0xFF373636),
),
),
],
),
),
IconButton(
icon: const Icon(
Icons.delete,
color: AppColors.red,
size: 20,
),
onPressed: () async {
final shouldDelete = await showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Delete Enquiry'),
content: const Text(
'Are you sure you want to delete this enquiry?',
),
actions: [
TextButton(
onPressed: () => Navigator.of(
context,
).pop(false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () =>
Navigator.of(context).pop(true),
child: const Text('Delete'),
),
],
),
);
if (shouldDelete == true) {
Fluttertoast.showToast(
msg: 'Deleting enquiry...',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.grey,
textColor: Colors.white,
);
try {
final success = await ref.read(
enquriydeleteProvider(
enquiry.id.toString(),
).future,
);
if (success) {
// Reset expanded index and refresh the list
setState(() {
expandedIndex = null;
});
await Future.delayed(
const Duration(milliseconds: 300),
);
ref.invalidate(enquriylistProvider);
Fluttertoast.showToast(
msg: 'Enquiry deleted successfully',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
);
} else {
Fluttertoast.showToast(
msg: 'Failed to delete enquiry',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
} catch (e) {
Fluttertoast.showToast(
msg: 'Error: ${e.toString()}',
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
}
},
),
],
),
const SizedBox(height: 8),
_infoText(
"Mobile number : ",
enquiry.mobile ?? 'No Mobile',
),
const SizedBox(height: 13),
_infoText(
"E-mail Id : ",
enquiry.email ?? 'No Email',
),
const SizedBox(height: 13),
_infoText(
"Message : ",
enquiry.message ?? 'No Message',
),
],
),
),
],
),
);
}),
),
),
),
);
}
Widget _infoText(String label, String value) {
return Text.rich(
TextSpan(
children: [
TextSpan(
text: label,
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 13,
height: 1.239,
),
),
TextSpan(
text: value,
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 13,
height: 1.239,
color: Color(0xFF373636),
),
),
],
),
);
}
}
@@ -0,0 +1,175 @@
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/view/user_main_screens/history_screen/Service_Booking.dart';
import 'package:bookmywages/view/user_main_screens/history_screen/canceled_page.dart';
import 'package:bookmywages/view/user_main_screens/history_screen/completed_screen.dart';
import 'package:bookmywages/view/user_main_screens/history_screen/enquriy_page.dart';
import 'package:bookmywages/view/user_main_screens/history_screen/payment_deatils.dart';
import 'package:bookmywages/view/user_main_screens/main_contoller.dart';
import 'package:flutter/material.dart';
class HistoryScreen extends StatefulWidget {
final int? initialTabIndex;
const HistoryScreen({super.key, this.initialTabIndex});
@override
State<HistoryScreen> createState() => _HistoryScreenState();
}
class _HistoryScreenState extends State<HistoryScreen>
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
int _currentIndex = 0;
TabController? _tabController;
@override
bool get wantKeepAlive => true;
final List<String> tabTitles = [
"Service Booking", // Index 0
"Enquiry list", // Index 1
"Payment Details", // Index 2
"Completed Booking", // Index 3
"Cancelation Booking", // Index 4
];
@override
void initState() {
super.initState();
// Set initial tab index from widget parameter
if (widget.initialTabIndex != null &&
widget.initialTabIndex! >= 0 &&
widget.initialTabIndex! < tabTitles.length) {
_currentIndex = widget.initialTabIndex!;
}
// Initialize TabController with the correct initial index
_tabController = TabController(
length: tabTitles.length,
vsync: this,
initialIndex: _currentIndex,
);
_tabController!.addListener(() {
if (_tabController!.indexIsChanging) {
setState(() {
_currentIndex = _tabController!.index;
});
}
});
}
@override
void dispose() {
_tabController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
super.build(context);
if (_tabController == null) {
return const Scaffold(body: Center(child: CircularProgressIndicator()));
}
return PopScope(
onPopInvoked: (didPop) {
if (didPop) {
final indexController = InheritedIndexController.of(context);
indexController?.changeIndex(0);
}
},
child: Scaffold(
backgroundColor: Colors.white,
appBar: PreferredSize(
preferredSize: const Size.fromHeight(150.0),
child: Column(
children: [
AppBar(
backgroundColor: Colors.white,
elevation: 0,
title: const Text(
"History",
style: TextStyle(
fontFamily: 'Inter',
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
centerTitle: true,
),
Container(
margin: const EdgeInsets.only(top: 16.0),
alignment: Alignment.centerLeft,
height: 65,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: TabBar(
controller: _tabController,
isScrollable: true,
tabAlignment: TabAlignment.start,
dividerColor: Colors.transparent,
indicatorColor: Colors.transparent,
labelPadding: const EdgeInsets.symmetric(horizontal: 8.0),
tabs: List.generate(
tabTitles.length,
(index) => _buildCustomTab(
tabTitles[index],
index == _currentIndex,
),
),
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
),
),
),
],
),
),
body: TabBarView(
controller: _tabController,
physics: const NeverScrollableScrollPhysics(),
children: const [
ServiceBooking(), // Index 0
EnquriyPage(), // Index 1
PaymentDetails(), // Index 2
CompletedPage(), // Index 3
CanceledPage(), // Index 4
],
),
),
);
}
Widget _buildCustomTab(String text, bool isSelected) {
return Tab(
height: 53,
child: Container(
width: 180,
height: 45,
decoration: BoxDecoration(
color: isSelected ? AppColors.primary : AppColors.secondprimary,
border: Border.all(color: const Color(0xFFDBDBDB)),
borderRadius: BorderRadius.circular(15),
),
alignment: Alignment.center,
child: Text(
text,
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w400,
fontSize: 15,
height: 1.0,
letterSpacing: 0.5,
color: isSelected ? AppColors.secondprimary : AppColors.lightgray,
),
),
),
);
}
}
@@ -0,0 +1,448 @@
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';
class PaymentDetails extends ConsumerStatefulWidget {
const PaymentDetails({super.key});
@override
ConsumerState<PaymentDetails> createState() => _PaymentDetailsState();
}
class _PaymentDetailsState extends ConsumerState<PaymentDetails> {
List<dynamic> _localPayments = [];
@override
Widget build(BuildContext context) {
final paymentAsync = ref.watch(paymentdetailsProvider);
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: paymentAsync.when(
data: (payments) {
final filteredPayments = payments.where((p) => p.type == 1).toList();
// Initialize local copy only once
if (_localPayments.isEmpty) {
_localPayments = List.from(filteredPayments);
}
if (_localPayments.isEmpty) {
return const Center(child: Text("No payment history found."));
}
return RefreshIndicator(
onRefresh: () async {
final refreshed = await ref.refresh(
paymentdetailsProvider.future,
);
setState(() {
_localPayments = refreshed.where((p) => p.type == 2).toList();
});
},
child: ListView.builder(
itemCount: _localPayments.length,
itemBuilder: (context, index) {
final payment = _localPayments[index];
return Dismissible(
key: Key(payment.id.toString()),
direction: DismissDirection.endToStart,
background: Container(
margin: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(20),
),
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 20),
child: const Icon(Icons.delete, color: Colors.white),
),
confirmDismiss: (direction) async {
return await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Confirm Delete"),
content: const Text(
"Are you sure you want to delete this payment record?",
),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text("CANCEL"),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text(
"DELETE",
style: TextStyle(color: Colors.red),
),
),
],
);
},
);
},
onDismissed: (direction) async {
Fluttertoast.showToast(
msg: 'Deleting payment...',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.grey,
textColor: Colors.white,
);
final success = await ref.read(
paymentdeleteProvider(payment.id.toString()).future,
);
if (success) {
setState(() {
_localPayments.removeAt(index);
});
Fluttertoast.showToast(
msg: '${payment.planName} deleted successfully',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
);
} else {
Fluttertoast.showToast(
msg: 'Failed to delete payment',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
},
child: Container(
margin: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: const Color(0xFFCFCFCF),
width: 1,
),
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width: 130,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFF334E95),
borderRadius: BorderRadius.circular(12.86),
border: Border.all(
color: Colors.white,
width: 0.43,
),
boxShadow: [
BoxShadow(
color: const Color(0x40828282),
blurRadius: 1.71,
offset: const Offset(0, 2.14),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
payment.planName,
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 14,
height: 1.0,
letterSpacing: 0.1371,
color: Colors.white,
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(height: 15),
Row(
children: [
Container(
width: 6.86,
height: 6.86,
decoration: const BoxDecoration(
color: Color(0xFFF9E369),
shape: BoxShape.circle,
),
),
const SizedBox(width: 8),
Expanded(
child: Text(
_formatDuration(payment.duration),
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 12,
height: 1.0,
letterSpacing: 0.0771,
color: Colors.white,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
const SizedBox(height: 10),
Row(
children: [
Container(
width: 6.86,
height: 6.86,
decoration: const BoxDecoration(
color: Color(0xFFF9E369),
shape: BoxShape.circle,
),
),
const SizedBox(width: 8),
Expanded(
child: Text(
payment.description,
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w400,
fontSize: 12,
height: 1.0,
letterSpacing: 0.0771,
color: Colors.white,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
],
),
const Divider(color: Colors.white),
Center(
child: Text(
_formatPrice(payment.price),
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
],
),
),
const SizedBox(width: 12),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
payment.planName,
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 19.9,
height: 1.0,
letterSpacing: 0.199,
color: Colors.black,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 10),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
"Start :",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 15.61,
height: 14.04 / 15.61,
letterSpacing: 0.0,
color: Colors.black,
),
),
const SizedBox(height: 10),
Text(
DateFormat('MMM d, y').format(
DateTime.parse(
payment.createdDate,
),
),
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w700,
fontSize: 12,
height: 14.04 / 15.61,
letterSpacing: 0.0,
color: Color(0xFF636363),
),
),
],
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
"End :",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 15.61,
height: 14.04 / 15.61,
letterSpacing: 0.0,
color: Colors.black,
),
),
const SizedBox(height: 10),
Text(
DateFormat('MMM d, y').format(
DateTime.parse(payment.endDate),
),
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w700,
fontSize: 12,
height: 14.04 / 15.61,
letterSpacing: 0.0,
color: Color(0xFF636363),
),
),
],
),
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
"Time :",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 15.61,
height: 14.04 / 15.61,
letterSpacing: 0.0,
color: Colors.black,
),
),
const SizedBox(height: 10),
Text(
DateFormat('hh:mm a').format(
DateTime.parse(
payment.createdDate,
),
),
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w700,
fontSize: 12,
height: 14.04 / 15.61,
letterSpacing: 0.0,
color: Color(0xFF636363),
),
),
],
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
"Payment :",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 15.61,
height: 14.04 / 15.61,
letterSpacing: 0.0,
color: Colors.black,
),
),
const SizedBox(height: 10),
Text(
_formatPrice(payment.price),
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w700,
fontSize: 12,
height: 14.04 / 15.61,
letterSpacing: 0.0,
color: Color(0xFF636363),
),
),
],
),
],
),
],
),
),
),
],
),
),
),
);
},
),
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, _) => Center(child: Text("Error: ${e.toString()}")),
),
);
}
static String _formatDuration(int days) {
if (days == 30) return '1 Month';
if (days == 60) return '2 Months';
if (days == 90) return '3 Months';
if (days == 180) return '6 Months';
if (days == 365) return '1 Year';
return '$days Days';
}
static String _formatPrice(String price) {
if (price.startsWith('Rs.')) {
return price;
}
return 'Rs.$price';
}
}
File diff suppressed because it is too large. Load diff
+116
View File
@@ -0,0 +1,116 @@
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:get/get.dart';
class ImagePage extends StatefulWidget {
final List<String> mediaUrls;
const ImagePage({super.key, required this.mediaUrls});
@override
State<ImagePage> createState() => _ImagePageState();
}
class _ImagePageState extends State<ImagePage> {
int selectedImageIndex = 0; // Track the currently selected image
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.secondprimary,
appBar: AppBar(
backgroundColor: AppColors.secondprimary,
leading: IconButton(
onPressed: () => Get.back(),
icon: Icon(Icons.arrow_back_ios_outlined),
),
title: Text("Service Image"),
centerTitle: true,
),
body: Column(
children: [
SizedBox(height: 50),
Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(
22.94,
), // Set border-radius to 22.94
child: CachedNetworkImage(
imageUrl: widget.mediaUrls.isNotEmpty
? widget.mediaUrls[selectedImageIndex] // Use selected index
: '',
width: 250, // Set width to 250
height: 250, // Set height to 250
fit: BoxFit.cover,
placeholder: (context, url) => const Center(
child: SizedBox(
width: 30,
height: 30,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
errorWidget: (context, url, error) => const Icon(Icons.error),
),
),
),
SizedBox(height: 20),
CarouselSlider(
options: CarouselOptions(
height: 150, // Set height of the carousel
enlargeCenterPage: true,
enableInfiniteScroll: false,
viewportFraction: 0.3,
aspectRatio: 1.0,
),
items: widget.mediaUrls.asMap().entries.map((entry) {
int index = entry.key;
String url = entry.value;
bool isSelected = index == selectedImageIndex;
return GestureDetector(
onTap: () {
setState(() {
selectedImageIndex = index; // Update selected image
});
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22.94),
border: isSelected
? Border.all(
color: Colors.blue,
width: 3,
) // Highlight selected image
: null,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(
22.94,
), // Set border-radius to 22.94
child: CachedNetworkImage(
imageUrl: url,
width: 176, // Set width to 176
height: 158, // Set height to 158
fit: BoxFit.cover,
placeholder: (context, url) => const Center(
child: SizedBox(
width: 30,
height: 30,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
errorWidget: (context, url, error) =>
const Icon(Icons.error),
),
),
),
);
}).toList(),
),
],
),
);
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,377 @@
import 'dart:convert';
import 'dart:ui';
import 'dart:math' as math;
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; // Add this import
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http;
class MainController extends ConsumerStatefulWidget {
final Widget child;
final int? initialBottomIndex;
const MainController({
super.key,
required this.child,
this.initialBottomIndex,
});
@override
ConsumerState<MainController> createState() => _MainControllerState();
}
class _MainControllerState extends ConsumerState<MainController>
with SingleTickerProviderStateMixin {
int _selectedIndex = 0;
bool _showMenu = false;
late AnimationController _animationController;
@override
void initState() {
super.initState();
// Set bottom navigation index
if (widget.initialBottomIndex != null) {
_selectedIndex = widget.initialBottomIndex!;
} else {
// Auto-detect based on current route
final currentRoute = Get.currentRoute;
if (currentRoute == RouterConts.homescreen) {
_selectedIndex = 0;
} else if (currentRoute == RouterConts.packageList) {
_selectedIndex = 1;
} else if (currentRoute == RouterConts.categorypage) {
_selectedIndex = 2;
} else if (currentRoute == RouterConts.history) {
_selectedIndex = 3;
} else if (currentRoute == RouterConts.profilemainscreen ||
currentRoute == RouterConts.editprofile ||
currentRoute == RouterConts.changepassword) {
_selectedIndex = 0; // No tab selected
}
}
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
);
}
void _toggleMenu() {
setState(() {
_showMenu = !_showMenu;
_showMenu
? _animationController.forward()
: _animationController.reverse();
});
}
// 🎯 NEW: Handle back button press
Future<bool> _onWillPop() async {
final currentRoute = Get.currentRoute;
// If menu is open, close it first
if (_showMenu) {
_toggleMenu();
return false; // Don't exit
}
// Handle back navigation based on current route
switch (currentRoute) {
case RouterConts.profilemainscreen:
case RouterConts.editprofile:
case RouterConts.changepassword:
// Navigate back to home when coming from profile screens
Get.offAllNamed(RouterConts.homescreen);
return false; // Don't use default back behavior
case RouterConts.packageList:
case RouterConts.categorypage:
case RouterConts.history:
// For other main tabs, go to home first
Get.offAllNamed(RouterConts.homescreen);
return false;
case RouterConts.homescreen:
// If already on home, allow default back behavior (exit app)
return true;
default:
// For any other screens, try to go back to home
try {
Get.back();
} catch (e) {
// If can't go back, navigate to home
Get.offAllNamed(RouterConts.homescreen);
}
return false;
}
}
void _onItemTapped(int index, BuildContext context) {
if (_selectedIndex == index) return;
switch (index) {
case 0:
Get.offAllNamed(RouterConts.homescreen);
break;
case 1:
Get.offAllNamed(RouterConts.packageList);
break;
case 2:
Get.offAllNamed(RouterConts.categorypage);
break;
case 3:
// Navigate to history with default tab (Service Booking)
Get.offAllNamed(
RouterConts.history,
arguments: {
'historyTab': 0, // Default to first tab
},
);
break;
}
}
void changeSelectedIndex(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
final isKeyboardOpen = MediaQuery.of(context).viewInsets.bottom > 0;
// 🎯 Wrap with WillPopScope to handle back button
return WillPopScope(
onWillPop: _onWillPop,
child: Scaffold(
resizeToAvoidBottomInset: false,
body: Stack(
children: [
InheritedIndexController(
changeIndex: changeSelectedIndex,
child: widget.child,
),
if (_showMenu && !isKeyboardOpen)
AnimatedOpacity(
opacity: 1.0,
duration: const Duration(milliseconds: 300),
child: GestureDetector(
onTap: _toggleMenu,
child: Container(
alignment: Alignment.center,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0),
child: Container(
color: Colors.black.withOpacity(0.2),
width: double.infinity,
height: double.infinity,
),
),
),
),
),
if (_showMenu && !isKeyboardOpen)
Positioned(
bottom: 60,
left: 0,
right: 0,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 110),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildMenuOption(
icon: Icons.store,
label: 'Vendor',
color: const Color(0xFF0066FF),
onTap: () async {
_toggleMenu();
try {
await ref.read(getvendorIdProvider.future);
Get.toNamed(RouterConts.vendorwelcome);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Failed to fetch Vendor ID'),
),
);
}
},
),
_buildMenuOption(
icon: Icons.person,
label: 'Profile',
color: const Color(0xFF0066FF),
onTap: () {
_toggleMenu();
Get.toNamed(RouterConts.profilemainscreen);
},
),
],
),
),
),
],
),
floatingActionButton: isKeyboardOpen
? null
: FloatingActionButton(
heroTag: "main_controller_fab",
onPressed: _toggleMenu,
shape: const CircleBorder(),
backgroundColor: const Color(0xFF0066FF),
child: AnimatedBuilder(
animation: _animationController,
builder: (context, child) {
return Transform.rotate(
angle: _animationController.value * 0.75 * math.pi,
child: Icon(
_animationController.value > 0.5
? Icons.close
: Icons.add,
color: Colors.white,
),
);
},
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
notchMargin: 8,
color: Colors.white,
elevation: 8,
child: SizedBox(
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_bottomNavItem(0, AppAssets.home),
_bottomNavItem(1, AppAssets.package),
const Expanded(child: SizedBox()),
_bottomNavItem(2, AppAssets.categories),
_bottomNavItem(3, AppAssets.history),
],
),
),
),
),
);
}
Widget _bottomNavItem(int index, String assetPath) {
return Expanded(
child: InkWell(
onTap: () => _onItemTapped(index, context),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
assetPath,
color: _selectedIndex == index
? const Color(0xFF0066FF)
: Colors.grey,
width: 26,
height: 29,
),
const SizedBox(height: 4),
Container(
height: 3,
width: 30,
decoration: BoxDecoration(
color: _selectedIndex == index
? const Color(0xFF0066FF)
: Colors.transparent,
borderRadius: BorderRadius.circular(2),
),
),
],
),
),
);
}
Widget _buildMenuOption({
required IconData icon,
required String label,
required Color color,
required VoidCallback onTap,
}) {
return ScaleTransition(
scale: CurvedAnimation(
parent: _animationController,
curve: Curves.easeOut,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
blurRadius: 3,
spreadRadius: 1,
offset: const Offset(0, 1),
),
],
),
child: IconButton(
icon: Icon(icon, color: Colors.white),
onPressed: onTap,
padding: EdgeInsets.zero,
),
),
const SizedBox(height: 5),
Text(
label,
style: const TextStyle(
color: Color(0xFF0066FF),
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
],
),
);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
}
class InheritedIndexController extends InheritedWidget {
final void Function(int) changeIndex;
const InheritedIndexController({
super.key,
required this.changeIndex,
required super.child,
});
static InheritedIndexController? of(BuildContext context) {
return context
.dependOnInheritedWidgetOfExactType<InheritedIndexController>();
}
@override
bool updateShouldNotify(InheritedIndexController oldWidget) {
return oldWidget.changeIndex != changeIndex;
}
}
@@ -0,0 +1,401 @@
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:get/get.dart';
class MostPopluarViewall extends ConsumerStatefulWidget {
const MostPopluarViewall({super.key});
@override
ConsumerState<MostPopluarViewall> createState() => _MostPopluarViewallState();
}
class _MostPopluarViewallState extends ConsumerState<MostPopluarViewall> {
bool _isValidCompleteUrl(String? url) {
if (url == null || url.isEmpty) return false;
try {
final uri = Uri.parse(url);
return uri.isAbsolute && uri.path.isNotEmpty;
} catch (e) {
return false;
}
}
@override
Widget build(BuildContext context) {
final popularServicesAsync = ref.watch(mostPopularProvider('0'));
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: SafeArea(
child: popularServicesAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(child: Text('Error: $error')),
data: (services) {
if (services.isEmpty) {
return const Padding(
padding: EdgeInsets.all(8.0),
child: Center(
child: Text("No services available for this category"),
),
);
}
return CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Stack(
alignment: Alignment.center,
children: [
Align(
alignment: Alignment.centerLeft,
child: IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () => Navigator.pop(context),
),
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Text(
"Most popular service",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
SliverPadding(
padding: const EdgeInsets.all(16.0),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: MediaQuery.of(context).size.width / 2,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
childAspectRatio: 0.74,
),
delegate: SliverChildBuilderDelegate((context, index) {
final service = services[index];
return LayoutBuilder(
builder: (context, constraints) {
return Container(
decoration: BoxDecoration(
color: const Color(0xFFFCFAFA),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: const Color(0xFFE3E3E3),
width: 1,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// Service image with CachedNetworkImage
ClipRRect(
borderRadius: const BorderRadius.vertical(
top: Radius.circular(19),
),
child: SizedBox(
height: constraints.maxWidth * 0.6,
width: double.infinity,
child:
_isValidCompleteUrl(
service.images1?.first,
)
? CachedNetworkImage(
imageUrl: service.images1!.first,
width: double.infinity,
height: constraints.maxWidth * 0.6,
fit: BoxFit.cover,
placeholder: (context, url) =>
Container(
color: Colors.grey[200],
child: const Center(
child:
CircularProgressIndicator(
strokeWidth: 2,
),
),
),
errorWidget:
(context, url, error) =>
Image.asset(
AppAssets.cleaning,
width: double.infinity,
height:
constraints.maxWidth *
0.6,
fit: BoxFit.cover,
),
)
: Image.asset(
AppAssets.cleaning,
width: double.infinity,
height: constraints.maxWidth * 0.6,
fit: BoxFit.cover,
),
),
),
// Rest of your widget code remains the same...
Align(
alignment: Alignment.centerRight,
child: Container(
height: 30,
width: 80,
transform: Matrix4.translationValues(
-10,
-15,
0,
),
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.white,
width: 1.5,
),
),
child: Center(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4,
),
child: Text(
'Rs.${service.amount ?? "N/A"}',
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w400,
fontSize: 16.86,
height: 1.0,
letterSpacing: 0.02,
color: Color(0xFFFCFAFA),
),
),
),
),
),
),
),
// Service details
Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(
8,
0,
8,
8,
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
service.serviceName ??
'Service',
style: const TextStyle(
fontFamily: 'Gilroy-Medium',
fontWeight: FontWeight.w700,
fontSize: 15.02,
height: 1.0,
letterSpacing: 0.0,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.star,
color: Colors.orange,
size: 18,
),
const SizedBox(width: 2),
Text(
service.averageReview
?.toString() ??
'0.0',
style: const TextStyle(
fontFamily: 'SF UI Display',
fontWeight: FontWeight.w600,
fontSize: 14,
height: 1.0,
letterSpacing: -0.5,
),
),
],
),
],
),
const SizedBox(height: 8),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(
4,
),
decoration: BoxDecoration(
border: Border.all(
color: AppColors.lightGrey,
),
color: Colors.white,
borderRadius:
BorderRadius.circular(12),
),
child: Row(
mainAxisSize:
MainAxisSize.min,
children: [
_isValidCompleteUrl(
service.profilePic1,
)
? CircleAvatar(
radius: 15,
backgroundImage:
CachedNetworkImageProvider(
service
.profilePic1!,
),
)
: const CircleAvatar(
radius: 15,
backgroundImage:
AssetImage(
AppAssets
.login,
),
),
const SizedBox(width: 4),
Flexible(
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
mainAxisSize:
MainAxisSize.min,
children: [
Text(
service.vendorName ??
'Vendor',
style: const TextStyle(
fontFamily:
'Gilroy-Medium',
fontWeight:
FontWeight
.w400,
fontSize: 11.75,
height: 1.0,
letterSpacing:
0.0,
color: Color(
0xFF353434,
),
),
maxLines: 1,
overflow:
TextOverflow
.ellipsis,
),
const SizedBox(
height: 2,
),
Text(
service.serviceName ??
'Service',
style: const TextStyle(
fontFamily:
'Gilroy-Regular',
fontWeight:
FontWeight
.w400,
fontSize: 11.75,
height: 1.0,
letterSpacing:
0.0,
color: Color(
0xFF717171,
),
),
maxLines: 1,
overflow:
TextOverflow
.ellipsis,
),
],
),
),
],
),
),
),
const SizedBox(width: 4),
GestureDetector(
onTap: () {
Get.toNamed(
RouterConts.detailserivce,
arguments: service.id,
);
},
child: Container(
padding: const EdgeInsets.all(
8,
),
decoration: BoxDecoration(
color: AppColors.primary,
borderRadius:
BorderRadius.circular(12),
),
child: const Icon(
Icons
.arrow_forward_ios_rounded,
size: 16,
color: Colors.white,
),
),
),
],
),
],
),
),
),
],
),
);
},
);
}, childCount: services.length),
),
),
],
);
},
),
),
);
}
}
@@ -0,0 +1,165 @@
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/model/notification_model.dart';
import 'package:bookmywages/view/auth/auth_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// Badge count state provider
final notificationCountProvider = StateProvider<int>((ref) => 0);
// Repository provider
final notificationRepositoryProvider = Provider(
(ref) => NotificationRepository(),
);
// Future provider with parameters
final notificationProvider = FutureProvider.family
.autoDispose<List<NotificationModel>, ({int type, String userId})>((
ref,
params,
) async {
final repo = ref.read(notificationRepositoryProvider);
return repo.fetchNotification(type: params.type, userId: params.userId);
});
class NotificationPage extends ConsumerWidget {
final int type;
final String id;
const NotificationPage({super.key, required this.type, required this.id});
@override
Widget build(BuildContext context, WidgetRef ref) {
final asyncNotif = ref.watch(
notificationProvider((type: type, userId: id)),
);
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
alignment: Alignment.center,
children: [
Align(
alignment: Alignment.centerLeft,
child: GestureDetector(
onTap: () => Navigator.pop(context),
child: const Icon(Icons.arrow_back_ios),
),
),
const Center(
child: Text(
"Notification",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
],
),
const SizedBox(height: 20),
// Notification list with badge update
asyncNotif.when(
loading: () =>
const Center(child: CircularProgressIndicator()),
error: (err, _) => Center(child: Text('Error: $err')),
data: (notifications) {
Future.microtask(() {
ref.read(notificationCountProvider.notifier).state =
notifications.length;
});
if (notifications.isEmpty) {
return const Center(child: Text("No Notification"));
}
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: notifications.length,
itemBuilder: (context, index) {
final item = notifications[index];
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 67.08,
height: 67.08,
margin: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 10,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(9.75),
border: Border.all(
color: const Color(0xFFB7B7B7),
width: 0.98,
),
),
child: _buildNotificationImage(item.images),
),
Expanded(
child: Text(
item.message,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 15,
height: 28 / 15,
letterSpacing: 0.15,
color: AppColors.thridprimary,
),
),
),
],
);
},
);
},
),
],
),
),
),
),
);
}
Widget _buildNotificationImage(List<String> images) {
if (images.isEmpty || images[0].isEmpty) {
return const Icon(Icons.notifications, size: 30, color: Colors.grey);
}
return ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.network(
images[0],
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return const Icon(Icons.broken_image, size: 30, color: Colors.grey);
},
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return const Center(
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
);
},
),
);
}
}
@@ -0,0 +1,370 @@
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/model/package_model.dart';
import 'package:bookmywages/model/plan_sucess_model.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:bookmywages/view/user_main_screens/main_contoller.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
class PackageScreen extends ConsumerStatefulWidget {
const PackageScreen({super.key});
@override
ConsumerState<PackageScreen> createState() => _PackageScreenState();
}
class _PackageScreenState extends ConsumerState<PackageScreen> {
bool _isMounted = false;
@override
void initState() {
super.initState();
_isMounted = true;
}
@override
void dispose() {
_isMounted = false;
super.dispose();
}
@override
Widget build(BuildContext context) {
final packageAsyncValue = ref.watch(pacakgeProvider);
final indexController = InheritedIndexController.of(context);
return PopScope(
onPopInvoked: (didPop) {
if (didPop) {
// Reset main controller index to 0 when going back
final indexController = InheritedIndexController.of(context);
indexController?.changeIndex(0);
}
},
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
icon: const Icon(
Icons.arrow_back_ios_new_sharp,
color: Colors.black,
),
onPressed: () => Navigator.pop(context),
),
centerTitle: true,
title: const Text(
"Subscription Plan",
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
),
),
extendBodyBehindAppBar: true,
body: LayoutBuilder(
builder: (context, constraints) {
final isSmallScreen = constraints.maxWidth < 360;
final cardWidth = constraints.maxWidth * 0.8;
final cardHeight = constraints.maxHeight * 0.4;
return Container(
height: double.infinity,
width: double.infinity,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(AppAssets.background),
fit: BoxFit.cover,
),
),
child: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: constraints.maxWidth * 0.04,
vertical: constraints.maxHeight * 0.02,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: constraints.maxHeight * 0.2,
),
child: Image.asset(
AppAssets.subscriptionimage,
fit: BoxFit.contain,
),
),
SizedBox(height: constraints.maxHeight * 0.02),
Text(
"Choose your right plan",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w400,
fontSize: isSmallScreen ? 24 : 32,
height: 1.0,
letterSpacing: 0.32,
color: Colors.black,
),
),
SizedBox(height: constraints.maxHeight * 0.01),
Padding(
padding: EdgeInsets.symmetric(
horizontal: constraints.maxWidth * 0.05,
),
child: Text(
"Make upgrade your plan and get more advantages of services",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: isSmallScreen ? 13 : 15,
height: 1.71,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
SizedBox(height: constraints.maxHeight * 0.02),
Expanded(
child: packageAsyncValue.when(
data: (packages) {
final filteredPackages = packages
.where((pkg) => pkg.type == 1)
.toList();
return Center(
child: SizedBox(
height: cardHeight,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: filteredPackages.length,
itemBuilder: (context, index) {
final PackageModel package =
filteredPackages[index];
return Container(
width: cardWidth,
margin: EdgeInsets.symmetric(
horizontal: constraints.maxWidth * 0.02,
),
constraints: BoxConstraints(
maxHeight: cardHeight,
),
decoration: BoxDecoration(
color: const Color(0xFF334E95),
borderRadius: BorderRadius.circular(30),
border: Border.all(
color: const Color(0xFF334E95),
width: 1,
),
boxShadow: const [
BoxShadow(
color: Color(0x40828282),
offset: Offset(0, 5),
blurRadius: 4,
),
],
),
child: _PackageCard(
package: package,
onSubscribe: () => _subscribeToPlan(
package,
indexController,
),
isSmallScreen: isSmallScreen,
),
);
},
),
),
);
},
loading: () =>
const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(
child: Text(
'Error loading packages: $error',
style: const TextStyle(color: Colors.red),
),
),
),
),
],
),
),
),
);
},
),
),
);
}
Future<void> _subscribeToPlan(
PackageModel package,
InheritedIndexController? indexController,
) async {
try {
final prefs = await SharedPreferences.getInstance();
final userId = prefs.getString('userId') ?? '';
final model = PlanSuccessModel(
userId: userId,
planId: package.id.toString(),
duration: package.duration,
type: package.type,
);
final result = await ref.read(planSuccessProvider(model).future);
if (_isMounted) {
if (result) {
await showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Success'),
content: const Text('Plan subscribed successfully!'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
indexController?.changeIndex(0);
ref.invalidate(expiredPlanProvider);
Get.toNamed(RouterConts.homescreen);
},
child: const Text('OK'),
),
],
),
);
} else {
Fluttertoast.showToast(
msg: 'Failed to subscribe to plan',
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
}
} catch (error) {
if (_isMounted) {
Fluttertoast.showToast(
msg: 'Error: ${error.toString()}',
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
}
}
}
class _PackageCard extends StatelessWidget {
final PackageModel package;
final VoidCallback onSubscribe;
final bool isSmallScreen;
const _PackageCard({
required this.package,
required this.onSubscribe,
required this.isSmallScreen,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(MediaQuery.of(context).size.width * 0.04),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
package.name,
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: isSmallScreen ? 16 : 18,
height: 1.0,
letterSpacing: 0.32,
color: Colors.white,
),
),
),
const SizedBox(height: 8),
_buildFeatureRow(package.description),
const SizedBox(height: 16),
_buildFeatureRow(_getFormattedDuration(package.duration)),
const SizedBox(height: 16),
_buildFeatureRow('${package.noOfService} book service'),
],
),
const Divider(color: Colors.white),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
package.price,
style: TextStyle(
fontSize: isSmallScreen ? 14 : 16,
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
GestureDetector(
onTap: onSubscribe,
child: Container(
width: 30,
height: 30,
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: const Icon(Icons.arrow_forward, color: Colors.black),
),
),
],
),
],
),
);
}
Widget _buildFeatureRow(String text) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const CircleAvatar(radius: 8, backgroundColor: Color(0xFFF9E369)),
const SizedBox(width: 6),
Expanded(
child: Text(
text,
style: TextStyle(
fontSize: isSmallScreen ? 12 : 14,
color: Colors.white,
),
),
),
],
);
}
String _getFormattedDuration(int duration) {
if (duration < 30) {
return '$duration days';
} else {
int months = duration ~/ 30;
return '$months month${months > 1 ? 's' : ''}';
}
}
}
@@ -0,0 +1,456 @@
import 'dart:io';
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/consts_widgets/comman_button.dart';
import 'package:bookmywages/consts_widgets/comman_textformfiled.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:bookmywages/viewmodel/consts_api.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_picker/image_picker.dart';
class EditProfile extends StatefulWidget {
const EditProfile({super.key});
@override
State<EditProfile> createState() => _EditProfileState();
}
class _EditProfileState extends State<EditProfile> {
File? _image;
final ImagePicker _picker = ImagePicker();
final TextEditingController nameController = TextEditingController();
final TextEditingController numberController = TextEditingController();
final TextEditingController emailController = TextEditingController();
final TextEditingController addressController = TextEditingController();
bool _isProfileDataInitialized = false;
Future<void> _pickImage() async {
final pickedFile = await _picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
setState(() {
_image = File(pickedFile.path);
});
}
}
// Helper method to validate and construct image URL
String? _getValidImageUrl(String? imageUrl) {
if (imageUrl == null || imageUrl.isEmpty) {
return null;
}
// Check if URL is complete (has a filename)
if (imageUrl.endsWith('/') || imageUrl.endsWith('/images/')) {
return null;
}
// Ensure URL is properly formatted
if (!imageUrl.startsWith('http')) {
return null;
}
return imageUrl;
}
// Helper widget for safe network image loading
Widget _buildNetworkImage(String? imageUrl, {BoxFit fit = BoxFit.cover}) {
final validUrl = _getValidImageUrl(imageUrl);
if (validUrl == null) {
return Image.asset(AppAssets.profile, fit: fit);
}
return Image.network(
validUrl,
fit: fit,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
},
errorBuilder: (context, error, stackTrace) {
print('Error loading image: $error');
return Image.asset(AppAssets.profile, fit: fit);
},
);
}
// Helper method for CircleAvatar image provider
ImageProvider _getAvatarImageProvider(String? imageUrl) {
if (_image != null) {
return FileImage(_image!);
}
final validUrl = _getValidImageUrl(imageUrl);
if (validUrl != null) {
return NetworkImage(validUrl);
}
return const AssetImage(AppAssets.profile);
}
final TextStyle gilroyTextStyle = const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 20,
height: 1.45,
letterSpacing: 0.01,
);
@override
void dispose() {
nameController.dispose();
numberController.dispose();
emailController.dispose();
addressController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: AppColors.secondprimary,
resizeToAvoidBottomInset: false,
body: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: constraints.maxHeight),
child: IntrinsicHeight(
child: Column(
children: [
Stack(
children: [
SizedBox(
width: double.infinity,
height: height * 0.4,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(
profilegetuserProvider,
);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
if (profile != null &&
!_isProfileDataInitialized) {
WidgetsBinding.instance
.addPostFrameCallback((_) {
setState(() {
nameController.text =
profile.name ?? '';
numberController.text =
profile.number ?? '';
emailController.text =
profile.email ?? '';
addressController.text =
profile.address ?? '';
_isProfileDataInitialized = true;
});
});
}
return _image == null
? _buildNetworkImage(
profile?.profilePic1,
)
: Image.file(
_image!,
fit: BoxFit.cover,
);
},
loading: () => const Center(
child: CircularProgressIndicator(),
),
error: (error, _) => Center(
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
const Icon(Icons.error, size: 50),
Text('Error loading profile: $error'),
],
),
),
);
},
),
),
Positioned(
bottom: 0,
child: CustomPaint(
size: Size(width, height * 0.4),
painter: RightToLeftFullWidthTrianglePainter(),
),
),
Positioned(
bottom: height * 0.03,
left: width / 2 - 170,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(
profilegetuserProvider,
);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
return CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
backgroundImage:
_getAvatarImageProvider(
profile?.profilePic1,
),
onBackgroundImageError:
(error, stackTrace) {
print(
'Avatar image error: $error',
);
},
),
);
},
loading: () => const CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
child: CircularProgressIndicator(),
),
),
error: (error, _) => const CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
backgroundImage: AssetImage(
AppAssets.menu,
),
),
),
);
},
),
),
Positioned(
bottom: height * 0.08,
left: width / 2 - 20,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(
profilegetuserProvider,
);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
if (profile == null) {
return Text(
'No Profile Data',
style: gilroyTextStyle,
);
}
return Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
profile.name ?? 'No Name',
style: gilroyTextStyle,
),
IconButton(
onPressed: _pickImage,
icon: const Icon(Icons.edit),
),
],
),
Row(
children: [
const Icon(
Icons.location_city,
size: 20,
),
const SizedBox(width: 4),
Text(
profile.address ??
'No address available',
style: const TextStyle(
fontSize: 12,
),
),
],
),
],
);
},
loading: () =>
const CircularProgressIndicator(),
error: (error, _) => Text(
'Error: $error',
style: gilroyTextStyle,
),
);
},
),
),
],
),
const SizedBox(height: 30),
Padding(
padding: EdgeInsets.symmetric(horizontal: width * 0.05),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Name", style: gilroyTextStyle),
const SizedBox(height: 15),
CommonTextFormField(
hintText: "Enter your name",
controller: nameController,
),
const SizedBox(height: 30),
Text("Mobile Number", style: gilroyTextStyle),
const SizedBox(height: 15),
CommonTextFormField(
hintText: "Enter your mobile number",
keyboardType: TextInputType.phone,
controller: numberController,
),
const SizedBox(height: 30),
Text("Address", style: gilroyTextStyle),
const SizedBox(height: 15),
CommonTextFormField(
hintText: "Enter your address",
controller: addressController,
),
const SizedBox(height: 30),
Text("Email", style: gilroyTextStyle),
const SizedBox(height: 15),
CommonTextFormField(
hintText: "Enter your email",
keyboardType: TextInputType.emailAddress,
controller: emailController,
),
const SizedBox(height: 30),
Center(
child: Consumer(
builder: (context, ref, _) {
return CommanButton(
width: width * 0.6,
text: "Save",
textStyle: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 23,
height: 1.0,
letterSpacing: 0.01,
color: AppColors.secondprimary,
),
onPressed: () async {
try {
final repo = ref.read(
profileupdateRepositoryProvider,
);
await repo.updateProfile(
url: ConstsApi.upadateprofile,
name: nameController.text,
number: numberController.text,
email: emailController.text,
address: addressController.text,
imageFile: _image,
);
if (mounted) {
Fluttertoast.showToast(
msg: "Profile updated successfully",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
);
ref.refresh(profilegetuserProvider);
Future.delayed(
const Duration(milliseconds: 1500),
() {
if (mounted) {
Navigator.of(context).pop();
}
},
);
}
} catch (e) {
if (mounted) {
Fluttertoast.showToast(
msg: "Error updating profile: $e",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
}
},
);
},
),
),
const SizedBox(height: 30),
],
),
),
],
),
),
),
);
},
),
),
);
}
}
class RightToLeftFullWidthTrianglePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = Colors.white;
final path = Path();
path.moveTo(size.width, 0);
path.lineTo(size.width, size.height);
path.lineTo(0, size.height);
path.close();
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
@@ -0,0 +1,421 @@
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
class ProfileChangepass extends ConsumerStatefulWidget {
const ProfileChangepass({super.key});
@override
ConsumerState<ProfileChangepass> createState() => _ProfileChangepassState();
}
class _ProfileChangepassState extends ConsumerState<ProfileChangepass> {
final TextEditingController _newPasswordController = TextEditingController();
final TextEditingController _confirmPasswordController =
TextEditingController();
final _formKey = GlobalKey<FormState>();
bool _obscureNewPassword = true;
bool _obscureConfirmPassword = true;
String? _newPasswordError;
String? _confirmPasswordError;
@override
void dispose() {
_newPasswordController.dispose();
_confirmPasswordController.dispose();
super.dispose();
}
Future<void> _submitForm() async {
FocusScope.of(context).unfocus();
// Reset errors
setState(() {
_newPasswordError = null;
_confirmPasswordError = null;
});
if (_formKey.currentState!.validate()) {
try {
final success = await ref.read(
changepasswordProvider(_newPasswordController.text).future,
);
if (success && mounted) {
Fluttertoast.showToast(
msg: "Password changed successfully",
backgroundColor: Colors.green,
textColor: Colors.white,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
Navigator.pop(context);
} else {
Fluttertoast.showToast(
msg: "Failed to change password",
backgroundColor: Colors.red,
textColor: Colors.white,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
}
} catch (e) {
if (mounted) {
Fluttertoast.showToast(
msg: "Error: ${e.toString()}",
backgroundColor: Colors.red,
textColor: Colors.white,
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
);
}
}
}
}
String? _validateNewPassword(String? value) {
if (value == null || value.isEmpty) {
setState(() {
_newPasswordError = "Please enter a password";
});
return "";
}
if (value.length < 6) {
// Fixed: was 4, should be 6 as per error message
setState(() {
_newPasswordError = "Password must be at least 6 characters";
});
return "";
}
setState(() {
_newPasswordError = null;
});
return null;
}
String? _validateConfirmPassword(String? value) {
if (value == null || value.isEmpty) {
setState(() {
_confirmPasswordError = "Please confirm your password";
});
return "";
}
if (value != _newPasswordController.text) {
setState(() {
_confirmPasswordError = "Passwords don't match";
});
return "";
}
setState(() {
_confirmPasswordError = null;
});
return null;
}
@override
Widget build(BuildContext context) {
final keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
final isKeyboardVisible = keyboardHeight > 0;
final screenHeight = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: AppColors.secondprimary,
resizeToAvoidBottomInset: false, // Keep false to prevent white space
body: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Container(
height: screenHeight, // Fixed height
color: AppColors.secondprimary,
child: SafeArea(
child: Column(
children: [
// Header with back button
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
GestureDetector(
onTap: () => Navigator.pop(context),
child: const Icon(
Icons.arrow_back_ios_new,
size: 20,
color: Colors.black,
),
),
const Expanded(
child: Center(
child: Text(
'Change Password',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
),
),
const SizedBox(width: 20),
],
),
),
// Scrollable content with proper height calculation
Expanded(
child: SingleChildScrollView(
physics: const ClampingScrollPhysics(),
padding: EdgeInsets.only(
left: 16.0,
right: 16.0,
bottom: isKeyboardVisible ? keyboardHeight + 16 : 16.0,
),
child: Column(
children: [
// Show smaller image when keyboard is visible, normal size when not
if (!isKeyboardVisible) ...[
Image.asset(
AppAssets.changepass,
width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.height * 0.3,
fit: BoxFit.contain,
),
const SizedBox(height: 16),
] else ...[
// Smaller image when keyboard is open
Image.asset(
AppAssets.changepass,
width: MediaQuery.of(context).size.width * 0.4,
height: screenHeight * 0.12, // Even smaller height
fit: BoxFit.contain,
),
const SizedBox(height: 8),
],
// Form to change password
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Create Password",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontSize: 20,
fontWeight: FontWeight.w700,
color: Colors.black87,
height: 18.68 / 20,
letterSpacing: 0.5,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 53,
decoration: BoxDecoration(
color: const Color(0xFFFDFFFF),
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color(0xFF8C8A8A),
),
),
child: TextFormField(
controller: _newPasswordController,
obscureText: _obscureNewPassword,
decoration: InputDecoration(
hintText: "Enter new password",
contentPadding:
const EdgeInsets.symmetric(
horizontal: 16,
vertical: 10,
),
border: InputBorder.none,
hintStyle: const TextStyle(
fontFamily: 'Martel',
fontWeight: FontWeight.w700,
fontSize: 14,
height: 29 / 14,
letterSpacing: -0.5,
color: Color(0xFF757576),
),
suffixIcon: IconButton(
icon: Icon(
_obscureNewPassword
? Icons.visibility_off
: Icons.visibility,
color: Colors.grey,
),
onPressed: () {
setState(() {
_obscureNewPassword =
!_obscureNewPassword;
});
},
),
),
validator: _validateNewPassword,
),
),
SizedBox(
height: _newPasswordError != null ? 28 : 0,
child:
_newPasswordError != null
? Padding(
padding: const EdgeInsets.only(
top: 8.0,
left: 16.0,
),
child: Text(
_newPasswordError!,
style: const TextStyle(
color: Colors.red,
fontSize: 12,
),
),
)
: null,
),
],
),
const SizedBox(height: 20),
const Text(
"Confirm Password",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontSize: 20,
fontWeight: FontWeight.w700,
color: Colors.black87,
height: 18.68 / 20,
letterSpacing: 0.5,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 53,
decoration: BoxDecoration(
color: const Color(0xFFFDFFFF),
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color(0xFF8C8A8A),
),
),
child: TextFormField(
controller: _confirmPasswordController,
obscureText: _obscureConfirmPassword,
decoration: InputDecoration(
hintText: "Confirm your password",
contentPadding:
const EdgeInsets.symmetric(
horizontal: 16,
vertical: 10,
),
border: InputBorder.none,
hintStyle: const TextStyle(
fontFamily: 'Martel',
fontWeight: FontWeight.w700,
fontSize: 14,
height: 29 / 14,
letterSpacing: -0.5,
color: Color(0xFF757576),
),
suffixIcon: IconButton(
icon: Icon(
_obscureConfirmPassword
? Icons.visibility_off
: Icons.visibility,
color: Colors.grey,
),
onPressed: () {
setState(() {
_obscureConfirmPassword =
!_obscureConfirmPassword;
});
},
),
),
validator: _validateConfirmPassword,
),
),
SizedBox(
height:
_confirmPasswordError != null ? 28 : 0,
child:
_confirmPasswordError != null
? Padding(
padding: const EdgeInsets.only(
top: 8.0,
left: 16.0,
),
child: Text(
_confirmPasswordError!,
style: const TextStyle(
color: Colors.red,
fontSize: 12,
),
),
)
: null,
),
],
),
const SizedBox(height: 20),
Center(
child: SizedBox(
width: 299,
height: 61.71,
child: ElevatedButton(
onPressed: _submitForm,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0066FF),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
34.77,
),
),
elevation: 0,
),
child: const Text(
"Save",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 28.76,
height: 1.0,
letterSpacing: 0.01,
),
),
),
),
),
// Add some bottom spacing
SizedBox(height: isKeyboardVisible ? 16 : 30),
],
),
),
],
),
),
),
],
),
),
),
),
);
}
}
@@ -0,0 +1,668 @@
import 'dart:ui';
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:bookmywages/viewmodel/consts_api.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ProfileMainPage extends StatefulWidget {
const ProfileMainPage({super.key});
@override
State<ProfileMainPage> createState() => _ProfileMainPageState();
}
class _ProfileMainPageState extends State<ProfileMainPage> {
File? _image;
final ImagePicker _picker = ImagePicker();
bool _isProfileDataInitialized = false;
bool _isUploading = false;
// Modified _pickImage method with automatic API upload using existing repository
Future<void> _pickImage() async {
try {
final pickedFile = await _picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
setState(() {
_image = File(pickedFile.path);
_isUploading = true;
});
// Automatically upload to API using existing repository
await _uploadImageToAPI(File(pickedFile.path));
}
} catch (e) {
print('Error picking image: $e');
_showErrorToast('Failed to pick image: $e');
}
}
// Upload image using existing ProfileupdateRepository
Future<void> _uploadImageToAPI(File imageFile) async {
try {
// Get current profile data
final profileData = ProviderScope.containerOf(
context,
).read(profilegetuserProvider);
await profileData.when(
data: (profiles) async {
if (profiles.isNotEmpty) {
final profile = profiles[0];
// Get the repository
final repository = ProviderScope.containerOf(
context,
).read(profileupdateRepositoryProvider);
// Update profile with new image and existing data
await repository.updateProfile(
url: ConstsApi.upadateprofile, // Use your existing API constant
name: profile.name,
number: profile.number,
email: profile.email,
address: profile.address ?? '',
imageFile: imageFile,
);
// Refresh profile data to get updated image URL
ProviderScope.containerOf(context).refresh(profilegetuserProvider);
ProviderScope.containerOf(
context,
).refresh(profileupdateuserProvider);
_showSuccessToast('Profile picture updated successfully!');
// Clear local image since it's now uploaded
setState(() {
_image = null;
});
} else {
_showErrorToast('No profile data available');
setState(() {
_image = null;
});
}
},
loading: () async {
_showErrorToast('Profile data is still loading');
setState(() {
_image = null;
});
},
error: (error, _) async {
_showErrorToast('Error getting profile data: $error');
setState(() {
_image = null;
});
},
);
} catch (e) {
print('Error uploading image: $e');
_showErrorToast('Upload failed: $e');
setState(() {
_image = null;
});
} finally {
setState(() {
_isUploading = false;
});
}
}
// Helper methods for showing toasts
void _showSuccessToast(String message) {
Fluttertoast.showToast(
msg: message,
backgroundColor: Colors.green,
textColor: Colors.white,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
}
void _showErrorToast(String message) {
Fluttertoast.showToast(
msg: message,
backgroundColor: Colors.red,
textColor: Colors.white,
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
);
}
// Helper method to validate and construct image URL
String? _getValidImageUrl(String? imageUrl) {
if (imageUrl == null || imageUrl.isEmpty) {
return null;
}
// Check if URL is complete (has a filename)
if (imageUrl.endsWith('/') || imageUrl.endsWith('/images/')) {
return null;
}
// Ensure URL is properly formatted
if (!imageUrl.startsWith('http')) {
return null;
}
return imageUrl;
}
// Helper widget for safe network image loading
Widget _buildNetworkImage(String? imageUrl, {BoxFit fit = BoxFit.cover}) {
final validUrl = _getValidImageUrl(imageUrl);
if (validUrl == null) {
return Image.asset(AppAssets.profile, fit: fit);
}
return Image.network(
validUrl,
fit: fit,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
},
errorBuilder: (context, error, stackTrace) {
print('Error loading image: $error');
return Image.asset(AppAssets.profile, fit: fit);
},
);
}
// Helper method for CircleAvatar image provider
ImageProvider _getAvatarImageProvider(String? imageUrl) {
if (_image != null) {
return FileImage(_image!);
}
final validUrl = _getValidImageUrl(imageUrl);
if (validUrl != null) {
return NetworkImage(validUrl);
}
return const AssetImage(AppAssets.profile);
}
final TextStyle gilroyTextStyle = const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 20,
height: 1.45,
letterSpacing: 0.01,
);
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: SafeArea(
child: Column(
children: [
Flexible(
flex: 1,
child: Stack(
children: [
SizedBox(
width: double.infinity,
height: height * 0.4,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(profilegetuserProvider);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
if (profile != null && !_isProfileDataInitialized) {
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
profile.address ?? '';
_isProfileDataInitialized = true;
});
});
}
return _image == null
? _buildNetworkImage(profile?.profilePic1)
: Image.file(_image!, fit: BoxFit.cover);
},
loading: () =>
const Center(child: CircularProgressIndicator()),
error: (error, _) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error, size: 50),
Text('Error loading profile: $error'),
],
),
),
);
},
),
),
Positioned(
bottom: 0,
child: CustomPaint(
size: Size(width, height * 0.4),
painter: RightToLeftFullWidthTrianglePainter(),
),
),
Positioned(
bottom: height * 0.03,
left: width / 2 - 170,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(profilegetuserProvider);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
return Stack(
alignment: Alignment.center,
children: [
CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
backgroundImage: _getAvatarImageProvider(
profile?.profilePic1,
),
onBackgroundImageError:
(error, stackTrace) {
print('Avatar image error: $error');
},
),
),
// Show upload progress indicator
if (_isUploading)
Container(
width: 136,
height: 136,
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
shape: BoxShape.circle,
),
child: const Center(
child: CircularProgressIndicator(
color: Colors.white,
),
),
),
],
);
},
loading: () => const CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
child: CircularProgressIndicator(),
),
),
error: (error, _) => const CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
backgroundImage: AssetImage(AppAssets.menu),
),
),
);
},
),
),
Positioned(
bottom: height * 0.08,
left: width / 2 - 20,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(profilegetuserProvider);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
if (profile == null) {
return Text(
'No Profile Data',
style: gilroyTextStyle,
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
profile.name ?? 'No Name',
style: gilroyTextStyle,
),
IconButton(
onPressed: _isUploading
? null
: _pickImage,
icon: _isUploading
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
),
)
: const Icon(Icons.edit),
),
],
),
Row(
children: [
const Icon(Icons.location_city, size: 20),
const SizedBox(width: 4),
Text(
profile.address ?? 'No address available',
style: const TextStyle(fontSize: 12),
),
],
),
],
);
},
loading: () => const CircularProgressIndicator(),
error: (error, _) =>
Text('Error: $error', style: gilroyTextStyle),
);
},
),
),
],
),
),
const SizedBox(height: 30),
Expanded(
flex: 1,
child: ListView(
shrinkWrap: false,
physics: const NeverScrollableScrollPhysics(),
children: [
_buildMenuItem(Icons.person, 'My Profile'),
_buildMenuItem(Icons.lock, 'Change Password'),
_buildMenuItem(Icons.notifications, 'Notification'),
_buildMenuItem(Icons.description, 'Terms and Conditions'),
_buildMenuItem(Icons.logout, 'Sign out'),
],
),
),
],
),
),
);
}
Widget _buildMenuItem(IconData icon, String title) {
return ListTile(
leading: Icon(
icon,
size: 23.000513076782227,
color: const Color(0xFF3E3E3F),
),
title: Text(
title,
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 18,
height: 1.0,
letterSpacing: 0.2,
color: Color(0xFF3E3E3F),
),
),
trailing: const Icon(Icons.arrow_forward_ios_rounded),
onTap: () async {
try {
if (title == 'My Profile') {
await Get.toNamed(RouterConts.editprofile);
} else if (title == 'Change Password') {
await Get.toNamed(RouterConts.changepassword);
} else if (title == 'Sign out') {
_showSignOutDialog();
} else if (title == 'Terms and Conditions') {
_showTermsAndConditionsDialog(); // Removed ref parameter
}
} catch (e) {
print('Navigation error: $e');
if (mounted) {
Fluttertoast.showToast(
msg: 'Navigation error: $e',
backgroundColor: Colors.red,
textColor: Colors.white,
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
);
}
}
},
);
}
void _showSignOutDialog() {
if (!mounted) return;
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Sign Out'),
content: const Text('Are you sure you want to sign out?'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () async {
Navigator.of(context).pop();
final prefs = await SharedPreferences.getInstance();
await prefs.remove('userId');
await prefs.remove('vendor_id');
await prefs.remove('data');
if (context.mounted) {
// context.go(
// RouterConts.loginpage,
// ); // or use pushReplacement if needed
}
},
child: const Text('Sign Out'),
),
],
);
},
);
}
void _showTermsAndConditionsDialog() {
// Removed WidgetRef ref parameter
if (!mounted) return;
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
child: Dialog(
backgroundColor: Colors.transparent,
insetPadding: const EdgeInsets.all(20),
child: Center(
child: Consumer(
builder: (context, ref, _) {
final termsAsync = ref.watch(termsAndConditionsProvider);
return termsAsync.when(
data: (terms) => Container(
width: 389,
height: 547,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: const Color(0xFF959595),
width: 1,
),
),
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Center(
child: Text(
"Terms & Condition",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
const SizedBox(height: 12),
Expanded(
child: ScrollbarTheme(
data: ScrollbarThemeData(
thumbColor: WidgetStateProperty.all(
AppColors.primary,
),
trackColor: WidgetStateProperty.all(
Colors.transparent,
),
trackBorderColor: WidgetStateProperty.all(
Colors.transparent,
),
thickness: WidgetStateProperty.all(13),
radius: const Radius.circular(19),
thumbVisibility: WidgetStateProperty.all(true),
),
child: Scrollbar(
thumbVisibility: true,
interactive: true,
thickness: 13,
radius: const Radius.circular(19),
child: ListView(
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
terms.data,
style: const TextStyle(
color: Colors.black,
),
),
const SizedBox(height: 20),
Center(
child: SizedBox(
width: 228,
height: 51.82,
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(
0xFF0066FF,
),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
22.95,
),
),
),
child: const Text(
"OK",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 18.87,
height: 23.59 / 18.87,
letterSpacing: -0.59,
color: Colors.white,
),
),
),
),
),
],
),
],
),
),
),
),
],
),
),
loading: () =>
const Center(child: CircularProgressIndicator()),
error: (e, _) => Container(
padding: const EdgeInsets.all(16),
child: Text(
"Error: ${e.toString()}",
style: const TextStyle(color: Colors.red),
),
),
);
},
),
),
),
);
},
);
}
}
class RightToLeftFullWidthTrianglePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = Colors.white;
final path = Path();
path.moveTo(size.width, 0); // top right corner
path.lineTo(size.width, size.height); // bottom right corner
path.lineTo(0, size.height); // bottom left (tip)
path.close();
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
@@ -0,0 +1,51 @@
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:flutter/material.dart';
class SucessfullScreen extends StatefulWidget {
const SucessfullScreen({super.key});
@override
State<SucessfullScreen> createState() => _SucessfullScreenState();
}
class _SucessfullScreenState extends State<SucessfullScreen> {
@override
void initState() {
super.initState();
// Wait 3 seconds then go back
Future.delayed(const Duration(seconds: 3), () {
if (mounted) {
Navigator.pop(context); // This goes back to the previous screen
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(AppAssets.sucess, width: 300, height: 300),
Text(
"Successful your Booking",
style: TextStyle(
fontFamily: 'Mogra',
fontWeight: FontWeight.w600,
fontSize: 22,
height: 57.82 / 25.46, // line-height ratio
letterSpacing: 1.0,
color: Color(0xFF0C2C5C),
),
),
],
),
),
);
}
}