0% found this document useful (0 votes)
9 views6 pages

Createaccount

The document is a Flutter widget for creating an account, featuring fields for name, email, and password with validation. It includes functionality for email verification and password confirmation, as well as a method to send user data to a server. The UI is designed with a dark theme and includes visual feedback for input errors.

Uploaded by

riveramiko5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Createaccount

The document is a Flutter widget for creating an account, featuring fields for name, email, and password with validation. It includes functionality for email verification and password confirmation, as well as a method to send user data to a server. The UI is designed with a dark theme and includes visual feedback for input errors.

Uploaded by

riveramiko5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

import 'package:flutter/material.

dart';
import 'package:http/http.dart' as http;
import 'varconnect.dart';

class CreateAccount extends StatefulWidget {


const CreateAccount({super.key});

@override
State<CreateAccount> createState() => _CreateAccountState();
}

class _CreateAccountState extends State<CreateAccount> {


@override

//email verification
final RegExp emailRegex = RegExp(
r'^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
);

//for textcontroller obscure text


bool _obscureText1 = true;
bool _obscureText2 = true;

//text controller declaration


TextEditingController name = TextEditingController();
TextEditingController email = TextEditingController();
TextEditingController pass1 = TextEditingController();
TextEditingController pass2 = TextEditingController();

//for sending data to the database


Future<void> registeracc() async{
final uri = link+ "user_register.php";

Map<String, dynamic> userdata = {


'name' : name.text,
'pass' : pass2.text,
'email' : email.text
};
final response = await http.post(Uri.parse(uri), body:userdata,);
print(response.body);

print(userdata);

setState(() {
msg = response.body;
});
}
verification()
{
bool namecheck = name.text.isEmpty;
String checkmail = email.text.trim();
bool isValidEmail = emailRegex.hasMatch(checkmail);
bool emptypass1 = pass1.text.isEmpty;
bool emptypass2 = pass1.text.isEmpty;
bool passcheck = identical(pass1.text, pass2.text);

if (namecheck == false && isValidEmail == true && passcheck == true )


{
if(emptypass1 == false && emptypass2 == false)
{
registeracc();
Navigator.pop(context);
setState(() {
msg = "";
});
}
else
{
setState(() {
msg = "Password cannot be empty, please try again ";
});
}
}

else
{
setState(() {
msg = "Something wrong with your credential, please try again ";
});
}
}

Widget build(BuildContext context) {


return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Create an Account',style: TextStyle(fontSize: 20,color:
Colors.white),),
),

body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(top: 30,left: 10,right: 10,bottom: 5),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black12,
width: 2.0,
),
borderRadius: BorderRadius.circular(60.0),
color: Colors.black,
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 5.0,
spreadRadius: 2.0,
offset: Offset(0, 3),
),
],
),
child: Padding(
padding: const EdgeInsets.all(40.0),
child: Column(
children: [
SizedBox(height: 30,),
Container(
child: Column(
children: [

Row(
children: [
Text('Name ',style: TextStyle(fontWeight:
FontWeight.bold,fontSize: 15,color: Colors.white),),
],
),

Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0), // Adjust
the radius as needed
border: Border.all(
color: Colors.yellow, // Set the border color
width: 2.0, // Set the border width
),
),
child: TextField(
decoration: InputDecoration(
//labelText: 'Name',
border: InputBorder.none, // Remove the default
TextField border
contentPadding: EdgeInsets.symmetric(horizontal:
10.0), // Adjust the padding as needed
),
style: TextStyle(color: Colors.white),
controller: name
),
),

SizedBox(height: 30,),

Row(
children: [
Text('Email ',style: TextStyle(fontWeight:
FontWeight.bold,fontSize: 15,color: Colors.white),),
],
),

Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0), // Adjust
the radius as needed
border: Border.all(
color: Colors.yellow, // Set the border color
width: 2.0, // Set the border width
),
),
child: TextField(
decoration: InputDecoration(
//labelText: 'Email',
border: InputBorder.none, // Remove the default
TextField border
contentPadding: EdgeInsets.symmetric(horizontal:
10.0), // Adjust the padding as needed
),
style: TextStyle(color: Colors.white),
controller: email
),
),
SizedBox(height: 30,),

Row(
children: [
Text('Password ',style: TextStyle(fontWeight:
FontWeight.bold,fontSize: 15,color: Colors.white),),
],
),

Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0), // Adjust
the radius as needed
border: Border.all(
color: Colors.yellow, // Set the border color
width: 2.0, // Set the border width
),
),
child: TextField(
obscureText: _obscureText1,
decoration: InputDecoration(
//labelText: 'Password',
border: InputBorder.none, // Remove the default
TextField border
contentPadding: EdgeInsets.only(left: 10.0,top:
10.0),
//contentPadding: EdgeInsets.symmetric(horizontal:
10.0), // Adjust the padding as needed
suffixIcon: IconButton(
icon: Icon(
_obscureText1 ? Icons.visibility :
Icons.visibility_off,color: Colors.yellow,
),
onPressed: () {
setState(() {
_obscureText1 = !_obscureText1;
});
},
),
),
style: TextStyle(color: Colors.white),
controller: pass1
),
),

SizedBox(height: 30,),

Row(
children: [
Text('Confirm Password ',style: TextStyle(fontWeight:
FontWeight.bold,fontSize: 15,color: Colors.white),),
],
),

Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0), // Adjust
the radius as needed
border: Border.all(
color: Colors.yellow, // Set the border color
width: 2.0, // Set the border width
),
),
child: TextField(
obscureText: _obscureText2,
decoration: InputDecoration(
//labelText: 'Password',
border: InputBorder.none, // Remove the default
TextField border
contentPadding: EdgeInsets.only(left: 10.0,top:
10.0), // Adjust the padding as needed
suffixIcon: IconButton(
icon: Icon(
_obscureText2 ? Icons.visibility :
Icons.visibility_off,
color: Colors.yellow,
),
onPressed: () {

setState(() {
_obscureText2 = !_obscureText2;
});
},
),
),
style: TextStyle(color: Colors.white),
controller: pass2
),
),

SizedBox(height: 30,),

Container(
width: 200,
height: 40,
child: ClipRRect(
borderRadius: BorderRadius.circular(100.0), // Set the
border radius
child: Container(
color: Colors.yellow,
child: TextButton(
onPressed: () async{
await verification();
name.text = "";
email.text = "";
pass1.text = "";
pass2.text = "";

}, child: Text('Sign Up',style: TextStyle(color:


Colors.black,fontWeight: FontWeight.bold)
),
),
),
),
),
SizedBox(height: 15,),

Text(msg, style: TextStyle(color: Colors.red, fontSize:


15),textAlign: TextAlign.center,),

],
),
),
],

),
),
),
),

),

);
}
}

You might also like