You are on page 1of 12

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:intl/intl.dart';
import 'package:lawyar/auth/otp.dart';
import 'package:http/http.dart' as http;

class SignupScreen extends StatefulWidget {


@override
_AppState createState() => _AppState();
}

class _AppState extends State<SignupScreen> {

TextEditingController _name = TextEditingController();


TextEditingController _realtivername = TextEditingController();
TextEditingController _address = TextEditingController();
TextEditingController _education = TextEditingController();
TextEditingController _country = TextEditingController();
TextEditingController _enrollmentno = TextEditingController();
TextEditingController _barpractice = TextEditingController();
TextEditingController _email = TextEditingController();
TextEditingController _mobile = TextEditingController();

final GlobalKey<FormState> _formkey = GlobalKey<FormState>();

@override
void initState() {
// TODO: implement initState
super.initState();
this.getSWData();
}

DateTime _selectedDate;
TextEditingController _textEditingController = TextEditingController();
String _selected;
String _selected1;
String _selected2;
//var case_types = ["Case 1", "case 2", "case 3", "case 4", "case 5"];

//List<Map> data = List();


List<Map> case_types = [
{"id": '1',"name": "Civil"},
{"id": '2',"name": "Criminal"},
{"id": '3',"name": "Divorce"},
{"id": '4',"name": "Marriage"},
{"id": '14',"name": "Murder"},
]

Future getSWData() async {

var url = Uri.parse('https://api.mylawyar.com/api/case_type');


http.Response respons = await http.get(url);
print(respons.statusCode);
if(respons.statusCode == 200){
// print('Sucess');
//final case_types = jsonDecode(respons.body);
//final name = case_types[1]['name'];
Map<String ,dynamic> jsonBody = jsonDecode(respons.body);
final data = jsonBody['data']['case_types'];
//print(data);
//print(data[1]['name']);
data.map((items) =>{
print(items['name'])
}).toList();

}else{
print('Oops somthing went wrong');
}
}

@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;

return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0,
brightness: Brightness.light,
backgroundColor: Colors.white,
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(Icons.arrow_back_ios,
size: 20,
color: Colors.black,),

),
),
body:
//ListView(

// children: <Widget>[

SingleChildScrollView(
child: Container(
height: 1500,
width: double.infinity,
child: Form(
key: _formkey,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 10),
height: 100,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/splash.png"),
fit: BoxFit.fitHeight
),

),
),
Text("Create an account",
style: TextStyle(fontSize: 30,
fontWeight: FontWeight.bold,
color: Color(0xff660027)),),
SizedBox(height: 20,),

],
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _name,
keyboardType: TextInputType.text,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Name',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
),
validator: (String value) {
if (value.isEmpty) {
return "Please enter name";
}
return null;
},
onSaved: (String name) {

},
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _realtivername,
keyboardType: TextInputType.text,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: "Father's/Husband's Name",
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
),
validator: (String value) {
if (value.isEmpty) {
return "Please enter Father name";
}
return null;
},
onSaved: (String name) {

},
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _address,
keyboardType: TextInputType.text,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Address',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
)
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Date of birth',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
),
controller: _textEditingController,
onTap: () {
_selectDate(context);
},
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _education,
keyboardType: TextInputType.text,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Education qualification',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
)
),
),

Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: InputDecorator(
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(borderSide:
BorderSide(color: Color(0xff660027) )),
enabledBorder: UnderlineInputBorder(borderSide:
BorderSide(color: Color(0xff660027).withOpacity(0.2),)),
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
),
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
hint: new Text("Type of case prefer ",style:
TextStyle(
color: Color(0xff660027),
),),
isDense: true,
value: _selected,
onChanged: (String newValue) {
setState(() {
_selected = newValue;
});
print(_selected);
},
items: case_types.map((Map map) {
return DropdownMenuItem<String>(
value: map["id"].toString(),
child: Text(map["name"],style: TextStyle(
color: Color(0xff660027),

),),
);
}).toList(),
),
),
),
),
),

Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: InputDecorator(
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(borderSide:
BorderSide(color: Color(0xff660027) )),
enabledBorder: UnderlineInputBorder(borderSide:
BorderSide(color: Color(0xff660027).withOpacity(0.2),)),
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
),
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
hint: new Text("Type of case prefer ",style:
TextStyle(
color: Color(0xff660027),
),),
isDense: true,
value: _selected1,
onChanged: (String newValue) {
setState(() {
_selected1 = newValue;
});
print(_selected1);
},
items: case_types.map((Map map) {
return DropdownMenuItem<String>(
value: map["id"].toString(),
child: Text(map["name"],style: TextStyle(
color: Color(0xff660027),

),),
);
}).toList(),
),
),
),
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: InputDecorator(
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(borderSide:
BorderSide(color: Color(0xff660027) )),
enabledBorder: UnderlineInputBorder(borderSide:
BorderSide(color: Color(0xff660027).withOpacity(0.2),)),
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
),
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
hint: new Text("Type of case prefer ",style:
TextStyle(
color: Color(0xff660027),
),),
isDense: true,
value: _selected2,
onChanged: (String newValue) {
setState(() {
_selected2 = newValue;
});
print(_selected2);
},
items: case_types.map((Map map) {
return DropdownMenuItem<String>(
value: map["id"].toString(),
child: Text(map["name"],style: TextStyle(
color: Color(0xff660027),

),),
);
}).toList(),
),
),
),
),
),

Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Date of enrollment',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
),
controller: _textEditingController,
onTap: () {
_selectDate(context);
},
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _enrollmentno,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Enrollment No',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
)
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _barpractice,
keyboardType: TextInputType.text,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Which bar practicing',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
)
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _email,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Email',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
),
keyboardType: TextInputType.emailAddress,
validator: (String value) {
if (value.isEmpty) {
return "Please enter email";
}
if (!RegExp("^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-z]")
.hasMatch(value)) {
return "Please enter valid email";
}
return null;
},
onSaved: (String email) {

},
),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _country,
keyboardType: TextInputType.text,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Country code',
hintStyle: TextStyle(color: Color(0xff660027)),
labelStyle: TextStyle(color: Color(0xff660027)),
)
),
),

Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 40),
child: TextFormField(
controller: _mobile,
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff660027))),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xff660027).withOpacity(0.2),)),
labelText: 'Mobile/Whatsapp no',

hintStyle: TextStyle(color: Color(0xff660027)),


labelStyle: TextStyle(color: Color(0xff660027)),
),
keyboardType: TextInputType.phone,
validator: (String value) {
if (value.isEmpty) {
return "Please enter phone no";
}
if (value.length < 10) {
return " please enter valid phone no";
}
return null;
},
),
),
// SizedBox(height: size.height * 0.0001),

SizedBox(height: 10,),
Padding(padding:
EdgeInsets.symmetric(horizontal: 40),
child: Container(

child: MaterialButton(
minWidth: double.infinity,
height: 60,
onPressed: () {
if (_formkey.currentState.validate()) {
RegistrationUser();
print("successfull");
//Navigator.push(context,
MaterialPageRoute(builder: (context)=> Otp()));
//return;
} else {
print("Unsuccessfull");
}
},
color: Color(0xff660027),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)
),
child: Text(
"Register",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 18
),
),
)
),
),

],
))
],
),
),
),
),
//],
// ),
);
}

//date of birth
_selectDate(BuildContext context) async {
DateTime newSelectedDate = await showDatePicker(
context: context,
initialDate: _selectedDate != null ? _selectedDate : DateTime.now(),
firstDate: DateTime(1950),
lastDate: DateTime(2040),
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.dark().copyWith(
colorScheme: ColorScheme.dark(
primary: Color(0xffff5e9c),
onPrimary: Colors.white,
surface: Color(0xff870537),
onSurface: Colors.white,
),
dialogBackgroundColor: Color(0xff660027),
),
child: child,
);
});

if (newSelectedDate != null) {
_selectedDate = newSelectedDate;
_textEditingController
..text = DateFormat.yMMMd().format(_selectedDate)
..selection = TextSelection.fromPosition(TextPosition(
offset: _textEditingController.text.length,
affinity: TextAffinity.upstream));
}
}

//API CALLING IN POST METHOD

Future RegistrationUser() async {


var APIURL = "https://api.mylawyar.com/api/lawyer";

Map mapeddata = {
'name': _name.text,
'relative_name': _realtivername.text,
'dob': "1996-04-11",
'date_of_enrollment': "2022-12-08",
'address': _address.text,
'educational_qualification': _education.text,
'enrollment_number': _enrollmentno.text,
'bar_practice': _barpractice.text,
'email': _email.text,
'phone': _mobile.text,
'country_code': _country.text,
'case_type_1': _selected,
'case_type_2': _selected1,
'case_type_3': _selected2,
};
print("JSON DATA: ${mapeddata}");

http.Response response = await http.post(


Uri.parse(APIURL), body: mapeddata);

var data = jsonDecode(response.body);

print("DATA: ${data}");
}

}
// we will be creating a widget for text field
Widget inputFile({label, obscureText = false})
{
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
label,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
color:Colors.black87
),

),
SizedBox(
height: 5,
),
TextField(
obscureText: obscureText,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 0,
horizontal: 10),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[400]
),

),
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey[400])
)
),
),
SizedBox(height: 10,)
],
);
}

You might also like