Initial commit of Flutter project

This commit is contained in:
2025-09-19 11:30:38 +05:30
parent 1f0ec17edc
commit 4a9ae0a3b3
28 changed files with 2033 additions and 594 deletions

View File

@@ -1,14 +1,28 @@
import 'package:flutter/material.dart';
import 'package:glowwheels/helpers/shopid_helper.dart';
import 'package:provider/provider.dart';
import '../models/serviceboy_model.dart';
import '../provider/serviceboy_provider.dart';
import 'package:google_fonts/google_fonts.dart';
class AssignServiceBoyDialog extends StatelessWidget {
final List<ServiceBoy> serviceBoys;
import 'package:glowwheels/models/serviceboy_model.dart';
import '../provider/serviceboy_provider.dart';
import '../provider/order_provider.dart';
const AssignServiceBoyDialog({super.key, required this.serviceBoys});
class AssignServiceBoyDialog extends StatefulWidget {
final List<ServiceBoy> serviceBoys;
final String orderId;
const AssignServiceBoyDialog({
Key? key,
required this.serviceBoys,
required this.orderId,
}) : super(key: key);
@override
State<AssignServiceBoyDialog> createState() => _AssignServiceBoyDialogState();
}
class _AssignServiceBoyDialogState extends State<AssignServiceBoyDialog> {
bool _isLoading = false;
@override
Widget build(BuildContext context) {
@@ -19,14 +33,17 @@ class AssignServiceBoyDialog extends StatelessWidget {
return AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
title: const Text("Select Service Boy", style: TextStyle(fontWeight: FontWeight.bold)),
title: const Text(
"Select Service Boy",
style: TextStyle(fontWeight: FontWeight.bold),
),
content: SizedBox(
height: 200,
width: double.maxFinite,
child: ListView.builder(
itemCount: serviceBoys.length,
itemCount: widget.serviceBoys.length,
itemBuilder: (context, index) {
final boy = serviceBoys[index];
final boy = widget.serviceBoys[index];
final isSelected = assignProvider.selectedBoy == boy;
return GestureDetector(
@@ -35,8 +52,9 @@ class AssignServiceBoyDialog extends StatelessWidget {
padding: const EdgeInsets.all(12),
margin: const EdgeInsets.symmetric(vertical: 4),
decoration: BoxDecoration(
color: isSelected ? Color.fromRGBO(0, 80, 170, 1) : Colors.transparent,
color: isSelected ? const Color.fromRGBO(0, 80, 170, 1) : Colors.transparent,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.grey.shade300),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -64,28 +82,80 @@ class AssignServiceBoyDialog extends StatelessWidget {
),
actions: [
TextButton(
child: Text("CANCEL",style: GoogleFonts.poppins(
fontSize: 14,color: Color.fromRGBO(25, 25, 112, 1)
,fontWeight: FontWeight.w400
),),
onPressed: () {
Navigator.of(context).pop(); // return null
},
onPressed: () => Navigator.of(context).pop(),
child: Text(
"CANCEL",
style: GoogleFonts.poppins(
fontSize: 14,
color: const Color.fromRGBO(25, 25, 112, 1),
fontWeight: FontWeight.w400,
),
),
),
ElevatedButton(
onPressed: assignProvider.selectedBoy != null
? () {
Navigator.of(context).pop(assignProvider.selectedBoy);
onPressed: assignProvider.selectedBoy != null && !_isLoading
? () async {
setState(() {
_isLoading = true;
});
final selectedBoy = assignProvider.selectedBoy!;
final orderProvider = Provider.of<OrdersProvider>(context, listen: false);
final shopId = getShopId(context);
try {
await orderProvider.assignServiceBoyToOrder(
orderId: widget.orderId,
serviceBoyId: selectedBoy.id,
shopId: shopId!,
);
if (mounted) {
Navigator.of(context, rootNavigator: true).pop(
selectedBoy
); // ✅ return selected boy
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Service boy assigned successfully!')),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to assign service boy: $e')),
);
}
} finally {
if (mounted) {
setState(() {
_isLoading = false;
});
}
}
}
: null,
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF1B1464),
backgroundColor: const Color(0xFF1B1464),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
),
child: Text("Assign",style: GoogleFonts.inter(
fontSize: 12,color: Colors.white
,fontWeight: FontWeight.w500
),),
child: _isLoading
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: Text(
"Assign",
style: GoogleFonts.inter(
fontSize: 12,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
],
);
@@ -94,4 +164,3 @@ class AssignServiceBoyDialog extends StatelessWidget {
);
}
}