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 13 ([Tutorial](https://www.youtube.com/watch?v=t8gd1ZmybiQ&list=PLrjrqTcKCnhTXI2GyPkaQF47inLp6LoIC&index=13))

- Local Files
- Load
- Decode JSON

## Getting Started

This project is a starting point for a Flutter application.
Expand Down
68 changes: 68 additions & 0 deletions assets/files/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"products": [
{
"id": 1,
"name": "iPhone 12 Pro",
"desc": "Apple iPhone 12th generation",
"price": 999,
"color": "#33505a",
"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRISJ6msIu4AU9_M9ZnJVQVFmfuhfyJjEtbUm3ZK11_8IV9TV25-1uM5wHjiFNwKy99w0mR5Hk&usqp=CAc"
},
{
"id": 2,
"name": "Pixel 5",
"desc": "Google Pixel phone 5th generation",
"price": 699,
"color": "#00ac51",
"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSd0JhwLvm_uLDLc-la7hK9WyVpe9naJFcebKfhcICiq2KtvXDePNAU_9QO06LPcQ0K0fLByc7m&usqp=CAc"
},
{
"id": 3,
"name": "M1 Macbook Air",
"desc": "Apple Macbook air with apple silicon",
"price": 1099,
"color": "#e0bfae",
"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSMOMstwtmLnjFb3NHiDJ_kcQnueNVH-rv_3ps96HZmXlFumKWaiBqq_L4Uoyx3iFiNTrXNEbyB&usqp=CAc"
},
{
"id": 4,
"name": "Playstation 5",
"desc": "Sony Playstation 5th generation",
"price": 500,
"color": "#544ee4",
"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSMOMstwtmLnjFb3NHiDJ_kcQnueNVH-rv_3ps96HZmXlFumKWaiBqq_L4Uoyx3iFiNTrXNEbyB&usqp=CAc"
},
{
"id": 5,
"name": "Airpods Pro",
"desc": "Apple Aipods Pro 1st generation",
"price": 200,
"color": "#e3e4e9",
"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQROEs084z65psoo06zYl5R0tUzywOVKVQZzmzqCj3PDP1vVJTWv3gGwGMFENSy4qV4n7sEQjE&usqp=CAc"
},
{
"id": 6,
"name": "iPad Pro",
"desc": "Apple iPad Pro 2020 edition",
"price": 799,
"color": "#f73984",
"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSNzUeRQ5uH7E3hpECib8qxdhfHv6SnUGT7mOsew_xiOoqRR7ZpdH-TQ4J6-HuIEfqHimYyPXWH&usqp=CAc"
},
{
"id": 7,
"name": "Galaxy S21 Ultra",
"desc": "Samsung Galaxy S21 Ultra 2021 edition",
"price": 1299,
"color": "#1c1c1c",
"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTT_PZcc0wicVYR992s5QCIDLYy8t-z-9kibTUdWZBN2sd86aaqdAJfhvxAwZNWV9wfdzDikpr1&usqp=CAc"
},
{
"id": 8,
"name": "Galaxy S21",
"desc": "Samsung Galaxy S21 2021 edition",
"price": 899,
"color": "#7c95eb",
"image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRBNHd7FwarbxA1xdMFt24KazjcR4dWPH_t_T5dz4YNK1s7rJAQ8gOIuR_NRw6eeiQgFhbZ9sAN&usqp=CAc"
}
]
}
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.
2 changes: 1 addition & 1 deletion integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:integration_test/integration_test.dart';

import 'package:flutter_catalog/main.dart' as app;

void main() => run(_testMain);
// void main() => run(_testMain);

void _testMain() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
Expand Down
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
19 changes: 8 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_catalog/pages/login_page.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:flutter_catalog/utils/routes.dart';
import 'pages/home_page.dart';
import 'widgets/themes.dart';

void main() {
runApp(MyApp());
Expand All @@ -12,18 +13,14 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
themeMode: ThemeMode.light,
theme: ThemeData(
primarySwatch: Colors.deepPurple,
fontFamily: GoogleFonts.lato().fontFamily,
),
darkTheme: ThemeData(
brightness: Brightness.dark,
),
initialRoute: "/",
theme: MyTheme.lightTheme(context),
darkTheme: MyTheme.darkTheme(context),
debugShowCheckedModeBanner: false,
initialRoute: MyRoutes.homeRoute,
routes: {
"/": (context) => LoginPage(),
"/home": (context) => HomePage(),
"/login": (context) => LoginPage()
MyRoutes.homeRoute: (context) => HomePage(),
MyRoutes.loginRoute: (context) => LoginPage()
},
);
}
Expand Down
23 changes: 23 additions & 0 deletions lib/models/catalog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class CatalogModel {
static final items = [
Item(
id: 1,
name: "iPhone 12 Pro",
desc: "Apple iPhone 12th generation",
price: 999,
color: "#33505a",
image:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRISJ6msIu4AU9_M9ZnJVQVFmfuhfyJjEtbUm3ZK11_8IV9TV25-1uM5wHjiFNwKy99w0mR5Hk&usqp=CAc")
];
}

class Item {
final int id;
final String name;
final String desc;
final num price;
final String color;
final String image;

Item({this.id, this.name, this.desc, this.price, this.color, this.image});
}
43 changes: 38 additions & 5 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:convert';
import 'package:flutter_catalog/models/catalog.dart';
import 'package:flutter_catalog/widgets/drawer.dart';
import 'package:flutter_catalog/widgets/item_widget.dart';

class HomePage extends StatelessWidget {
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
final int days = 30;

final String name = "Codepur";

@override
void initState() {
super.initState();
loadData();
}

loadData() async {
final catalogJson =
await rootBundle.loadString("assets/files/catalog.json");
final decodedData = jsonDecode(catalogJson);
var productsData = decodedData["products"];
print(productsData);
}

@override
Widget build(BuildContext context) {
final dummyList = List.generate(20, (index) => CatalogModel.items[0]);
return Scaffold(
appBar: AppBar(
title: Text("Catalog App"),
),
body: Center(
child: Container(
child: Text("Welcome to $days days of flutter by $name"),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: ListView.builder(
itemCount: dummyList.length,
itemBuilder: (context, index) {
return ItemWidget(
item: dummyList[index],
);
},
),
),
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");
},
)
],
),
)
],
)
],
),
),
));
}
}
Loading