Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

A new Flutter project.

# Content of DAY 8 ([Tutorial](https://www.youtube.com/watch?v=FnEIq-k07HM&list=PLrjrqTcKCnhTXI2GyPkaQF47inLp6LoIC&index=8))

- Form
- TextField Validation
- Ink

## Getting Started

This project is a starting point for a Flutter application.
Expand Down
Binary file added assets/images/hey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_catalog/pages/login_page.dart';
import 'package:flutter_catalog/utils/routes.dart';
import 'package:google_fonts/google_fonts.dart';
import 'pages/home_page.dart';

Expand All @@ -22,8 +23,8 @@ class MyApp extends StatelessWidget {
initialRoute: "/",
routes: {
"/": (context) => LoginPage(),
"/home": (context) => HomePage(),
"/login": (context) => LoginPage()
MyRoutes.homeRoute: (context) => HomePage(),
MyRoutes.loginRoute: (context) => LoginPage()
},
);
}
Expand Down
168 changes: 118 additions & 50 deletions lib/pages/login_page.dart
Original file line number Diff line number Diff line change
@@ -1,61 +1,129 @@
import 'package:flutter/material.dart';
import 'package:flutter_catalog/utils/routes.dart';

class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
String name = "";
bool changeButton = false;

final _formKey = GlobalKey<FormState>();

moveToHome(BuildContext context) async {
if (_formKey.currentState.validate()) {
setState(() {
changeButton = true;
});
await Future.delayed(Duration(seconds: 1));
await Navigator.pushNamed(context, MyRoutes.homeRoute);
setState(() {
changeButton = false;
});
}
}

class LoginPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Material(
color: Colors.white,
child: Column(
children: [
Image.asset(
"assets/images/login_image.png",
fit: BoxFit.cover,
),
SizedBox(
height: 20.0,
),
Text(
"Welcome",
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 20.0,
),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 32.0),
child: Column(
children: [
TextFormField(
decoration: InputDecoration(
hintText: "Enter username",
labelText: "Username",
),
),
TextFormField(
obscureText: true,
decoration: InputDecoration(
hintText: "Enter password",
labelText: "Password",
),
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
children: [
Image.asset(
"assets/images/hey.png",
fit: BoxFit.cover,
),
SizedBox(
height: 20.0,
),
Text(
"Welcome $name",
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
),
SizedBox(
height: 20.0,
),
SizedBox(
height: 20.0,
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 16.0, horizontal: 32.0),
child: Column(
children: [
TextFormField(
decoration: InputDecoration(
hintText: "Enter username",
labelText: "Username",
),
validator: (value) {
if (value.isEmpty) {
return "Username cannot be empty";
}

return null;
},
onChanged: (value) {
name = value;
setState(() {});
},
),
TextFormField(
obscureText: true,
decoration: InputDecoration(
hintText: "Enter password",
labelText: "Password",
),
validator: (value) {
if (value.isEmpty) {
return "Password cannot be empty";
} else if (value.length < 6) {
return "Password length should be atleast 6";
}

return null;
},
),
SizedBox(
height: 40.0,
),
Material(
color: Colors.deepPurple,
borderRadius:
BorderRadius.circular(changeButton ? 50 : 8),
child: InkWell(
onTap: () => moveToHome(context),
child: AnimatedContainer(
duration: Duration(seconds: 1),
width: changeButton ? 50 : 150,
height: 50,
alignment: Alignment.center,
child: changeButton
? Icon(
Icons.done,
color: Colors.white,
)
: Text(
"Login",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18),
),
),
),
),
],
),
ElevatedButton(
child: Text("Login"),
style: TextButton.styleFrom(),
onPressed: () {
print("Hi Codepur");
},
)
],
),
)
],
)
],
),
),
));
}
}
4 changes: 4 additions & 0 deletions lib/utils/routes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class MyRoutes {
static String loginRoute = "/login";
static String homeRoute = "/home";
}