Created
August 29, 2024 23:02
-
-
Save Lxxyx/fad88462a8d71a988a5e2c778892ed7d 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: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
colorSchemeSeed: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({ | |
super.key, | |
required this.title, | |
}); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
final _formKey = GlobalKey<FormState>(); | |
final _emailController = TextEditingController(); | |
final _passwordController = TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Padding( | |
padding: const EdgeInsets.all(20.0), | |
child: Form( | |
key: _formKey, | |
child: Column( | |
children: [ | |
TextFormField( | |
decoration: const InputDecoration( | |
labelText: 'Email', | |
border: OutlineInputBorder(), | |
), | |
controller: _emailController, | |
validator: (value) { | |
if (value == null || value.isEmpty) { | |
return 'Please enter your email'; | |
} | |
return null; | |
}, | |
), | |
const SizedBox(height: 20), | |
TextFormField( | |
decoration: const InputDecoration( | |
labelText: 'Password', | |
border: OutlineInputBorder(), | |
), | |
obscureText: true, | |
controller: _passwordController, | |
validator: (value) { | |
if (value == null || value.isEmpty) { | |
return 'Please enter your password'; | |
} | |
return null; | |
}, | |
), | |
const SizedBox(height: 20), | |
ElevatedButton( | |
onPressed: () { | |
if (_formKey.currentState!.validate()) { | |
// Call your login API or function here | |
// For example: | |
_login(); | |
} | |
}, | |
child: const Text('Login'), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
void _login() { | |
// Call your login API or function here | |
// For example: | |
print('Logging in with email: ${_emailController.text} and password: ${_passwordController.text}'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment