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
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://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/iphone-12-pro-blue-hero?wid=940&hei=1112&fmt=png-alpha&qlt=80&.v=1604021661000"
},
{
"id": 2,
"name": "Pixel 5",
"desc": "Google Pixel phone 5th generation",
"price": 699,
"color": "#00ac51",
"image": "https://www.telstra.com.au/content/dam/tcom/lego/2020/plans-devices/mobiles/google-pixel-5/shared-google-pixel-5-black-05-900x1200.png"
},
{
"id": 3,
"name": "M1 Macbook Air",
"desc": "Apple Macbook air with apple silicon",
"price": 1099,
"color": "#e0bfae",
"image": "https://support.apple.com/library/APPLE/APPLECARE_ALLGEOS/SP825/macbookair.png"
},
{
"id": 4,
"name": "Playstation 5",
"desc": "Sony Playstation 5th generation",
"price": 500,
"color": "#544ee4",
"image": "https://i1.wp.com/freepngimages.com/wp-content/uploads/2020/07/Playstation-5-games-console-transparent-background-png-image.png?fit=1000%2C1000"
},
{
"id": 5,
"name": "Airpods Pro",
"desc": "Apple Aipods Pro 1st generation",
"price": 200,
"color": "#e3e4e9",
"image": "https://crdms.images.consumerreports.org/c_lfill,w_598/prod/products/cr/models/400116-wireless-portable-headphones-apple-airpods-pro-10009323.png"
},
{
"id": 6,
"name": "iPad Pro",
"desc": "Apple iPad Pro 2020 edition",
"price": 799,
"color": "#f73984",
"image": "https://store.storeimages.cdn-apple.com/4982/as-images.apple.com/is/ipad-pro-12-select-wifi-silver-202003_FMT_WHH?wid=940&hei=1112&fmt=png-alpha&qlt=80&.v=1583551131102"
},
{
"id": 7,
"name": "Galaxy S21 Ultra",
"desc": "Samsung Galaxy S21 Ultra 2021 edition",
"price": 1299,
"color": "#1c1c1c",
"image": "https://lh3.googleusercontent.com/qRQPjHrhRVIs-xnfNSyiPXOH2vH97ylMacgbTKebqJtRfNH3LlYo8pN-5igsLDWUH62tGl5zNpTsl5xd8SprzGmXoCEmWFOi2-2cQVGS-r3PaRXHt62DmJHq-jrYX0UQvWZ9BA=s800-c"
},
{
"id": 8,
"name": "Galaxy S21",
"desc": "Samsung Galaxy S21 2021 edition",
"price": 899,
"color": "#7c95eb",
"image": "https://images.samsung.com/is/image/samsung/p6pim/za/galaxy-s21/gallery/za-clear-cover-galaxy-s21-5g-ef-qg991ttegww-363168624?$720_576_PNG$"
}
]
}
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.
Binary file added assets/images/login_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 0 additions & 36 deletions integration_test/app_test.dart

This file was deleted.

8 changes: 0 additions & 8 deletions integration_test/driver.dart

This file was deleted.

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"
8 changes: 7 additions & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ PODS:
- Flutter (1.0.0)
- integration_test (0.0.1):
- Flutter
- path_provider (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
path_provider:
:path: ".symlinks/plugins/path_provider/ios"

SPEC CHECKSUMS:
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
integration_test: 5ed24a436eb7ec17b6a13046e9bf7ca4a404e59e
integration_test: 6eb66a19f7104200dcfdd62bc0077e1b09686e4f
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions lib/core/store.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter_catalog/models/cart.dart';
import 'package:flutter_catalog/models/catalog.dart';
import 'package:velocity_x/velocity_x.dart';

class MyStore extends VxStore {
CatalogModel catalog;
CartModel cart;

MyStore() {
catalog = CatalogModel();
cart = CartModel();
cart.catalog = catalog;
}
}
29 changes: 19 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import 'package:flutter/material.dart';
import 'package:flutter_catalog/core/store.dart';
import 'package:flutter_catalog/pages/cart_page.dart';
import 'package:flutter_catalog/pages/login_page.dart';
import 'package:flutter_catalog/utils/routes.dart';
import 'package:velocity_x/velocity_x.dart';
import 'pages/home_page.dart';
import 'widgets/themes.dart';

void main() {
runApp(MyApp());
runApp(VxState(store: MyStore(), child: MyApp()));
}

class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Material(
child: Center(
child: Container(
child: Text("Welcome to 30 days of flutter"),
),
),
),
themeMode: ThemeMode.system,
theme: MyTheme.lightTheme(context),
darkTheme: MyTheme.darkTheme(context),
debugShowCheckedModeBanner: false,
initialRoute: MyRoutes.homeRoute,
routes: {
"/": (context) => LoginPage(),
MyRoutes.homeRoute: (context) => HomePage(),
MyRoutes.loginRoute: (context) => LoginPage(),
MyRoutes.cartRoute: (context) => CartPage(),
},
);
}
}
46 changes: 46 additions & 0 deletions lib/models/cart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter_catalog/core/store.dart';
import 'package:flutter_catalog/models/catalog.dart';
import 'package:velocity_x/velocity_x.dart';

class CartModel {
// catalog field
CatalogModel _catalog;

// Collection of IDs - store Ids of each item
final List<int> _itemIds = [];

// Get Catalog
CatalogModel get catalog => _catalog;

set catalog(CatalogModel newCatalog) {
assert(newCatalog != null);
_catalog = newCatalog;
}

// Get items in the cart
List<Item> get items => _itemIds.map((id) => _catalog.getById(id)).toList();

// Get total price
num get totalPrice =>
items.fold(0, (total, current) => total + current.price);
}

class AddMutation extends VxMutation<MyStore> {
final Item item;

AddMutation(this.item);
@override
perform() {
store.cart._itemIds.add(item.id);
}
}

class RemoveMutation extends VxMutation<MyStore> {
final Item item;

RemoveMutation(this.item);
@override
perform() {
store.cart._itemIds.remove(item.id);
}
}
104 changes: 104 additions & 0 deletions lib/models/catalog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'dart:convert';

class CatalogModel {
static List<Item> items;

// Get Item by ID
Item getById(int id) =>
items.firstWhere((element) => element.id == id, orElse: null);

// Get Item by position
Item getByPosition(int pos) => items[pos];
}

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;
}
}
Loading