ravipatil6596

Flutter Registration

Aug 13th, 2021 (edited)
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.45 KB | None | 0 0
  1. import 'dart:convert';
  2. import 'package:http/http.dart' as http;
  3. import 'package:flutter/material.dart';
  4.  
  5. class RegisterScreen extends StatefulWidget {
  6.   const RegisterScreen({Key? key}) : super(key: key);
  7.  
  8.   @override
  9.   _RegisterScreenState createState() => _RegisterScreenState();
  10. }
  11.  
  12. class _RegisterScreenState extends State<RegisterScreen> {
  13.   TextEditingController emailscon = TextEditingController();
  14.   TextEditingController contact = TextEditingController();
  15.   TextEditingController password = TextEditingController();
  16.   TextEditingController conpassword = TextEditingController();
  17.  
  18.   register(String email, contact, pass, conpass) async {
  19.     Map data = {
  20.       'Email': email,
  21.       'Mobile': contact,
  22.       'Password': pass,
  23.       'RetypePassword': conpass,
  24.     };
  25.     print(data);
  26.  
  27.     String body = json.encode(data);
  28.     var url = 'http://medbo.digitalicon.in/api/medboapi/userreg';
  29.     var response = await http.post(
  30.       Uri.parse(url),
  31.       body: body,
  32.       headers: {
  33.         "Content-Type": "application/json",
  34.         "accept": "application/json",
  35.         "Access-Control-Allow-Origin": "*"
  36.       },
  37.     );
  38.     print(response.body);
  39.     print(response.statusCode);
  40.     if (response.statusCode == 200) {
  41.       //Or put here your next screen using Navigator.push() method
  42.       print('success');
  43.     } else {
  44.       print('error');
  45.     }
  46.   }
  47.  
  48.   @override
  49.   Widget build(BuildContext context) {
  50.     return Scaffold(
  51.       resizeToAvoidBottomInset: false,
  52.       backgroundColor: Colors.white,
  53.       body: SingleChildScrollView(
  54.         physics: ScrollPhysics(),
  55.         padding: const EdgeInsets.all(16.0),
  56.         child: Column(
  57.           children: [
  58.             SizedBox(
  59.               height: 150,
  60.               child: Padding(
  61.                 padding: const EdgeInsets.all(38.0),
  62.                 child: Text(
  63.                   'Register',
  64.                   style: TextStyle(fontSize: 30),
  65.                 ),
  66.               ),
  67.             ),
  68.             TextFormField(
  69.               controller: emailscon,
  70.               keyboardType: TextInputType.emailAddress,
  71.               textInputAction: TextInputAction.next,
  72.               decoration: InputDecoration(
  73.                 prefixIcon: Icon(Icons.email),
  74.                 border: OutlineInputBorder(),
  75.                 labelText: 'Email',
  76.                 hintText: 'Enter Email Here',
  77.               ),
  78.             ),
  79.             SizedBox(
  80.               height: 20,
  81.             ),
  82.             TextFormField(
  83.               controller: contact,
  84.               keyboardType: TextInputType.phone,
  85.               textInputAction: TextInputAction.next,
  86.               decoration: InputDecoration(
  87.                 prefixIcon: Icon(Icons.phone),
  88.                 border: OutlineInputBorder(),
  89.                 labelText: 'Contact',
  90.                 hintText: 'Enter Contact Here',
  91.               ),
  92.             ),
  93.             SizedBox(
  94.               height: 20,
  95.             ),
  96.             TextFormField(
  97.               controller: password,
  98.               textInputAction: TextInputAction.next,
  99.               decoration: InputDecoration(
  100.                 prefixIcon: Icon(Icons.lock),
  101.                 border: OutlineInputBorder(),
  102.                 labelText: 'Password',
  103.                 hintText: 'Enter Password Here',
  104.               ),
  105.             ),
  106.             SizedBox(
  107.               height: 20,
  108.             ),
  109.             TextFormField(
  110.               controller: conpassword,
  111.               textInputAction: TextInputAction.next,
  112.               decoration: InputDecoration(
  113.                 prefixIcon: Icon(Icons.lock),
  114.                 border: OutlineInputBorder(),
  115.                 labelText: 'Confirm Password',
  116.                 hintText: 'Enter Password Here',
  117.               ),
  118.             ),
  119.             SizedBox(
  120.               height: 20,
  121.             ),
  122.             ElevatedButton(
  123.               child: Text('Register'),
  124.               onPressed: () {
  125.                 register(emailscon.text, contact.text, password.text,
  126.                     conpassword.text);
  127.               },
  128.             ),
  129.           ],
  130.         ),
  131.       ),
  132.     );
  133.   }
  134. }
  135.  
  136. //your response
  137.  
  138.  
  139. /* I/flutter ( 8238): {Email: [email protected], Mobile: 1234567890, Password: aa, RetypePassword: aa}
  140. I/flutter ( 8238): {"Status":"1","Message":"You are registered successfully","UserData":{"Name":"[email protected]","EncUserId":"SBPlOA3zq2tOk4gOSzBCHw=="}}
  141. I/flutter ( 8238): 200
  142. I/flutter ( 8238): success*/
  143.  
Add Comment
Please, Sign In to add comment