Initial commit of Flutter project
This commit is contained in:
@@ -1,16 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:glowwheels/helpers/shopid_helper.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../provider/serviceboy_provider.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
class AddServiceBoyScreen extends StatelessWidget {
|
||||
import '../provider/serviceboy_provider.dart';
|
||||
import '../provider/shop_provider.dart';
|
||||
|
||||
class AddServiceBoyScreen extends StatefulWidget {
|
||||
@override
|
||||
_AddServiceBoyScreenState createState() => _AddServiceBoyScreenState();
|
||||
}
|
||||
|
||||
class _AddServiceBoyScreenState extends State<AddServiceBoyScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final TextEditingController nameController = TextEditingController();
|
||||
final TextEditingController phoneController = TextEditingController();
|
||||
|
||||
bool isLoading = false;
|
||||
late String shopId='';
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
shopId = getShopId(context)!;
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final serviceBoyProvider = Provider.of<ServiceBoyProvider>(context, listen: false);
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFF9FAF4), // light background as per screenshot
|
||||
backgroundColor: Color(0xFFF9FAF4),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
@@ -20,12 +37,12 @@ class AddServiceBoyScreen extends StatelessWidget {
|
||||
),
|
||||
title: Text(
|
||||
'Add Service boy',
|
||||
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,
|
||||
),
|
||||
),
|
||||
//centerTitle: true,
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -33,15 +50,15 @@ class AddServiceBoyScreen extends StatelessWidget {
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: 30,),
|
||||
SizedBox(height: 30),
|
||||
TextFormField(
|
||||
controller: nameController,
|
||||
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),
|
||||
@@ -54,9 +71,10 @@ class AddServiceBoyScreen extends StatelessWidget {
|
||||
keyboardType: TextInputType.phone,
|
||||
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),
|
||||
@@ -67,28 +85,69 @@ class AddServiceBoyScreen extends StatelessWidget {
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
/* if (_formKey.currentState!.validate()) {
|
||||
Provider.of<ServiceBoyProvider>(context, listen: false).addServiceBoy(
|
||||
nameController.text,
|
||||
phoneController.text,
|
||||
);
|
||||
Navigator.pop(context);
|
||||
}*/
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
if (shopId == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Shop ID is missing')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
await serviceBoyProvider.addServiceBoy(
|
||||
shopId,
|
||||
nameController.text.trim(),
|
||||
phoneController.text.trim(),
|
||||
);
|
||||
|
||||
// After successful addition, navigate back
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Service boy added successfully!')),
|
||||
);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to add service boy')),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Color(0xFF000B8C), // dark blue
|
||||
backgroundColor: Color(0xFF000B8C),
|
||||
padding: EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
),
|
||||
child: Text('Submit', style:
|
||||
|
||||
GoogleFonts.inter(
|
||||
fontSize: 18,color: Colors.white
|
||||
,fontWeight: FontWeight.w600
|
||||
child: isLoading
|
||||
? SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 2.5,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
'Submit',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 18,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user