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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

A new Flutter project.

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

- Material Drawer
- DevTools
- ListView
- NetworkImage

## 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.
8 changes: 5 additions & 3 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 @@ -19,11 +20,12 @@ class MyApp extends StatelessWidget {
darkTheme: ThemeData(
brightness: Brightness.dark,
),
initialRoute: "/",
debugShowCheckedModeBanner: false,
initialRoute: MyRoutes.homeRoute,
routes: {
"/": (context) => LoginPage(),
"/home": (context) => HomePage(),
"/login": (context) => LoginPage()
MyRoutes.homeRoute: (context) => HomePage(),
MyRoutes.loginRoute: (context) => LoginPage()
},
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_catalog/widgets/drawer.dart';

class HomePage extends StatelessWidget {
final int days = 30;
Expand All @@ -14,7 +15,7 @@ class HomePage extends StatelessWidget {
child: Text("Welcome to $days days of flutter by $name"),
),
),
drawer: Drawer(),
drawer: MyDrawer(),
);
}
}
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";
}
70 changes: 70 additions & 0 deletions lib/widgets/drawer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyDrawer extends StatelessWidget {
@override
Widget build(BuildContext context) {
final imageUrl =
"https://avatars.githubusercontent.com/u/12619420?s=460&u=26db98cbde1dd34c7c67b85c240505a436b2c36d&v=4";
return Drawer(
child: Container(
color: Colors.deepPurple,
child: ListView(
padding: EdgeInsets.zero,
children: [
DrawerHeader(
padding: EdgeInsets.zero,
child: UserAccountsDrawerHeader(
margin: EdgeInsets.zero,
accountName: Text("Pawan Kumar"),
accountEmail: Text("mtechviral@gmail.com"),
currentAccountPicture: CircleAvatar(
backgroundImage: NetworkImage(imageUrl),
),
),
),
ListTile(
leading: Icon(
CupertinoIcons.home,
color: Colors.white,
),
title: Text(
"Home",
textScaleFactor: 1.2,
style: TextStyle(
color: Colors.white,
),
),
),
ListTile(
leading: Icon(
CupertinoIcons.profile_circled,
color: Colors.white,
),
title: Text(
"Profile",
textScaleFactor: 1.2,
style: TextStyle(
color: Colors.white,
),
),
),
ListTile(
leading: Icon(
CupertinoIcons.mail,
color: Colors.white,
),
title: Text(
"Email me",
textScaleFactor: 1.2,
style: TextStyle(
color: Colors.white,
),
),
)
],
),
),
);
}
}