Created
July 2, 2025 07:08
-
-
Save Lxxyx/00b8d0d938da93e9677293f92d1c1c8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Login Page', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
colorSchemeSeed: Colors.blue, | |
), | |
home: const LoginPage(), | |
); | |
} | |
} | |
class LoginPage extends StatefulWidget { | |
const LoginPage({super.key}); | |
@override | |
State<LoginPage> createState() => _LoginPageState(); | |
} | |
class _LoginPageState extends State<LoginPage> { | |
final _formKey = GlobalKey<FormState>(); | |
String _email = ''; | |
String _password = ''; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Login Page'), | |
), | |
body: Padding( | |
padding: const EdgeInsets.all(20.0), | |
child: Form( | |
key: _formKey, | |
child: Column( | |
children: [ | |
const SizedBox(height: 20), | |
TextFormField( | |
decoration: const InputDecoration( | |
labelText: 'Email', | |
border: OutlineInputBorder(), | |
), | |
validator: (value) { | |
if (value == null || value.isEmpty) { | |
return 'Please enter an email'; | |
} | |
return null; | |
}, | |
onSaved: (value) => _email = value!, | |
), | |
const SizedBox(height: 20), | |
TextFormField( | |
obscureText: true, | |
decoration: const InputDecoration( | |
labelText: 'Password', | |
border: OutlineInputBorder(), | |
), | |
validator: (value) { | |
if (value == null || value.isEmpty) { | |
return 'Please enter a password'; | |
} | |
return null; | |
}, | |
onSaved: (value) => _password = value!, | |
), | |
const SizedBox(height: 20), | |
ElevatedButton( | |
onPressed: () { | |
if (_formKey.currentState!.validate()) { | |
_formKey.currentState!.save(); | |
// Add your login logic here | |
// For example, you can call a function to login | |
login(_email, _password); | |
} | |
}, | |
child: const Text('Login'), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
void login(String email, String password) { | |
// Add your login logic here | |
// For example, you can print the email and password to the console | |
print('Email: $email, Password: $password'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment