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,38 +1,81 @@
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 EditServiceBoyScreen extends StatelessWidget {
class EditServiceBoyScreen extends StatefulWidget {
final ServiceBoy serviceBoy;
EditServiceBoyScreen({required this.serviceBoy});
@override
_EditServiceBoyScreenState createState() => _EditServiceBoyScreenState();
}
class _EditServiceBoyScreenState extends State<EditServiceBoyScreen> {
final _formKey = GlobalKey<FormState>();
late final TextEditingController nameController =
TextEditingController(text: serviceBoy.name);
late final TextEditingController phoneController =
TextEditingController(text: serviceBoy.phone);
late final TextEditingController nameController;
late final TextEditingController phoneController;
bool isLoading = false;
@override
void initState() {
super.initState();
nameController = TextEditingController(text: widget.serviceBoy.name);
phoneController = TextEditingController(text: widget.serviceBoy.phone);
}
@override
void dispose() {
nameController.dispose();
phoneController.dispose();
super.dispose();
}
void _saveDetails(BuildContext context) async {
final name = nameController.text.trim();
final phone = phoneController.text.trim();
// Validation: at least one field must be non-empty and different
if (name.isEmpty && phone.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Please edit at least one field')),
);
return;
}
final shopId = getShopId(context)!;
setState(() => isLoading = true);
await Provider.of<ServiceBoyProvider>(context, listen: false)
.editServiceBoy(widget.serviceBoy.id, name, phone, shopId);
setState(() => isLoading = false);
Navigator.pop(context); // back to previous screen
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF9FAF4), // light background
backgroundColor: const Color(0xFFF9FAF4),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () => Navigator.pop(context),
),
title: Text(
title: Text(
'Edit Service boy Details',
style: GoogleFonts.nunito(
fontSize: 18,color: Color.fromRGBO(26, 26, 26, 1)
,fontWeight: FontWeight.w500
)
style: GoogleFonts.nunito(
fontSize: 18,
color: Color.fromRGBO(26, 26, 26, 1),
fontWeight: FontWeight.w500),
),
),
body: Padding(
padding: const EdgeInsets.all(16),
@@ -40,50 +83,40 @@ class EditServiceBoyScreen extends StatelessWidget {
key: _formKey,
child: Column(
children: [
SizedBox(height: 30,),
SizedBox(height: 30),
TextFormField(
controller: nameController,
decoration: InputDecoration(
decoration: InputDecoration(
hintText: 'Name',
hintStyle: GoogleFonts.nunito(
fontSize: 14,color: Color.fromRGBO(26, 26, 26, 1)
,fontWeight: FontWeight.w400
),
hintStyle: GoogleFonts.nunito(
fontSize: 14,
color: Color.fromRGBO(26, 26, 26, 1),
fontWeight: FontWeight.w400),
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 14),
contentPadding:
EdgeInsets.symmetric(horizontal: 12, vertical: 14),
),
validator: (value) => value!.isEmpty ? 'Enter name' : null,
),
const SizedBox(height: 25),
SizedBox(height: 25),
TextFormField(
controller: phoneController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
decoration: InputDecoration(
hintText: 'Mobile Number',
hintStyle: GoogleFonts.nunito(
fontSize: 14,color: Color.fromRGBO(26, 26, 26, 1)
,fontWeight: FontWeight.w400
),
hintStyle: GoogleFonts.nunito(
fontSize: 14,
color: Color.fromRGBO(26, 26, 26, 1),
fontWeight: FontWeight.w400),
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 14),
contentPadding:
EdgeInsets.symmetric(horizontal: 12, vertical: 14),
),
validator: (value) => value!.isEmpty ? 'Enter phone number' : null,
),
const Spacer(),
Spacer(),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
/* if (_formKey.currentState!.validate()) {
Provider.of<ServiceBoyProvider>(context, listen: false)
.editServiceBoy(
serviceBoy.id,
nameController.text,
phoneController.text,
);
Navigator.pop(context);
}*/
},
onPressed: isLoading ? null : () => _saveDetails(context),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF000B8C),
padding: const EdgeInsets.symmetric(vertical: 14),
@@ -91,10 +124,20 @@ class EditServiceBoyScreen extends StatelessWidget {
borderRadius: BorderRadius.circular(6),
),
),
child: Text('Save', style:GoogleFonts.inter(
fontSize: 18,color: Colors.white
,fontWeight: FontWeight.w600
)),
child: isLoading
? SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
)
: Text('Save',
style: GoogleFonts.inter(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.w600)),
),
),
],