Skip to content

Commit

Permalink
it's working kinda good
Browse files Browse the repository at this point in the history
  • Loading branch information
mikezamayias committed Jan 23, 2022
1 parent 89ae618 commit 6291b03
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 148 deletions.
311 changes: 165 additions & 146 deletions lib/pages/phones/view/widgets/phone_specifications_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,88 +32,97 @@ class PhoneSpecificationsCard extends StatelessWidget {
),
child: Padding(
padding: const EdgeInsets.all(21),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Column(
children: [
Expanded(
flex: 1,
child: CachedNetworkImage(
imageUrl: phone.imageUrl,
errorWidget: (context, url, error) => Icon(
Icons.error,
color: Colors.red.shade700,
),
progressIndicatorBuilder: (context, url, downloadProgress) {
return CircularProgressIndicator(
value: downloadProgress.progress,
);
},
fit: BoxFit.contain,
),
),
Expanded(
flex: 3,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// model
SpecificationField(
fieldName: 'Model',
fieldValue: phone.model,
),
// soc
SpecificationField(
fieldName: 'Soc',
fieldValue: phone.soc,
),
// ram
SpecificationField(
fieldName: 'Ram',
fieldValue: '${phone.ram} GB',
),
// storage
SpecificationField(
fieldName: 'Storage',
fieldValue: phone.storage,
),
// screen size
SpecificationField(
fieldName: 'Screen size',
fieldValue: '${phone.screenSize} inch',
),
// camera
SpecificationField(
fieldName: 'Camera',
fieldValue: phone.camera,
),
// sar
SpecificationField(
fieldName: 'SAR',
fieldValue: '${phone.sar} W/kg',
),
// price
SpecificationField(
fieldName: 'Price',
fieldValue: '€${phone.price}',
),
// quantity
SpecificationField(
fieldName: 'Stock',
fieldValue: '${phone.stock}',
),
Center(
child: BusyButton(
title: 'Buy',
onPressed: () {},
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 1,
child: CachedNetworkImage(
imageUrl: phone.imageUrl,
errorWidget: (context, url, error) => Icon(
Icons.error,
color: Colors.red.shade700,
),
progressIndicatorBuilder:
(context, url, downloadProgress) {
return CircularProgressIndicator(
value: downloadProgress.progress,
);
},
fit: BoxFit.contain,
),
],
),
),
Expanded(
flex: 3,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// model
SpecificationField(
fieldName: 'Model',
fieldValue: phone.model,
),
// soc
SpecificationField(
fieldName: 'Soc',
fieldValue: phone.soc,
),
// ram
SpecificationField(
fieldName: 'Ram',
fieldValue: '${phone.ram} GB',
),
// storage
SpecificationField(
fieldName: 'Storage',
fieldValue: phone.storage,
),
// screen size
SpecificationField(
fieldName: 'Screen size',
fieldValue: '${phone.screenSize} inch',
),
// camera
SpecificationField(
fieldName: 'Camera',
fieldValue: phone.camera,
),
// sar
SpecificationField(
fieldName: 'SAR',
fieldValue: '${phone.sar} W/kg',
),
// price
SpecificationField(
fieldName: 'Price',
fieldValue: '€${phone.price}',
),
// quantity
SpecificationField(
fieldName: 'Stock',
fieldValue: '${phone.stock}',
),
],
),
),
],
),
],
BuyPhoneBusyButton(phone: phone),
].map(
(item) {
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 9,
),
child: item,
);
},
).toList(),
),
),
),
Expand Down Expand Up @@ -193,74 +202,7 @@ class PhoneSpecificationsCard extends StatelessWidget {
fieldName: 'Stock',
fieldValue: '${phone.stock}',
),
Center(
child: BusyButton(
title: 'Buy',
onPressed: () {
if (phone.stock > 0) {
if (locator<AuthenticationService>().currentUser !=
null) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('${phone.model} added to cart'),
content:
const Text('This feature is coming soon'),
actions: [
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('You need to be logged in'),
content:
const Text('This feature is coming soon'),
actions: [
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('${phone.model} is out of stock'),
content:
const Text('This feature is coming soon'),
actions: [
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
},
),
),
BuyPhoneBusyButton(phone: phone),
],
),
),
Expand All @@ -269,3 +211,80 @@ class PhoneSpecificationsCard extends StatelessWidget {
}
}
}

class BuyPhoneBusyButton extends StatelessWidget {
const BuyPhoneBusyButton({
Key? key,
required this.phone,
}) : super(key: key);

final PhoneModel phone;

@override
Widget build(BuildContext context) {
return Center(
child: BusyButton(
title: 'Buy',
onPressed: () {
if (phone.stock > 0) {
if (locator<AuthenticationService>().currentUser != null) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('${phone.model} added to cart'),
content: const Text('This feature is coming soon'),
actions: [
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('You need to be logged in'),
content: const Text('This feature is coming soon'),
actions: [
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('${phone.model} is out of stock'),
content: const Text('This feature is coming soon'),
actions: [
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
},
),
);
}
}
4 changes: 2 additions & 2 deletions lib/widgets/busy_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _BusyButtonState extends State<BusyButton> {
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
alignment: Alignment.center,
padding: const EdgeInsets.all(12),
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 21),
decoration: BoxDecoration(
color: widget.enabled ? Colors.orange : Colors.grey[800],
borderRadius: BorderRadius.circular(21),
Expand All @@ -41,7 +41,7 @@ class _BusyButtonState extends State<BusyButton> {
widget.title,
style: Theme.of(context).textTheme.button!.copyWith(
color: Colors.white,
fontWeight: FontWeight.w600,
fontWeight: FontWeight.w700,
fontSize: 18,
),
)
Expand Down

0 comments on commit 6291b03

Please sign in to comment.