diff --git a/lib/data/fake_model/fake_product_repository.dart b/lib/data/fake_model/fake_product_repository.dart index b9f569c3..a4fa1f76 100644 --- a/lib/data/fake_model/fake_product_repository.dart +++ b/lib/data/fake_model/fake_product_repository.dart @@ -149,7 +149,8 @@ class FakeProductRepository extends ProductRepository with FavoritesRepository { SortRules sortRules = const SortRules(), FilterRules filterRules}) async { return (await _getFavorites()) - .map((value) => FavoriteProduct(value, HashMap())); + .map((value) => FavoriteProduct(value, HashMap())) + .toList(); } @override diff --git a/lib/presentation/features/favorites/views/favourites_list_view.dart b/lib/presentation/features/favorites/views/favourites_list_view.dart index 098401fa..47ba7956 100644 --- a/lib/presentation/features/favorites/views/favourites_list_view.dart +++ b/lib/presentation/features/favorites/views/favourites_list_view.dart @@ -5,10 +5,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:openflutterecommerce/config/routes.dart'; -import 'package:openflutterecommerce/config/theme.dart'; import 'package:openflutterecommerce/presentation/features/favorites/favorites.dart'; import 'package:openflutterecommerce/presentation/features/product_details/product_screen.dart'; -import 'package:openflutterecommerce/presentation/widgets/data_driven/blank_product_list_item.dart'; import 'package:openflutterecommerce/presentation/widgets/extensions/product_view.dart'; class FavoritesListView extends StatelessWidget { @@ -18,38 +16,25 @@ class FavoritesListView extends StatelessWidget { builder: (context, state) { return SliverList( delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - if (state.data == null) { - return Padding( - padding: EdgeInsets.symmetric(horizontal: AppSizes.sidePadding), - child: BlankProductListItem(), - ); - } else { - return Padding( - padding: - EdgeInsets.symmetric(horizontal: AppSizes.sidePadding), - child: state.data[index].getListView( - context: context, - showProductInfo: () { - Navigator.of(context).pushNamed( - OpenFlutterEcommerceRoutes.product, - arguments: ProductDetailsParameters( - state.data[index].product.id, - selectedAttributes: - state.data[index].favoriteForm)); - }, - onRemoveFromFavorites: () { - BlocProvider.of(context).add( - RemoveFromFavoriteEvent( - state.data[index].product.id)); - }, - onAddToCart: () { - BlocProvider.of(context) - .add(AddToCartEvent(state.data[index].product.id)); - }, - )); - } - }, + (BuildContext context, int index) => state.data[index].getListView( + context: context, + showProductInfo: () { + Navigator.of(context).pushNamed( + OpenFlutterEcommerceRoutes.product, + arguments: ProductDetailsParameters( + state.data[index].product.id, + selectedAttributes: state.data[index].favoriteForm)); + }, + onRemoveFromFavorites: () { + BlocProvider.of(context) + .add(RemoveFromFavoriteEvent(state.data[index].product.id)); + }, + onAddToCart: () { + BlocProvider.of(context) + .add(AddToCartEvent(state.data[index].product.id)); + }, + ), + childCount: state.data != null ? state.data.length : 0, ), ); }); diff --git a/lib/presentation/widgets/extensions/product_view.dart b/lib/presentation/widgets/extensions/product_view.dart index 3072a742..843bd840 100644 --- a/lib/presentation/widgets/extensions/product_view.dart +++ b/lib/presentation/widgets/extensions/product_view.dart @@ -76,8 +76,10 @@ extension View on Product { Widget _getFavoritesButton(VoidCallback onFavoritesClick) { return FloatingActionButton( - heroTag: Random().nextInt( - 1000000), //TODO make sure that there is only one product with specified id on screen and use it as a tag + heroTag: title + + Random() + .nextInt(1000000) + .toString(), //TODO make sure that there is only one product with specified id on screen and use it as a tag mini: true, backgroundColor: AppColors.white, onPressed: onFavoritesClick, @@ -99,7 +101,7 @@ extension View on Product { return Text( price != null ? '\$' + price.toStringAsFixed(0) : '', style: _theme.textTheme.display3.copyWith( - decoration: discountPrice!=null && discountPrice > 0 + decoration: discountPrice != null && discountPrice > 0 ? TextDecoration.lineThrough : TextDecoration.none, ),