Skip to content
Open

Day4 #35

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

- Hero Animations
- MaterialPageRoute
- Arc

## 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://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.
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"
6 changes: 6 additions & 0 deletions 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
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

Expand Down
23 changes: 14 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_catalog/pages/login_page.dart';
import 'package:flutter_catalog/utils/routes.dart';
import 'pages/home_page.dart';
import 'widgets/themes.dart';

void main() {
runApp(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.light,
theme: MyTheme.lightTheme(context),
darkTheme: MyTheme.darkTheme(context),
debugShowCheckedModeBanner: false,
initialRoute: MyRoutes.homeRoute,
routes: {
"/": (context) => LoginPage(),
MyRoutes.homeRoute: (context) => HomePage(),
MyRoutes.loginRoute: (context) => LoginPage()
},
);
}
}
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;
}
}
71 changes: 71 additions & 0 deletions lib/pages/home_detail_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:flutter_catalog/models/catalog.dart';
import 'package:flutter_catalog/widgets/themes.dart';
import 'package:velocity_x/velocity_x.dart';

class HomeDetailPage extends StatelessWidget {
final Item catalog;

const HomeDetailPage({Key key, @required this.catalog})
: assert(catalog != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
backgroundColor: MyTheme.creamColor,
bottomNavigationBar: Container(
color: Colors.white,
child: ButtonBar(
alignment: MainAxisAlignment.spaceBetween,
buttonPadding: EdgeInsets.zero,
children: [
"\$${catalog.price}".text.bold.xl4.red800.make(),
ElevatedButton(
onPressed: () {},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
MyTheme.darkBluishColor,
),
shape: MaterialStateProperty.all(
StadiumBorder(),
)),
child: "Buy".text.make(),
).wh(100, 50)
],
).p32(),
),
body: SafeArea(
bottom: false,
child: Column(
children: [
Hero(
tag: Key(catalog.id.toString()),
child: Image.network(catalog.image),
).h32(context),
Expanded(
child: VxArc(
height: 30.0,
arcType: VxArcType.CONVEY,
edge: VxEdge.TOP,
child: Container(
color: Colors.white,
width: context.screenWidth,
child: Column(
children: [
catalog.name.text.xl4
.color(MyTheme.darkBluishColor)
.bold
.make(),
catalog.desc.text.textStyle(context.captionStyle).xl.make(),
10.heightBox,
],
).py64(),
),
))
],
),
),
);
}
}
58 changes: 58 additions & 0 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +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/home_widgets/catalog_header.dart';
import 'package:flutter_catalog/widgets/home_widgets/catalog_list.dart';
import 'package:flutter_catalog/widgets/themes.dart';
import 'package:velocity_x/velocity_x.dart';

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(
backgroundColor: MyTheme.creamColor,
body: SafeArea(
child: Container(
padding: Vx.m32,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CatalogHeader(),
if (CatalogModel.items != null && CatalogModel.items.isNotEmpty)
CatalogList().py16().expand()
else
CircularProgressIndicator().centered().expand(),
],
),
),
));
}
}
Loading