Created
August 29, 2024 23:05
-
-
Save Lxxyx/4cb80b9a562200a4e2eac11ab4c52650 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 _emailController = TextEditingController(); | |
final _passwordController = TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Login Page'), | |
), | |
body: Padding( | |
padding: const EdgeInsets.all(20.0), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
TextField( | |
controller: _emailController, | |
decoration: const InputDecoration( | |
labelText: 'Email', | |
border: OutlineInputBorder(), | |
), | |
), | |
const SizedBox(height: 20), | |
TextField( | |
controller: _passwordController, | |
obscureText: true, | |
decoration: const InputDecoration( | |
labelText: 'Password', | |
border: OutlineInputBorder(), | |
), | |
), | |
const SizedBox(height: 20), | |
ElevatedButton( | |
onPressed: () { | |
// Add login logic here | |
// For example, you can call a function to validate the inputs | |
_login(); | |
}, | |
child: const Text('Login'), | |
), | |
], | |
), | |
), | |
); | |
} | |
void _login() { | |
final email = _emailController.text; | |
final password = _passwordController.text; | |
// Add your login logic here | |
// For example, you can call an API to authenticate the user | |
// If the login is successful, you can navigate to the next page | |
if (email.isNotEmpty && password.isNotEmpty) { | |
// Navigate to the next page | |
Navigator.pushReplacement( | |
context, | |
MaterialPageRoute(builder: (context) => const HomePage()), | |
); | |
} else { | |
// Show an error message | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar(content: Text('Please enter email and password')), | |
); | |
} | |
} | |
} | |
class HomePage extends StatelessWidget { | |
const HomePage({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Home Page'), | |
), | |
body: const Center( | |
child: Text('Welcome to the home page!'), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment