Enhancement: back button to main menu reload

This commit is contained in:
2024-06-04 15:57:17 +03:00
parent eaa8b138a4
commit 1e5b235a6c
4 changed files with 48 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ import 'package:gymlink_module_web/components/app_bar.dart';
import 'package:gymlink_module_web/components/basket_item_card.dart';
import 'package:gymlink_module_web/components/heading.dart';
import 'package:gymlink_module_web/interfaces/items.dart';
import 'package:gymlink_module_web/pages/main.dart';
import 'package:gymlink_module_web/pages/order_confirmation.dart';
import 'package:gymlink_module_web/providers/cart.dart';
import 'package:gymlink_module_web/tools/items.dart';
@@ -244,7 +245,11 @@ class _BasketPageState extends State<BasketPage> {
style: Theme.of(context).textTheme.bodyLarge),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => Navigator.pop(context, true),
onPressed: () => Navigator.pushAndRemoveUntil(
context,
CustomPageRoute(
builder: (_) => const MainPage()),
(route) => route.isFirst),
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor,
shape: const RoundedRectangleBorder(

View File

@@ -3,6 +3,7 @@ import 'dart:math';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:gymlink_module_web/components/app_bar.dart';
import 'package:gymlink_module_web/components/heading.dart';
import 'package:gymlink_module_web/interfaces/items.dart';
@@ -30,7 +31,7 @@ class _DetailPageState extends State<DetailPage> {
bool isInCart = false;
int quantity = 0;
GymItem? item;
String categoryName = '';
String? categoryName;
final CarouselController _carouselController = CarouselController();
int _currentImage = 0;
@@ -68,12 +69,14 @@ class _DetailPageState extends State<DetailPage> {
});
if (mounted) {
getCategories(context).then((value) {
categoryName = value
.firstWhere(
(element) => element.id == (item!.categoryId),
orElse: () => GymCategory(id: item!.categoryId, name: ''),
)
.name;
setState(() {
categoryName = value
.firstWhere(
(element) => element.id == (item!.categoryId),
orElse: () => GymCategory(id: item!.categoryId, name: ''),
)
.name;
});
});
}
}
@@ -147,10 +150,12 @@ class _DetailPageState extends State<DetailPage> {
IconButton(
icon: const Icon(Icons.add),
onPressed: () async {
await addItemToCart(widget.id);
setState(() {
quantity++;
});
if (item!.count > quantity) {
await addItemToCart(widget.id);
setState(() {
quantity++;
});
}
},
),
],
@@ -260,15 +265,21 @@ class _DetailPageState extends State<DetailPage> {
}).toList(),
),
])
: Image.network(item!.images[0].url,
width: min(
550, MediaQuery.sizeOf(context).width)),
: Image.network(
item!.images[0].url,
height: 400,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Center(
child: Text(
'Категория: ${categoryName == "" ? "Без категории" : categoryName}'),
child: Text(categoryName != null
? 'Категория: ${categoryName == "" ? "Без категории" : categoryName}'
: ''),
)),
Center(
child: MarkdownBody(
data: '### Отстаток: _${item!.count}_',
)),
item!.description != ''
? Padding(
padding: const EdgeInsetsDirectional.all(30),

View File

@@ -91,7 +91,10 @@ class _HistoryPageState extends State<HistoryPage> {
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const GymLinkHeader(title: 'История заказов'),
const GymLinkHeader(
title: 'История заказов',
toMain: true,
),
Expanded(
child: Row(
children: [