Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:http/http.dart' as http;
- import 'package:flutter/material.dart';
- class RegisterScreen extends StatefulWidget {
- const RegisterScreen({Key? key}) : super(key: key);
- @override
- _RegisterScreenState createState() => _RegisterScreenState();
- }
- class _RegisterScreenState extends State<RegisterScreen> {
- TextEditingController emailscon = TextEditingController();
- TextEditingController contact = TextEditingController();
- TextEditingController password = TextEditingController();
- TextEditingController conpassword = TextEditingController();
- register(String email, contact, pass, conpass) async {
- Map data = {
- 'Email': email,
- 'Mobile': contact,
- 'Password': pass,
- 'RetypePassword': conpass,
- };
- print(data);
- String body = json.encode(data);
- var url = 'http://medbo.digitalicon.in/api/medboapi/userreg';
- var response = await http.post(
- Uri.parse(url),
- body: body,
- headers: {
- "Content-Type": "application/json",
- "accept": "application/json",
- "Access-Control-Allow-Origin": "*"
- },
- );
- print(response.body);
- print(response.statusCode);
- if (response.statusCode == 200) {
- //Or put here your next screen using Navigator.push() method
- print('success');
- } else {
- print('error');
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- resizeToAvoidBottomInset: false,
- backgroundColor: Colors.white,
- body: SingleChildScrollView(
- physics: ScrollPhysics(),
- padding: const EdgeInsets.all(16.0),
- child: Column(
- children: [
- SizedBox(
- height: 150,
- child: Padding(
- padding: const EdgeInsets.all(38.0),
- child: Text(
- 'Register',
- style: TextStyle(fontSize: 30),
- ),
- ),
- ),
- TextFormField(
- controller: emailscon,
- keyboardType: TextInputType.emailAddress,
- textInputAction: TextInputAction.next,
- decoration: InputDecoration(
- prefixIcon: Icon(Icons.email),
- border: OutlineInputBorder(),
- labelText: 'Email',
- hintText: 'Enter Email Here',
- ),
- ),
- SizedBox(
- height: 20,
- ),
- TextFormField(
- controller: contact,
- keyboardType: TextInputType.phone,
- textInputAction: TextInputAction.next,
- decoration: InputDecoration(
- prefixIcon: Icon(Icons.phone),
- border: OutlineInputBorder(),
- labelText: 'Contact',
- hintText: 'Enter Contact Here',
- ),
- ),
- SizedBox(
- height: 20,
- ),
- TextFormField(
- controller: password,
- textInputAction: TextInputAction.next,
- decoration: InputDecoration(
- prefixIcon: Icon(Icons.lock),
- border: OutlineInputBorder(),
- labelText: 'Password',
- hintText: 'Enter Password Here',
- ),
- ),
- SizedBox(
- height: 20,
- ),
- TextFormField(
- controller: conpassword,
- textInputAction: TextInputAction.next,
- decoration: InputDecoration(
- prefixIcon: Icon(Icons.lock),
- border: OutlineInputBorder(),
- labelText: 'Confirm Password',
- hintText: 'Enter Password Here',
- ),
- ),
- SizedBox(
- height: 20,
- ),
- ElevatedButton(
- child: Text('Register'),
- onPressed: () {
- register(emailscon.text, contact.text, password.text,
- conpassword.text);
- },
- ),
- ],
- ),
- ),
- );
- }
- }
- //your response
- /* I/flutter ( 8238): {Email: [email protected], Mobile: 1234567890, Password: aa, RetypePassword: aa}
- I/flutter ( 8238): {"Status":"1","Message":"You are registered successfully","UserData":{"Name":"[email protected]","EncUserId":"SBPlOA3zq2tOk4gOSzBCHw=="}}
- I/flutter ( 8238): 200
- I/flutter ( 8238): success*/
Add Comment
Please, Sign In to add comment