Add: getting products from API

This commit is contained in:
2024-05-22 15:46:09 +03:00
parent 46ba11cd57
commit 7907dcf6c2
6 changed files with 399 additions and 237 deletions

View File

@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:gymlink_module_web/components/app_bar.dart';
import 'package:gymlink_module_web/components/heading.dart';
import 'package:gymlink_module_web/pages/basket.dart';
import 'package:gymlink_module_web/providers/cart.dart';
import 'package:gymlink_module_web/tools/prefs.dart';
import 'package:gymlink_module_web/tools/routes.dart';
import 'package:provider/provider.dart';
//TODO: Сделать получение инфы через объект
@@ -83,38 +85,59 @@ class _DetailPageState extends State<DetailPage> {
child: const Text('Добавить в корзину'),
);
} else {
return Row(
mainAxisSize: MainAxisSize.min,
return Column(
children: [
IconButton(
icon: const Icon(Icons.remove),
onPressed: () async {
await removeItemFromCart(widget.id);
setState(() {
if (quantity > 1) {
quantity--;
} else {
isInCart = false;
quantity = 0;
}
});
if (mounted) {
context.read<CartProvider>().updateCartLength();
}
},
),
const SizedBox(width: 10),
Text('$quantity'),
const SizedBox(width: 10),
IconButton(
icon: const Icon(Icons.add),
onPressed: () async {
await addItemToCart(widget.id);
setState(() {
quantity++;
});
},
Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.remove),
onPressed: () async {
await removeItemFromCart(widget.id);
setState(() {
if (quantity > 1) {
quantity--;
} else {
isInCart = false;
quantity = 0;
}
});
if (mounted) {
context.read<CartProvider>().updateCartLength();
}
},
),
const SizedBox(width: 10),
Text('$quantity'),
const SizedBox(width: 10),
IconButton(
icon: const Icon(Icons.add),
onPressed: () async {
await addItemToCart(widget.id);
setState(() {
quantity++;
});
},
),
],
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: ElevatedButton(
onPressed: () {
Navigator.pushReplacement(context,
CustomPageRoute(builder: (context) => const BasketPage()));
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(50)),
),
foregroundColor: Colors.white,
),
child: const Text('Открыть корзину'),
),
)
],
);
}
@@ -139,37 +162,43 @@ class _DetailPageState extends State<DetailPage> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
widget.image,
Padding(
padding: const EdgeInsetsDirectional.all(30),
child: ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 340,
maxWidth: 340,
maxHeight: 600,
),
child: Card(
elevation: 4,
color: Theme.of(context).scaffoldBackgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsetsDirectional.all(15),
child: ConstrainedBox(
constraints: const BoxConstraints(
minHeight: 100,
widget.description != ''
? Padding(
padding: const EdgeInsetsDirectional.all(30),
child: ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 340,
maxWidth: 340,
maxHeight: 600,
),
child: Card(
elevation: 4,
color:
Theme.of(context).scaffoldBackgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Text(
widget.description,
style: Theme.of(context).textTheme.bodyMedium,
child: SingleChildScrollView(
child: Padding(
padding:
const EdgeInsetsDirectional.all(15),
child: ConstrainedBox(
constraints: const BoxConstraints(
minHeight: 100,
),
child: Text(
widget.description,
style: Theme.of(context)
.textTheme
.bodyMedium,
),
),
),
),
),
),
),
),
),
),
)
: const SizedBox.shrink(),
Align(
alignment: const AlignmentDirectional(0, -1),
child: Padding(
@@ -179,7 +208,7 @@ class _DetailPageState extends State<DetailPage> {
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Стоимость ${widget.price}',
'Стоимость ${widget.price}руб.',
style: Theme.of(context).textTheme.bodyLarge,
),
_buildButton()