import 'package:flutter/material.dart';
class Login extends StatelessWidget {
String username;
String password;
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
Map<String, String> database = {"sumay": "Password12345"};
void login() {
final formState = formKey.currentState;
// If the form is validated and nothing is wrong with it
if (formState.validate()) {
formState.save();
if (database.containsKey(username)) {
if (database[username] == password) {
formKey.currentState.reset();
Navigator.push(context, MaterialPageRoute(builder: (context) => Home()));
}
else {
formKey.currentState.reset();
}
}
else {
formKey.currentState.reset();
}
}
else {
formKey.currentState.reset();
}
}
return Scaffold(
appBar: AppBar(title: Text("Login")),
body: ListView(
children: [
SizedBox(
height: 25,
),
// LOGO
Center(
child: Container(
child: Image.asset("images/logo.png"),
),
),
Form(
key: formKey, // This is the key used to validate the forms input
child: Column(
children: <Widget>[
// USERNAME //
TextFormField(
// This is to define the border and to label the text
decoration: InputDecoration(
labelText: "Username",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0)
)
),
// Checks the user input to see if it is valid
validator: (input) {
if (input.isEmpty) {
return "Please enter a username";
}
return null;
},
// If the validator passed, then save the information
onSaved: (input) => username = input,
),
]
),
);
}
}