Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Readme.md #14

Open
wants to merge 13 commits into
base: day4
Choose a base branch
from
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 15 ([Tutorial](https://www.youtube.com/watch?v=x0yGtUW7YU8&list=PLrjrqTcKCnhTXI2GyPkaQF47inLp6LoIC&index=15))

- JSON Mapping
- Data Class Generator
- Progress Indicator

## 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
97 changes: 97 additions & 0 deletions lib/models/catalog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import 'dart:convert';

class CatalogModel {
static List<Item> items;
}

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,
});

Item copyWith({
int id,
String name,
String desc,
num price,
String color,
String image,
}) {
return Item(
id: id ?? this.id,
name: name ?? this.name,
desc: desc ?? this.desc,
price: price ?? this.price,
color: color ?? this.color,
image: image ?? this.image,
);
}

Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'desc': desc,
'price': price,
'color': color,
'image': image,
};
}

factory Item.fromMap(Map<String, dynamic> map) {
if (map == null) return null;

return Item(
id: map['id'],
name: map['name'],
desc: map['desc'],
price: map['price'],
color: map['color'],
image: map['image'],
);
}

String toJson() => json.encode(toMap());

factory Item.fromJson(String source) => Item.fromMap(json.decode(source));

@override
String toString() {
return 'Item(id: $id, name: $name, desc: $desc, price: $price, color: $color, image: $image)';
}

@override
bool operator ==(Object o) {
if (identical(this, o)) return true;

return o is Item &&
o.id == id &&
o.name == name &&
o.desc == desc &&
o.price == price &&
o.color == color &&
o.image == image;
}

@override
int get hashCode {
return id.hashCode ^
name.hashCode ^
desc.hashCode ^
price.hashCode ^
color.hashCode ^
image.hashCode;
}
}
50 changes: 44 additions & 6 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
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 {
await Future.delayed(Duration(seconds: 2));
final catalogJson =
await rootBundle.loadString("assets/files/catalog.json");
final decodedData = jsonDecode(catalogJson);
var productsData = decodedData["products"];
CatalogModel.items = List.from(productsData)
.map<Item>((item) => Item.fromMap(item))
.toList();
setState(() {});
}

@override
Widget build(BuildContext context) {
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: (CatalogModel.items != null && CatalogModel.items.isNotEmpty)
? ListView.builder(
itemCount: CatalogModel.items.length,
itemBuilder: (context, index) => ItemWidget(
item: CatalogModel.items[index],
),
)
: Center(
child: CircularProgressIndicator(),
),
),
drawer: Drawer(),
drawer: MyDrawer(),
);
}
}
Loading