Skip to main content

In this lesson, we will focus on creating a Form like display:

This form will not do anything but is a good starting point for creating a login form.


Adding Simple Form

Once again, we will be modifying our main.dart file and replacing the MyApp class with the following code:

lib/main.dart

import 'package:flutter/material.dart';
 
void main() {
runApp(MyApp());
}
 
class MyApp extends StatelessWidget {
const MyApp({super.key});
 
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text('Login'),
),
body: Column(
children: <Widget>[
TextField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Email',
),
),
TextField(
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
),
),
ElevatedButton(
onPressed: () {
print('Login button pressed');
},
child: Text('Login'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
minimumSize: Size(double.infinity, 36),
),
),
],
)));
}
}

Saving the file should automatically update the emulator with the new form:

But how did we get here?

We replaced our AppBar title with Login to ...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 41 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.