Skip to content

Instantly share code, notes, and snippets.

@a7me63azzab
Created July 28, 2019 21:43
Show Gist options
  • Save a7me63azzab/28f6930288b9e4261c4d4f994ad20718 to your computer and use it in GitHub Desktop.
Save a7me63azzab/28f6930288b9e4261c4d4f994ad20718 to your computer and use it in GitHub Desktop.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wedding/src/helpers/color.dart';
import 'package:wedding/src/models/category_model.dart';
import 'package:wedding/src/scoped_models/main.dart';
import 'package:wedding/utils/dialogs.dart';
class ServiceProviderRegistrationPage extends StatefulWidget {
final MainModel model;
ServiceProviderRegistrationPage(this.model);
@override
State<StatefulWidget> createState() {
return ServiceProviderRegistrationPageState();
}
}
class ServiceProviderRegistrationPageState
extends State<ServiceProviderRegistrationPage> {
GlobalKey<FormState> _formKey = GlobalKey<FormState>();
GlobalKey<ScaffoldState> _scafoldKey = GlobalKey<ScaffoldState>();
bool _isLoading = false;
List<Category> _categories = <Category>[];
TextEditingController _categoryController = TextEditingController();
void showInSnackBar(String value) {
_scafoldKey.currentState
.showSnackBar(new SnackBar(content: new Text(value)));
}
@override
void initState() {
super.initState();
widget.model.fetchAllCategories().then((result) {
if (result != null && result.status == 'ok') {
setState(() {
_categories = result.categories;
});
} else {
print("eeeeeeeeeee ${result?.message ?? "000000000"}");
}
});
}
Map<String, dynamic> _formData = {
"name": null,
"category_id": null,
"email": null,
"phone": null,
"shop_name": null,
"shop_address": null,
"password": "hh",
"crn": null
};
void _openCitiesBottomSheet(BuildContext context) {
showCupertinoModalPopup(
context: context,
builder: (BuildContext context) {
return Container(
height: (MediaQuery.of(context).size.height / 2) + 100,
child: CupertinoActionSheet(
cancelButton: CupertinoButton(
child: Text(
"إلغاء",
style: TextStyle(
fontFamily: "Neo sans",
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(
getColorHexFromStr("#b83b56"),
)),
),
onPressed: () => Navigator.of(context).pop(),
),
actions: _categories
.map(
(category) => CupertinoButton(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text(
category.name ?? "",
style: TextStyle(
fontFamily: "Neo sans",
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(
getColorHexFromStr("#b83b56"),
),
),
),
Image.network(
category.image,
width: 20,
height: 20,
),
],
),
),
onPressed: () {
setState(() {
_formData['category_id'] = category.id;
_categoryController.text = category.name;
});
Navigator.of(context).pop();
},
),
)
.toList(),
),
);
});
}
void _displayConfirmDialog(BuildContext context) {
showCupertinoDialog(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text(
"عميلنا العزيز",
style: TextStyle(
fontFamily: "Neo sans",
fontSize: 18,
color: Color(
getColorHexFromStr("#b83b56"),
),
),
),
content: Column(
children: <Widget>[
Text(
"تم ارسال البيانات للادارة للتاكد من صحة البيانات",
style: TextStyle(
fontFamily: "Neo sans",
fontSize: 18,
color: Color(
getColorHexFromStr("#b83b56"),
),
),
),
Text(
"وسيتم الرد عليك عن طريق البريد الالكترونى فى اقرب وقت",
style: TextStyle(
fontFamily: "Neo sans",
fontSize: 18,
color: Color(
getColorHexFromStr("#b83b56"),
),
),
),
SizedBox(
height: 10,
),
Text(
"وشكرا لتعاملكم معنا",
style: TextStyle(
fontFamily: "Neo sans",
fontSize: 18,
color: Color(
getColorHexFromStr("#b83b56"),
),
),
),
],
),
actions: <Widget>[
CupertinoButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
"موافق",
style: TextStyle(
fontFamily: "Neo sans",
fontSize: 18,
color: Color(
getColorHexFromStr("#b83b56"),
),
),
),
),
],
);
});
}
void _submit(BuildContext context) {
if (!_formKey.currentState.validate()) {
showInSnackBar("من فضلك قم بحل جميع لمشاكل اولا");
return;
}
if (_formData['category_id'] == null) {
showInSnackBar("يجب اختيار القسم قبل التسجيل");
return;
}
_formData['password'] = "1212";
_formKey.currentState.save();
setState(() {
_isLoading = true;
});
widget.model.addProvider(_formData).then((result) {
if (result != null && result['status'] == 'ok') {
setState(() {
_isLoading = false;
});
_displayConfirmDialog(context);
} else {
setState(() {
_isLoading = false;
});
displayDialog(
context, "خطأ", result['message'] ?? "من فضلك حاول مره اخرى");
}
}).catchError((err) {
setState(() {
_isLoading = false;
});
print("errrrr ++++++++++++++++++++++ $err");
displayDialog(context, "خطأ", err['message'] ?? "من فضلك حاول مره اخرى");
});
}
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
key: _scafoldKey,
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
// Where the linear gradient begins and ends
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
// Add one stop for each color. Stops should increase from 0 to 1
stops: [0.2, 0.9],
colors: [
// Colors are easy thanks to Flutter's Colors class.
Color(
getColorHexFromStr("#FF3793"),
),
Color(
getColorHexFromStr("#C60F63"),
),
],
),
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
SizedBox(
height: 20,
),
Image.asset(
"assets/icons/logo_footer.png",
width: MediaQuery.of(context).size.width / 3,
),
SizedBox(
height: 10,
),
Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.fromLTRB(30, 10, 30, 10),
child: Material(
elevation: 5.0,
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.circular(35),
child: Container(
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Colors.white,
),
child: Column(
children: <Widget>[
Column(
children: <Widget>[
Text(
"تسجيل مقدم خدمة",
style: TextStyle(
fontFamily: "Neo sans",
fontSize: 18,
color: Color(
getColorHexFromStr("#b83b56"),
),
),
),
Container(
height: 5,
width:
MediaQuery.of(context).size.width / 4,
decoration: BoxDecoration(
color: Color(
getColorHexFromStr("#b83b56"),
),
),
),
SizedBox(
height: 10,
),
TextFormField(
onSaved: (String val) {
setState(() {
_formData['name'] = val;
});
},
validator: (String val) {
if (val.isEmpty) {
return "الاسم مطلوب";
} else
return null;
},
decoration: InputDecoration(
labelText: 'الاسم',
labelStyle: TextStyle(
color: Colors.grey,
fontFamily: "Neo sans",
),
border: UnderlineInputBorder(
borderSide: BorderSide(
style: BorderStyle.solid,
color: Colors.grey,
),
),
),
),
TextFormField(
onSaved: (String val) {
setState(() {
_formData['email'] = val;
});
},
validator: (String val) {
Pattern pattern =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
RegExp regex = new RegExp(pattern);
if (!regex.hasMatch(val))
return "البريد الالكترونى غير صحيح";
else
return null;
},
decoration: InputDecoration(
labelText: 'البريد الالكترونى',
labelStyle: TextStyle(
color: Colors.grey,
fontFamily: "Neo sans",
),
border: UnderlineInputBorder(
borderSide: BorderSide(
style: BorderStyle.solid,
color: Colors.grey,
),
),
),
),
TextFormField(
onSaved: (String val) {
setState(() {
_formData['phone'] = val;
});
},
validator: (String val) {
if (val.isEmpty) {
return "رقم الجوال مطلوب";
} else
return null;
},
decoration: InputDecoration(
labelText: 'رقم الجوال',
labelStyle: TextStyle(
color: Colors.grey,
fontFamily: "Neo sans",
),
border: UnderlineInputBorder(
borderSide: BorderSide(
style: BorderStyle.solid,
color: Colors.grey,
),
),
),
),
InkWell(
onTap: () {
_openCitiesBottomSheet(context);
},
child: TextFormField(
enabled: false,
controller: _categoryController,
onSaved: (String val) {},
validator: (String val) {
if (val.isEmpty) {
return "القسم مطلوب";
} else
return null;
},
decoration: InputDecoration(
labelText: 'القسم',
labelStyle: TextStyle(
color: Colors.grey,
fontFamily: "Neo sans",
),
border: UnderlineInputBorder(
borderSide: BorderSide(
style: BorderStyle.solid,
color: Colors.grey,
),
),
),
),
),
TextFormField(
onSaved: (String val) {
setState(() {
_formData['shop_name'] = val;
});
},
validator: (String val) {
if (val.isEmpty) {
return "اسم المحل مطلوب";
} else
return null;
},
decoration: InputDecoration(
labelText: 'اسم المحل',
labelStyle: TextStyle(
color: Colors.grey,
fontFamily: "Neo sans",
),
border: UnderlineInputBorder(
borderSide: BorderSide(
style: BorderStyle.solid,
color: Colors.grey,
),
),
),
),
TextFormField(
onSaved: (String val) {
setState(() {
_formData['shop_address'] = val;
});
},
validator: (String val) {
if (val.isEmpty) {
return "عنوان المحل مطلوب";
} else
return null;
},
decoration: InputDecoration(
labelText: 'عنوان المحل',
labelStyle: TextStyle(
color: Colors.grey,
fontFamily: "Neo sans",
),
border: UnderlineInputBorder(
borderSide: BorderSide(
style: BorderStyle.solid,
color: Colors.grey,
),
),
),
),
TextFormField(
onSaved: (String val) {
setState(() {
_formData['crn'] = val;
});
},
validator: (String val) {
if (val.isEmpty) {
return "رقم السجل التجارى مطلوب";
} else
return null;
},
decoration: InputDecoration(
labelText: 'رقم السجل التجارى',
labelStyle: TextStyle(
color: Colors.grey,
fontFamily: "Neo sans",
),
border: UnderlineInputBorder(
borderSide: BorderSide(
style: BorderStyle.solid,
color: Colors.grey,
),
),
),
),
SizedBox(
height: 20,
),
_isLoading
? Center(
child: CupertinoActivityIndicator(
animating: true,
radius: 15,
),
)
: InkWell(
onTap: () {
_submit(context);
},
child: Image.asset(
"assets/icons/go.png",
width: 80,
height: 80,
),
),
SizedBox(
height: 10,
),
],
),
// SizedBox(
// height: 20,
// ),
],
),
),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"لديك حساب بالفعل ؟",
style: TextStyle(
color: Colors.white,
fontFamily: "Neo sans",
),
),
Text(
"تسجيل الدخول",
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.white,
fontFamily: "Neo sans",
),
),
],
),
SizedBox(
height: 10,
),
],
),
],
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment