Open In App

Flutter – Design Login Page UI

Improve
Improve
Like Article
Like
Save
Share
Report

Flutter is Google’s Mobile SDK to build native iOS and Android apps from a single codebase. When building applications with Flutter everything is towards Widgets – the blocks with which the Flutter apps are built. The User Interface of the app is composed of many simple widgets, each of them handling one particular job. In this article, we will create a simple Login page, that can be fully customized with the size, color, and size of the Login button. A sample video is given below to get an idea about what we will do in this article.

Step By Step Implementation

Step 1: Create a New Project in Android Studio

To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.

Step 2: Import the Package in the pubspec.yaml file

import 'package:flutter/material.dart';
import 'log_in.dart';

Implementation 

Dart




import 'package:flutter/material.dart';
  
import 'HomePage.dart';
import 'log_in.dart';
  
void main() {
  runApp(MyApp());
}
  
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: LoginDemo(),
    );
  }
}
  
class LoginDemo extends StatefulWidget {
  @override 
  _LoginDemoState createState() => _LoginDemoState();
}
  
class _LoginDemoState extends State<LoginDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("GeeksforGeeks"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.only(top: 110.0),
              child: Center(
                child: Container(
                    width: 200,
                    height: 100,
                    /*decoration: BoxDecoration(
                        color: Colors.red,
                        borderRadius: BorderRadius.circular(50.0)),*/
                    child: Image.asset('assets/images/Instagram.png')),
              ),
            ),
            Padding(
              //padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
              padding: EdgeInsets.symmetric(horizontal: 15),
              child: TextField(
                decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: 'Phone number, email or username',
                    hintText: 'Enter valid email id as abc@gmail.com'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(
                  left: 15.0, right: 15.0, top: 15, bottom: 0),
              //padding: EdgeInsets.symmetric(horizontal: 15),
              child: TextField(
  
                obscureText: true,
                decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: 'Password',
                    hintText: 'Enter secure password'),
              ),
            ),
  
          SizedBox(
            height: 65,
            width: 360,
            child: Container(
                child: Padding(
                  padding: const EdgeInsets.only(top: 20.0),
                  child: ElevatedButton(
                    child: Text( 'Log in ', style: TextStyle(color: Colors.white, fontSize: 20),
                    ),
                    onPressed: (){
                      print('Successfully log in ');
                    },
  
                  ),
                ),
              ),
          ),
  
            SizedBox(
              height: 50,
            ),
            Container(
                child: Center(
                  child: Row(
                    children: [
  
                      Padding(
                        padding: const EdgeInsets.only(left: 62),
                        child: Text('Forgot your login details? '),
                      ),
  
                      Padding(
                        padding: const EdgeInsets.only(left:1.0),
                        child: InkWell(
                          onTap: (){
                            print('hello');
                          },
                            child: Text('Get help logging in.', style: TextStyle(fontSize: 14, color: Colors.blue),)),
                      )
                    ],
                  ),
                )
            )
          ],
        ),
      ),
    );
  }
}


Code Explanation

  • Here we first make the flutter project, remove the default code, make the stateful widget, and give the Login class name of the stateful widget.
  • Now return the scaffold in the stateful widget. In the stateful widget, we take the AppBar, row, and column, and write the text widget in the body.
  • Now, we take the child and in the child, we take the text field, we take the Text Field, and the Text Field wrapped with the padding. And give it in the hint box.
  • Enter a valid email id as abc@gmail.com” and  “Enter a secure password”.
  • Now we take the child and child we take Elevated Button and on pressed Login button print “Successfully logged in”. And Elevated Button wrap with the container and the container also wrap with padding. we are giving it in our code you just comment out and give the location of your page.

Output



Last Updated : 15 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads