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

@@ -1,8 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gymlink_module_web/pages/main.dart';
import 'package:gymlink_module_web/tools/routes.dart';
class GymLinkHeader extends StatelessWidget { class GymLinkHeader extends StatelessWidget {
final String title; final String title;
const GymLinkHeader({super.key, required this.title}); final bool toMain;
const GymLinkHeader({super.key, required this.title, this.toMain = false});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -13,7 +16,13 @@ class GymLinkHeader extends StatelessWidget {
Row( Row(
children: [ children: [
IconButton( IconButton(
onPressed: () => Navigator.pop(context), onPressed: () => toMain
? Navigator.pushAndRemoveUntil(
context,
CustomPageRoute(
builder: (context) => const MainPage()),
(route) => route.isFirst)
: Navigator.pop(context),
icon: const Icon(Icons.arrow_back)), icon: const Icon(Icons.arrow_back)),
Text(title, style: Theme.of(context).textTheme.titleLarge), Text(title, style: Theme.of(context).textTheme.titleLarge),
], ],

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

View File

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

View File

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