0% found this document useful (0 votes)
33 views4 pages

Flutter Static Login App Example

The document outlines the development of a Flutter app featuring a login screen that uses static data for user authentication. It includes code snippets for the main application, login screen, and home screen, detailing how to handle user input and navigate between screens. If the user enters the correct credentials, they are redirected to a home screen displaying a welcome message; otherwise, an error message is shown.

Uploaded by

hirparasujal1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views4 pages

Flutter Static Login App Example

The document outlines the development of a Flutter app featuring a login screen that uses static data for user authentication. It includes code snippets for the main application, login screen, and home screen, detailing how to handle user input and navigate between screens. If the user enters the correct credentials, they are redirected to a home screen displaying a welcome message; otherwise, an error message is shown.

Uploaded by

hirparasujal1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Enrollment No : 236470316040

PRACTICAL 27

Aim : Develop a Flutter app for Login using static data. If the User ID and
Password are correct then clicking a login button should open a new screen
showing Username at the center of the new screen.

[Link] :

import 'package:flutter/[Link]';
import 'login_screen.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {


const MyApp({[Link]});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Login App',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: [Link],
),
home: const LoginScreen(), // first screen
);
}
}

login_screen.dart :

import 'package:flutter/[Link]';
import 'home_screen.dart';

class LoginScreen extends StatefulWidget {


const LoginScreen({[Link]});

@override

TDEC/IT/SEM:5/MAD/4351604
Enrollment No : 236470316040

State<LoginScreen> createState() => _LoginScreenState();


}

class _LoginScreenState extends State<LoginScreen> {


// Controllers to read text
final TextEditingController userController = TextEditingController();
final TextEditingController passController = TextEditingController();

// Static login data


final String validUser = "admin";
final String validPass = "1234";

String errorMessage = "";

void checkLogin() {
String user = [Link];
String pass = [Link];

if (user == validUser && pass == validPass) {


// Navigate to Home Screen
[Link](
context,
MaterialPageRoute(
builder: (context) => HomeScreen(username: user),
),
);
} else {
setState(() {
errorMessage = "Invalid User ID or Password!";
});
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Login Page")),
body: Padding(
padding: const [Link](20.0),
child: Column(
mainAxisAlignment: [Link],
children: [
TextField(

TDEC/IT/SEM:5/MAD/4351604
Enrollment No : 236470316040

controller: userController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: "User ID",
),
),
const SizedBox(height: 15),
TextField(
controller: passController,
obscureText: true,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: "Password",
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: checkLogin,
child: const Text("Login"),
),
const SizedBox(height: 10),
Text(
errorMessage,
style: const TextStyle(color: [Link]),
),
],
),
),
);
}
}

home_screen.dart :

import 'package:flutter/[Link]';

class HomeScreen extends StatelessWidget {


final String username;
const HomeScreen({[Link], required [Link]});

@override
Widget build(BuildContext context) {
return Scaffold(

TDEC/IT/SEM:5/MAD/4351604
Enrollment No : 236470316040

appBar: AppBar(title: const Text("Home Page")),


body: Center(
child: Text(
"Welcome, $username!",
style: const TextStyle(fontSize: 24, fontWeight: [Link]),
),
),
);
}
}

OUTPUT :

TDEC/IT/SEM:5/MAD/4351604

You might also like