Flutter Registration/ Screen - Example

 


Simple demo for Registration in Flutter

Here's a step-by-step guide:

  1. Create a new Flutter project using your preferred IDE or by running the following command in your terminal:
flutter create registration_demo


  1. In the lib folder of your project, create a new file named register_screen.dart. This will be the screen where users can register.

  2. In register_screen.dart, create a new StatefulWidget named RegisterScreen.

import 'package:flutter/material.dart'; class RegisterScreen extends StatefulWidget { @override _RegisterScreenState createState() => _RegisterScreenState(); } class _RegisterScreenState extends State<RegisterScreen> { @override Widget build(BuildContext context) { return Container( child: Text('Registration Screen'), ); } }


  1. Add a TextFormField for the user to enter their email address.
class _RegisterScreenState extends State<RegisterScreen> { String _email = ''; @override Widget build(BuildContext context) { return Container( child: TextFormField( decoration: InputDecoration( labelText: 'Email', hintText: 'Enter your email address', ), keyboardType: TextInputType.emailAddress, onChanged: (value) { setState(() { _email = value; }); }, ), ); } }


  1. Add a TextFormField for the user to enter their password.
class _RegisterScreenState extends State<RegisterScreen> { String _email = ''; String _password = ''; @override Widget build(BuildContext context) { return Container( child: Column( children: [ TextFormField( decoration: InputDecoration( labelText: 'Email', hintText: 'Enter your email address', ), keyboardType: TextInputType.emailAddress, onChanged: (value) { setState(() { _email = value; }); }, ), TextFormField( decoration: InputDecoration( labelText: 'Password', hintText: 'Enter your password', ), obscureText: true, onChanged: (value) { setState(() { _password = value; }); }, ), ], ), ); } }


  1. Add a RaisedButton to submit the registration form.
class _RegisterScreenState extends State<RegisterScreen> { String _email = ''; String _password = ''; @override Widget build(BuildContext context) { return Container( child: Column( children: [ TextFormField( decoration: InputDecoration( labelText: 'Email', hintText: 'Enter your email address', ), keyboardType: TextInputType.emailAddress, onChanged: (value) { setState(() { _email = value; }); }, ), TextFormField( decoration: InputDecoration( labelText: 'Password', hintText: 'Enter your password', ), obscureText: true, onChanged: (value) { setState(() { _password = value; }); }, ), SizedBox(height: 16), RaisedButton( child: Text('Register'), onPressed: () { // TODO: Implement registration logic }, ), ], ), ); } }



Comments