login form code in flutter

Sure! Here's an example of a login page created using Flutter:


```dart

import 'package:flutter/material.dart';


void main() {

  runApp(LoginApp());

}


class LoginApp extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      title: 'Login Page',

      theme: ThemeData(

        primarySwatch: Colors.blue,

      ),

      home: LoginPage(),

    );

  }

}


class LoginPage extends StatefulWidget {

  @override

  _LoginPageState createState() => _LoginPageState();

}


class _LoginPageState extends State<LoginPage> {

  String _email = '';

  String _password = '';


  void _submitForm() {

    // Perform login logic here

    print('Email: $_email');

    print('Password: $_password');

  }


  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(

        title: Text('Login Page'),

      ),

      body: Padding(

        padding: EdgeInsets.all(16.0),

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,

          children: [

            TextField(

              decoration: InputDecoration(labelText: 'Email'),

              onChanged: (value) {

                setState(() {

                  _email = value;

                });

              },

            ),

            SizedBox(height: 16.0),

            TextField(

              decoration: InputDecoration(labelText: 'Password'),

              obscureText: true,

              onChanged: (value) {

                setState(() {

                  _password = value;

                });

              },

            ),

            SizedBox(height: 16.0),

            RaisedButton(

              onPressed: _submitForm,

              child: Text('Login'),

            ),

          ],

        ),

      ),

    );

  }

}

```


In this code, we create a simple login page with two input fields for email and password. When the user enters their credentials and taps the "Login" button, the `_submitForm` function is called, where you can perform the necessary login logic (e.g., API call, authentication, etc.). In this example, we simply print the email and password to the console.


To run this code, make sure you have Flutter and Dart installed on your machine. Create a new Flutter project, replace the default `lib/main.dart` file with the code above, and run the app using `flutter run`.


This is a basic login page implementation, and you can further enhance it by adding validation, error handling, and styling according to your requirements. 

Comments

Popular posts from this blog

swapping the alternate values in given array's element ! 17/11/2022

c++ basic question

Learning stage | c++ programs