diff --git a/lib/components/basket_item_card.dart b/lib/components/basket_item_card.dart index 3fd4076..ae8ca4f 100644 --- a/lib/components/basket_item_card.dart +++ b/lib/components/basket_item_card.dart @@ -6,7 +6,7 @@ class BasketItemCard extends StatelessWidget { final String name; final String price; final String id; - final Image image; + final Widget image; final String quantity; final VoidCallback onTapPlus; final VoidCallback onTapMinus; diff --git a/lib/components/item_card.dart b/lib/components/item_card.dart index c9b7f01..067cef7 100644 --- a/lib/components/item_card.dart +++ b/lib/components/item_card.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class ProductCard extends StatelessWidget { - final Image imagePath; + final Widget imagePath; final String name; final String price; final VoidCallback onTap; diff --git a/lib/components/order_confirm_item_card.dart b/lib/components/order_confirm_item_card.dart index afb3b0e..f92a050 100644 --- a/lib/components/order_confirm_item_card.dart +++ b/lib/components/order_confirm_item_card.dart @@ -5,7 +5,7 @@ class OrderConfirmItemCard extends StatelessWidget { final String name; final int count; final double price; - final Image image; + final Widget image; const OrderConfirmItemCard({ super.key, diff --git a/lib/pages/basket.dart b/lib/pages/basket.dart index f8ec976..2de1189 100644 --- a/lib/pages/basket.dart +++ b/lib/pages/basket.dart @@ -283,9 +283,22 @@ class _BasketPageState extends State { name: shortString(item.title), price: item.price.toStringAsFixed(2), id: item.id, - image: Image( - image: NetworkImage(item.images[0].url), - width: 50, + image: FutureBuilder( + future: precacheImage( + NetworkImage(item.images[0].url), + context), + builder: (context, snapshot) { + if (snapshot.connectionState == + ConnectionState.done) { + return Image( + image: NetworkImage( + item.images[0].url), + width: 50, + ); + } else { + return const CircularProgressIndicator(); + } + }, ), onTapPlus: () => addItem(item.id.toString()), diff --git a/lib/pages/main.dart b/lib/pages/main.dart index 4d17e98..b7c9877 100644 --- a/lib/pages/main.dart +++ b/lib/pages/main.dart @@ -111,7 +111,6 @@ class _MainPageState extends State { setState(() { filteredData = data; itemViewCount = min(filteredData.length, 5); - debugPrint(itemViewCount.toString()); }); WidgetsBinding.instance.addPostFrameCallback((_) { for (var element in filteredData.sublist(0, itemViewCount)) { @@ -281,11 +280,22 @@ class _MainPageState extends State { itemBuilder: (context, index) { final product = filteredData[index]; return ProductCard( - imagePath: Image( - image: - Image.network(product.images[0].url) - .image, - width: 120, + imagePath: FutureBuilder( + future: precacheImage( + NetworkImage(product.images[0].url), + context), + builder: (context, snapshot) { + if (snapshot.connectionState == + ConnectionState.done) { + return Image( + image: NetworkImage( + product.images[0].url), + width: 120, + ); + } else { + return const CircularProgressIndicator(); + } + }, ), name: shortString(product.title), price: product.price.toStringAsFixed(2), diff --git a/lib/pages/order_confirmation.dart b/lib/pages/order_confirmation.dart index 8231096..520470d 100644 --- a/lib/pages/order_confirmation.dart +++ b/lib/pages/order_confirmation.dart @@ -87,7 +87,7 @@ class _OrderConfirmationPageState extends State { } Future _goToPage() async { - final Uri url = Uri.parse('https://google.com'); + final Uri url = Uri.parse('https://example.org'); if (!await launchUrl(url, webOnlyWindowName: '_blank')) { throw 'Could not launch $url'; } @@ -115,10 +115,22 @@ class _OrderConfirmationPageState extends State { final item = cartItems[index]; return OrderConfirmItemCard( name: shortString(item.title), - image: Image( - image: NetworkImage(item.images[0].url), - width: 50, - height: 50), + image: FutureBuilder( + future: precacheImage( + NetworkImage(item.images[0].url), context), + builder: (context, snapshot) { + if (snapshot.connectionState == + ConnectionState.done) { + return Image( + image: NetworkImage(item.images[0].url), + width: 50, + height: 50, + ); + } else { + return const CircularProgressIndicator(); + } + }, + ), price: item.price, count: item.localCount, ); @@ -165,15 +177,6 @@ class _OrderConfirmationPageState extends State { ), ), ), - CheckboxListTile( - title: const Text('Согласен с обаботкой персональных данных'), - value: isAgree, - onChanged: (value) { - setState(() { - isAgree = value!; - }); - }, - ), ElevatedButton( onPressed: () async { _goToPage();