Add: CartProvider

This commit is contained in:
2024-05-15 13:49:18 +03:00
parent e52357edf5
commit c54176212a
5 changed files with 89 additions and 54 deletions

View File

@@ -6,10 +6,12 @@ import 'package:gymlink_module_web/components/item_card.dart';
import 'package:gymlink_module_web/pages/basket.dart';
import 'package:gymlink_module_web/pages/detail.dart';
import 'package:gymlink_module_web/pages/order_history.dart';
import 'package:gymlink_module_web/providers/cart.dart';
import 'package:gymlink_module_web/tools/prefs.dart';
import 'package:gymlink_module_web/tools/relative.dart';
import 'package:gymlink_module_web/tools/routes.dart';
import 'package:lazy_load_scrollview/lazy_load_scrollview.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
const List<Map<String, String>> testData = [
@@ -105,6 +107,7 @@ class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) {
final cartL = context.watch<CartProvider>().cartLength;
return Scaffold(
appBar: widget.isLoading ? null : const GymLinkAppBar(),
body: widget.isLoading
@@ -233,50 +236,49 @@ class _MainPageState extends State<MainPage> {
),
],
),
floatingActionButton: SizedBox(
height: 80,
width: 80,
child: FittedBox(
child: Stack(
children: [
FloatingActionButton(
onPressed: () => Navigator.of(context).push(CustomPageRoute(
builder: (context) => const BasketPage(),
)),
backgroundColor: Colors.transparent,
elevation: 0,
child: CircleAvatar(
radius: 25,
backgroundColor: Theme.of(context).primaryColor,
foregroundColor: Colors.white,
child: const Icon(Icons.shopping_cart_outlined)),
),
/**
* Загадочная штука, надо переделать
* TODO: По идее надо через провайдер сделать, но не пойму как это сделать
*/
cartLength > 0
? Positioned(
right: -3,
bottom: 0,
child: Card(
color: Colors.red,
child: SizedBox(
width: 20,
child: Center(
child: Text(
cartLength.toString(),
style: const TextStyle(color: Colors.white),
floatingActionButton: !widget.isLoading
? SizedBox(
height: 80,
width: 80,
child: FittedBox(
child: Stack(
children: [
FloatingActionButton(
onPressed: () =>
Navigator.of(context).push(CustomPageRoute(
builder: (context) => const BasketPage(),
)),
backgroundColor: Colors.transparent,
elevation: 0,
child: CircleAvatar(
radius: 25,
backgroundColor: Theme.of(context).primaryColor,
foregroundColor: Colors.white,
child: const Icon(Icons.shopping_cart_outlined)),
),
cartL > 0
? Positioned(
right: -3,
bottom: 0,
child: Card(
color: Colors.red,
child: SizedBox(
width: 20,
child: Center(
child: Text(
cartL.toString(),
style: const TextStyle(color: Colors.white),
),
),
),
),
),
),
),
)
: const SizedBox.shrink(),
],
),
),
),
)
: const SizedBox.shrink(),
],
),
),
)
: null,
floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,
);
}