Flutter Login page Code

Simple add this code in main.dart file and run :

import 'package:flutter/material.dart';

void main() {
runApp(MaterialApp(
home: MyApp(),
));
}

class MyApp extends StatefulWidget {
@override
_State createState() => _State();
}

class _State extends State {
TextEditingController nameController = TextEditingController();
TextEditingController passwordController = TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘Sample App’),
),
body: Padding(
padding: EdgeInsets.all(10),
child: ListView(
children: [
Container(
alignment: Alignment.center,
padding: EdgeInsets.all(10),
child: Text(
‘Login Example ‘,
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w500,
fontSize: 30),
)),
Container(
alignment: Alignment.center,
padding: EdgeInsets.all(10),
child: Text(
‘Sign in’,
style: TextStyle(fontSize: 20),
)),
Container(
padding: EdgeInsets.all(10),
child: TextField(
controller: nameController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: ‘User Name’,
),
),
),
Container(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: TextField(
obscureText: true,
controller: passwordController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: ‘Password’,
),
),
),
FlatButton(
onPressed: () {
//forgot password screen
},
textColor: Colors.blue,
child: Text(‘Forgot Password’),
),
Container(
height: 50,
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
child: RaisedButton(
textColor: Colors.white,
color: Colors.blue,
child: Text(‘Login’),
onPressed: () {
print(nameController.text);
print(passwordController.text);
},
)),
Container(
child: Row(
children: [
Text(‘Does not have account?’),
FlatButton(
textColor: Colors.blue,
child: Text(
‘Sign in’,
style: TextStyle(fontSize: 20),
),
onPressed: () {
//signup screen
},
)
],
mainAxisAlignment: MainAxisAlignment.center,
))
],
)));
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *