From c9bfde3cb127a1c8e081538ed0bca3a64f185ded Mon Sep 17 00:00:00 2001 From: Umair Adil Date: Sat, 4 Feb 2023 16:18:13 +0500 Subject: [PATCH] #142 - Handled exceptions --- android/app/build.gradle | 18 ++++-- android/build.gradle | 10 ++-- .../gradle/wrapper/gradle-wrapper.properties | 2 +- ios/Flutter/.last_build_id | 2 +- lib/data/model/category.dart | 4 +- lib/data/model/product.dart | 10 ++-- lib/data/model/promo.dart | 2 +- lib/data/network/network_status.dart | 7 +-- .../abstract/cart_repository.dart | 2 +- .../repositories/cart_repository_impl.dart | 4 +- .../woocommerce/models/promo_code_model.dart | 2 +- .../product_remote_repository.dart | 3 +- .../product/product_category_entity.dart | 37 +++++-------- .../entities/product/product_entity.dart | 16 ++---- .../entities/promo/promo_code_entity.dart | 7 +-- .../user/shipping_address_entity.dart | 7 +-- lib/domain/entities/user/user_entity.dart | 7 +-- .../cart/get_cart_products_use_case.dart | 4 +- .../find_categories_by_filter_use_case.dart | 34 ++++++------ lib/locator.dart | 3 +- lib/presentation/features/cart/cart_bloc.dart | 2 +- .../categories/categories_screen.dart | 2 +- .../features/favorites/favorites_screen.dart | 4 +- .../data_driven/size_changing_app_bar.dart | 8 +-- .../widgets/independent/bottom_menu.dart | 23 ++++---- .../widgets/independent/scaffold.dart | 23 ++++---- .../widgets/independent/view_options.dart | 55 ++++++++++++------- pubspec.yaml | 3 +- .../abstract/model/filter_rules_test.dart | 15 ++--- test/data/local/all_tests.dart | 38 ++++++------- .../cart/product_cart_data_source_test.dart | 2 +- .../delivery_method_data_source_test.dart | 2 +- .../category_hashtag_data_source_test.dart | 2 +- .../hashtag/hashtag_data_source_test.dart | 2 +- .../product_hashtag_data_source_test.dart | 2 +- .../order/order_product_data_source_test.dart | 2 +- ...er_product_parameter_data_source_test.dart | 2 +- .../order/user_order_data_source_test.dart | 2 +- .../product2parameter_data_source_test.dart | 2 +- .../product_category_data_source_test.dart | 2 +- .../product/product_data_source_test.dart | 2 +- .../product_image_data_source_test.dart | 2 +- .../product_parameter_data_source_test.dart | 2 +- ...ct_parameter_variant_data_source_test.dart | 2 +- .../product_review_data_source_test.dart | 2 +- ...product_review_photo_data_source_test.dart | 2 +- .../promo/promo_code_data_source_test.dart | 2 +- .../shipping_address_data_source_test.dart | 2 +- .../local/user/user_data_source_test.dart | 2 +- .../category_remote_repository_test.dart | 6 +- .../product_remote_repository_test.dart | 11 ++-- .../categories_by_filter_use_case_test.dart | 6 +- ...find_products_by_filter_use_case_test.dart | 8 +-- .../usecases/use_case_test_include.dart | 8 +-- 54 files changed, 216 insertions(+), 215 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index c822467c..13d1eaa4 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -26,21 +26,31 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 31 + compileSdkVersion 33 - sourceSets { - main.java.srcDirs += 'src/main/kotlin' + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' } lintOptions { disable 'InvalidPackage' + checkReleaseBuilds false + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.openflutter.openflutterecommerce" minSdkVersion 18 - targetSdkVersion 31 + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/android/build.gradle b/android/build.gradle index 3100ad2d..018f61f1 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.5.20' repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:4.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -14,15 +14,13 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" -} -subprojects { project.evaluationDependsOn(':app') } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 296b146b..bc6a58af 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip diff --git a/ios/Flutter/.last_build_id b/ios/Flutter/.last_build_id index 6577ce3c..d19201ad 100644 --- a/ios/Flutter/.last_build_id +++ b/ios/Flutter/.last_build_id @@ -1 +1 @@ -0e81f4131a64923bd5ca5804c4d3b13f \ No newline at end of file +2a331d4dad0001170383022c3954ea22 \ No newline at end of file diff --git a/lib/data/model/category.dart b/lib/data/model/category.dart index 924fd07c..c3e248f4 100644 --- a/lib/data/model/category.dart +++ b/lib/data/model/category.dart @@ -35,11 +35,11 @@ class ProductCategory extends Equatable { return ProductCategory( entity.id, parentId: entity.parentId, - name: entity.title, + name: entity.title!, description: entity.description, image: CommerceImage( 0,//TODO: remove id from CommerceImage - entity.image, + entity.image!, '' ) ); diff --git a/lib/data/model/product.dart b/lib/data/model/product.dart index 372b24ac..e67d177b 100644 --- a/lib/data/model/product.dart +++ b/lib/data/model/product.dart @@ -93,16 +93,16 @@ class Product extends Equatable { } List categories = []; if ( entity.categories.isNotEmpty ){ - entity.categories.forEach((category) => categories.add(ProductCategory(category.id, name: category.title, image: CommerceImage.placeHolder()))); + entity.categories.forEach((category) => categories.add(ProductCategory(category.id, name: category.title!, image: CommerceImage.placeHolder()))); } List hashTags = []; - if ( entity.hashTags.isNotEmpty ){ - entity.hashTags.forEach((hashTag) => hashTags.add(HashTag(id: hashTag.id, title: hashTag.title))); + if ( entity.hashTags!.isNotEmpty == true ){ + entity.hashTags!.forEach((hashTag) => hashTags.add(HashTag(id: hashTag.id, title: hashTag.title))); } return Product( entity.id, title: entity.title, - subTitle: entity.subTitle, + subTitle: entity.subTitle!, shortDescription: entity.description, description: entity.description, price: entity.price ?? 0, @@ -117,7 +117,7 @@ class Product extends Equatable { images: images, //TODO: add selectable attributes selectableAttributes: [], isFavorite: entity.isFavourite, - selectableAttributes: entity.selectableAttributes, created: DateTime.now(), properties: {} + selectableAttributes: entity.selectableAttributes!, created: DateTime.now(), properties: {} ); } else { throw EntityModelMapperException(message: 'Entity should be of type ProductEntity'); diff --git a/lib/data/model/promo.dart b/lib/data/model/promo.dart index 89a4a754..10ec5442 100644 --- a/lib/data/model/promo.dart +++ b/lib/data/model/promo.dart @@ -28,7 +28,7 @@ class Promo extends Equatable { promoCode: entity.promoCode, discount: entity.discountPercent, textColor: Colors.white, - daysLeft: entity.dateExpires.difference(DateTime.now()).inDays, + daysLeft: entity.dateExpires!.difference(DateTime.now()).inDays, image: "" ); } else { diff --git a/lib/data/network/network_status.dart b/lib/data/network/network_status.dart index 6e3b05de..4044c695 100644 --- a/lib/data/network/network_status.dart +++ b/lib/data/network/network_status.dart @@ -1,14 +1,13 @@ -import 'package:data_connection_checker/data_connection_checker.dart'; + abstract class NetworkStatus { Future get isConnected; } class NetworkStatusImpl implements NetworkStatus { - final DataConnectionChecker connectionChecker; - NetworkStatusImpl(this.connectionChecker); + NetworkStatusImpl(); @override - Future get isConnected => connectionChecker.hasConnection; + Future get isConnected => Future.value(true); } diff --git a/lib/data/repositories/abstract/cart_repository.dart b/lib/data/repositories/abstract/cart_repository.dart index f6739bbb..95152880 100644 --- a/lib/data/repositories/abstract/cart_repository.dart +++ b/lib/data/repositories/abstract/cart_repository.dart @@ -24,7 +24,7 @@ abstract class CartRepository { Future getAppliedPromo(); ///applies promo to cart - Future setPromo(Promo promo); + Future setPromo(Promo? promo); //get cart total price double getTotalPrice(); diff --git a/lib/data/repositories/cart_repository_impl.dart b/lib/data/repositories/cart_repository_impl.dart index 97a1fab7..b88981ef 100644 --- a/lib/data/repositories/cart_repository_impl.dart +++ b/lib/data/repositories/cart_repository_impl.dart @@ -45,8 +45,8 @@ class CartRepositoryImpl extends CartRepository{ } @override - Future setPromo(Promo promo) async { - cartProductDataStorage.appliedPromo = promo; + Future setPromo(Promo? promo) async { + cartProductDataStorage.appliedPromo = promo!; } @override diff --git a/lib/data/woocommerce/models/promo_code_model.dart b/lib/data/woocommerce/models/promo_code_model.dart index 2fd8ed5c..563a0eb9 100644 --- a/lib/data/woocommerce/models/promo_code_model.dart +++ b/lib/data/woocommerce/models/promo_code_model.dart @@ -46,7 +46,7 @@ class PromoCodeModel extends PromoCodeEntity { 'amount': discountPercent, 'discount_type': 'percent', 'description': title, - 'date_expires':DateFormat('yyyy-MM-ddTHH:mm:ss').format(dateExpires) + 'date_expires':DateFormat('yyyy-MM-ddTHH:mm:ss').format(dateExpires!) }; } } \ No newline at end of file diff --git a/lib/data/woocommerce/repositories/product_remote_repository.dart b/lib/data/woocommerce/repositories/product_remote_repository.dart index d2c7b809..a9e27175 100644 --- a/lib/data/woocommerce/repositories/product_remote_repository.dart +++ b/lib/data/woocommerce/repositories/product_remote_repository.dart @@ -40,8 +40,7 @@ class RemoteProductRepository extends ProductRepository { int pageSize = AppConsts.page_size, int categoryId = 0, bool isFavorite = false, - SortRules sortRules = const SortRules(), - required FilterRules filterRules}) async { + SortRules sortRules = const SortRules(), FilterRules? filterRules}) async { // TODO: implement getProducts try { diff --git a/lib/domain/entities/product/product_category_entity.dart b/lib/domain/entities/product/product_category_entity.dart index b35feb93..6674c91a 100644 --- a/lib/domain/entities/product/product_category_entity.dart +++ b/lib/domain/entities/product/product_category_entity.dart @@ -1,23 +1,16 @@ import 'package:openflutterecommerce/domain/entities/entity.dart'; class ProductCategoryEntity extends Entity { - final String title; - final String description; - final String image; - final String thumb; - final int parentId; - final int orderNumber; - final int count; + final String? title; + final String? description; + final String? image; + final String? thumb; + final int? parentId; + final int? orderNumber; + final int? count; ProductCategoryEntity( - {required int id, - required this.title, - required this.description, - required this.image, - required this.thumb, - required this.parentId, - required this.orderNumber, - required this.count}) : super(id); + {required int id, this.title, this.description, this.image, this.thumb, this.parentId, this.orderNumber, this.count}) : super(id); @override Map toMap() { @@ -36,12 +29,12 @@ class ProductCategoryEntity extends Entity { @override List get props => [ id, - title, - description, - image, - thumb, - parentId, - orderNumber, - count + title!, + description!, + image!, + thumb!, + parentId!, + orderNumber!, + count! ]; } diff --git a/lib/domain/entities/product/product_entity.dart b/lib/domain/entities/product/product_entity.dart index 9095a734..6448720a 100644 --- a/lib/domain/entities/product/product_entity.dart +++ b/lib/domain/entities/product/product_entity.dart @@ -6,13 +6,13 @@ import 'package:openflutterecommerce/domain/entities/product/product_category_en class ProductEntity extends Entity { final String title; - final String subTitle; + final String? subTitle; final List images; final String thumb; final double price; final double discountPercent; final List categories; - final List hashTags; + final List? hashTags; final int amount; final String description; final bool isFavourite; @@ -22,21 +22,17 @@ class ProductEntity extends Entity { final int rating3Count; final int rating4Count; final int rating5Count; - final List selectableAttributes; + final List? selectableAttributes; ProductEntity( {required int id, - required this.title, - required this.subTitle, + required this.title, this.subTitle, required this.images, required this.thumb, required double price, - required double discountPercent, - required List categories, - required List hashTags, + required double discountPercent, List? categories, List? hashTags, required this.amount, - required this.description, - required this.selectableAttributes, + required this.description, this.selectableAttributes, required bool isFavourite, rating, rating1Count, diff --git a/lib/domain/entities/promo/promo_code_entity.dart b/lib/domain/entities/promo/promo_code_entity.dart index 1754c15e..2729a78f 100644 --- a/lib/domain/entities/promo/promo_code_entity.dart +++ b/lib/domain/entities/promo/promo_code_entity.dart @@ -7,7 +7,7 @@ class PromoCodeEntity extends Entity { final double discountPercent; final bool belongsToUser; final bool wasUsed; - final DateTime dateExpires; + final DateTime? dateExpires; PromoCodeEntity( {required int id, @@ -16,8 +16,7 @@ class PromoCodeEntity extends Entity { required this.promoCode, required this.discountPercent, required this.belongsToUser, - required this.wasUsed, - required this.dateExpires}) : super(id); + required this.wasUsed, this.dateExpires}) : super(id); @override Map toMap() { @@ -42,6 +41,6 @@ class PromoCodeEntity extends Entity { discountPercent, belongsToUser, wasUsed, - dateExpires + dateExpires! ]; } diff --git a/lib/domain/entities/user/shipping_address_entity.dart b/lib/domain/entities/user/shipping_address_entity.dart index 580c1e8d..047033f8 100644 --- a/lib/domain/entities/user/shipping_address_entity.dart +++ b/lib/domain/entities/user/shipping_address_entity.dart @@ -6,7 +6,7 @@ class ShippingAddressEntity extends Entity { final String city; final String country; final String postal; - final bool isDefault; + final bool? isDefault; ShippingAddressEntity( {required int id, @@ -14,8 +14,7 @@ class ShippingAddressEntity extends Entity { required this.address, required this.city, required this.country, - required this.postal, - required this.isDefault}) : super(id); + required this.postal, this.isDefault}) : super(id); @override Map toMap() { @@ -38,6 +37,6 @@ class ShippingAddressEntity extends Entity { city, country, postal, - isDefault + isDefault! ]; } diff --git a/lib/domain/entities/user/user_entity.dart b/lib/domain/entities/user/user_entity.dart index 02882c49..deb8cfc5 100644 --- a/lib/domain/entities/user/user_entity.dart +++ b/lib/domain/entities/user/user_entity.dart @@ -6,7 +6,7 @@ class UserEntity extends Entity { final String email; final String password; final String birthDate; - final String token; + final String? token; final bool salesNotification; final bool newArrivalsNotification; final bool deliveryStatusChanges; @@ -17,8 +17,7 @@ class UserEntity extends Entity { required this.avatar, required this.email, required this.password, - required this.birthDate, - required this.token, + required this.birthDate, this.token, required this.salesNotification, required this.newArrivalsNotification, required this.deliveryStatusChanges}) : super(id); @@ -47,7 +46,7 @@ class UserEntity extends Entity { email, password, birthDate, - token, + token!, salesNotification, newArrivalsNotification, deliveryStatusChanges diff --git a/lib/domain/usecases/cart/get_cart_products_use_case.dart b/lib/domain/usecases/cart/get_cart_products_use_case.dart index e5c762b6..f11a318e 100644 --- a/lib/domain/usecases/cart/get_cart_products_use_case.dart +++ b/lib/domain/usecases/cart/get_cart_products_use_case.dart @@ -46,9 +46,9 @@ class GetCartProductsUseCaseImpl implements GetCartProductsUseCase { } class GetCartProductParams { - final Promo appliedPromo; + final Promo? appliedPromo; - GetCartProductParams({required this.appliedPromo}); + GetCartProductParams({this.appliedPromo}); } class GetCartProductsException implements Exception {} diff --git a/lib/domain/usecases/categories/find_categories_by_filter_use_case.dart b/lib/domain/usecases/categories/find_categories_by_filter_use_case.dart index a6d0b52c..d348d37c 100644 --- a/lib/domain/usecases/categories/find_categories_by_filter_use_case.dart +++ b/lib/domain/usecases/categories/find_categories_by_filter_use_case.dart @@ -1,7 +1,8 @@ import 'package:openflutterecommerce/data/repositories/abstract/category_repository.dart'; + /// # Find Categories by Filter Use Case Implementation -/// 2.1. Display category list use-case: User on the home page clicks “View All”, -/// categories are loaded and displayed in a list. +/// 2.1. Display category list use-case: User on the home page clicks “View All”, +/// categories are loaded and displayed in a list. /// Complete list of use cases /// https://medium.com/@openflutterproject/open-flutter-project-e-commerce-app-use-cases-and-features-6b7414a6e708 @@ -12,28 +13,25 @@ import 'package:openflutterecommerce/domain/usecases/categories/categories_by_fi import 'package:openflutterecommerce/locator.dart'; abstract class FindCategoriesByFilterUseCase - implements BaseUseCase {} + implements + BaseUseCase {} - -class FindCategoriesByFilterUseCaseImpl implements FindCategoriesByFilterUseCase { +class FindCategoriesByFilterUseCaseImpl + implements FindCategoriesByFilterUseCase { @override - Future execute(CategoriesByFilterParams params) async { + Future execute( + CategoriesByFilterParams params) async { try { CategoryRepository _categoryRepository = sl(); - List categories = await _categoryRepository.getCategories(parentCategoryId: params.categoryId); - return CategoriesByFilterResult( - categories, - categories.length, exception: null! - ); - + List categories = await _categoryRepository + .getCategories(parentCategoryId: params.categoryId); + return CategoriesByFilterResult(categories, categories.length, + exception: null!); } catch (e) { - return CategoriesByFilterResult( - null!, - 0, - exception: EmptyCategoriesException() - ); + return CategoriesByFilterResult([], 0, + exception: EmptyCategoriesException()); } } } -class EmptyCategoriesException implements Exception {} \ No newline at end of file +class EmptyCategoriesException implements Exception {} diff --git a/lib/locator.dart b/lib/locator.dart index c047583d..66d319ea 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -1,4 +1,3 @@ -import 'package:data_connection_checker/data_connection_checker.dart'; import 'package:get_it/get_it.dart'; import 'package:http/http.dart' as http; import 'package:openflutterecommerce/data/repositories/abstract/cart_repository.dart'; @@ -38,7 +37,7 @@ final sl = GetIt.instance; //Service locator description void init() { //Singleton for NetworkStatus identification - sl.registerLazySingleton(() => NetworkStatusImpl(DataConnectionChecker())); + sl.registerLazySingleton(() => NetworkStatusImpl()); //get home page products use case sl.registerLazySingleton(() => GetHomePageProductsUseCaseImpl()); diff --git a/lib/presentation/features/cart/cart_bloc.dart b/lib/presentation/features/cart/cart_bloc.dart index 83416794..7303b4e0 100644 --- a/lib/presentation/features/cart/cart_bloc.dart +++ b/lib/presentation/features/cart/cart_bloc.dart @@ -30,7 +30,7 @@ class CartBloc extends Bloc { Stream mapEventToState(CartEvent event) async* { if (event is CartLoadedEvent) { if (state is CartInitialState) { - final cartResults = await getCartProductsUseCase.execute(GetCartProductParams(appliedPromo: null!)); + final cartResults = await getCartProductsUseCase.execute(GetCartProductParams()); var promos = await getPromosUseCase.execute(GetPromosParams()); yield CartLoadedState( diff --git a/lib/presentation/features/categories/categories_screen.dart b/lib/presentation/features/categories/categories_screen.dart index 094ab807..26a44589 100644 --- a/lib/presentation/features/categories/categories_screen.dart +++ b/lib/presentation/features/categories/categories_screen.dart @@ -27,7 +27,7 @@ class CategoriesParameters { class _CategoriesScreenState extends State { @override Widget build(BuildContext context) { - final args = ModalRoute.of(context)!.settings.arguments as CategoriesParameters; + final args = ModalRoute.of(context)?.settings.arguments as CategoriesParameters?; print('widget parameters at categories screen ${args}'); return SafeArea( diff --git a/lib/presentation/features/favorites/favorites_screen.dart b/lib/presentation/features/favorites/favorites_screen.dart index cc3aeb71..3b51d41d 100644 --- a/lib/presentation/features/favorites/favorites_screen.dart +++ b/lib/presentation/features/favorites/favorites_screen.dart @@ -39,8 +39,8 @@ class _FavouriteScreenState extends State { slivers: [ SizeChangingAppBar( title: 'Favorites', - filterRules: state.filterRules!, - sortRules: state.sortBy!, + filterRules: state.filterRules, + sortRules: state.sortBy, isListView: state.isList, onFilterRulesChanged: (filter) { BlocProvider.of(context) diff --git a/lib/presentation/widgets/data_driven/size_changing_app_bar.dart b/lib/presentation/widgets/data_driven/size_changing_app_bar.dart index 0b88d349..06abcfbc 100644 --- a/lib/presentation/widgets/data_driven/size_changing_app_bar.dart +++ b/lib/presentation/widgets/data_driven/size_changing_app_bar.dart @@ -9,17 +9,15 @@ import 'package:openflutterecommerce/presentation/widgets/independent/view_optio class SizeChangingAppBar extends StatelessWidget { final String title; - final FilterRules filterRules; - final SortRules sortRules; + final FilterRules? filterRules; + final SortRules? sortRules; final bool isListView; final Function(FilterRules) onFilterRulesChanged; final Function(SortRules) onSortRulesChanged; final VoidCallback onViewChanged; const SizeChangingAppBar( - {required this.title, - required this.filterRules, - required this.sortRules, + {required this.title, this.filterRules, this.sortRules, this.isListView = true, required this.onFilterRulesChanged, required this.onSortRulesChanged, diff --git a/lib/presentation/widgets/independent/bottom_menu.dart b/lib/presentation/widgets/independent/bottom_menu.dart index 70f95730..e7e0f4fd 100644 --- a/lib/presentation/widgets/independent/bottom_menu.dart +++ b/lib/presentation/widgets/independent/bottom_menu.dart @@ -19,28 +19,27 @@ class OpenFlutterBottomMenu extends StatelessWidget { BottomNavigationBarItem getItem( String image, String title, ThemeData theme, int index) { return BottomNavigationBarItem( - icon: SvgPicture.asset( - image, - height: 24.0, - width: 24.0, - color: colorByIndex(theme, index), - ) - ); + label: title, + icon: SvgPicture.asset( + image, + height: 24.0, + width: 24.0, + color: colorByIndex(theme, index), + )); } @override Widget build(BuildContext context) { final _theme = Theme.of(context); - List menuItems =[ + List menuItems = [ getItem('assets/icons/bottom_menu/home.svg', 'Home', _theme, 0), getItem('assets/icons/bottom_menu/cart.svg', 'Shop', _theme, 1), getItem('assets/icons/bottom_menu/bag.svg', 'Bag', _theme, 2), - getItem('assets/icons/bottom_menu/favorites.svg', 'Favorites', - _theme, 3), + getItem('assets/icons/bottom_menu/favorites.svg', 'Favorites', _theme, 3), ]; - if ( AppSettings.profileEnabled ) { + if (AppSettings.profileEnabled) { menuItems.add(getItem( - 'assets/icons/bottom_menu/profile.svg', 'Profile', _theme, 4)); + 'assets/icons/bottom_menu/profile.svg', 'Profile', _theme, 4)); } return Container( decoration: BoxDecoration( diff --git a/lib/presentation/widgets/independent/scaffold.dart b/lib/presentation/widgets/independent/scaffold.dart index 61a0221a..d3176ead 100644 --- a/lib/presentation/widgets/independent/scaffold.dart +++ b/lib/presentation/widgets/independent/scaffold.dart @@ -44,17 +44,20 @@ class OpenFlutterScaffold extends StatelessWidget { : TabBar( tabs: [], ); - return Scaffold( - backgroundColor: background, - appBar: title != null - ? AppBar(title: Text(title), bottom: tabWidget, actions: [ - Row(children: [ - Icon(Icons.share), + return DefaultTabController( + length: tabBars.length, + child: Scaffold( + backgroundColor: background, + appBar: title != null + ? AppBar(title: Text(title), bottom: tabWidget, actions: [ + Row(children: [ + Icon(Icons.share), + ]) ]) - ]) - : null, - body: body, - bottomNavigationBar: OpenFlutterBottomMenu(bottomMenuIndex), + : null, + body: body, + bottomNavigationBar: OpenFlutterBottomMenu(bottomMenuIndex), + ), ); } } diff --git a/lib/presentation/widgets/independent/view_options.dart b/lib/presentation/widgets/independent/view_options.dart index c6c0730b..185418de 100644 --- a/lib/presentation/widgets/independent/view_options.dart +++ b/lib/presentation/widgets/independent/view_options.dart @@ -10,20 +10,19 @@ import 'package:openflutterecommerce/data/model/filter_rules.dart'; import 'package:openflutterecommerce/data/model/sort_rules.dart'; class OpenFlutterViewOptions extends StatelessWidget { - final SortRules sortRules; - final FilterRules filterRules; + final SortRules? sortRules; + final FilterRules? filterRules; final bool isListView; final Function(FilterRules) onFilterChanged; final Function(SortRules) onSortChanged; final Function()? onChangeViewClicked; const OpenFlutterViewOptions( - { - required this.onFilterChanged, + {required this.onFilterChanged, required this.onSortChanged, required this.onChangeViewClicked, - required this.sortRules, - required this.filterRules, + this.sortRules, + this.filterRules, this.isListView = true}); @override @@ -56,7 +55,8 @@ class OpenFlutterViewOptions extends StatelessWidget { Icon(Icons.import_export), Container( padding: EdgeInsets.only(left: 5), - child: Text(sortRules?.getSortTitle() ?? '', style: _theme.textTheme.bodyText1), + child: Text(sortRules?.getSortTitle() ?? '', + style: _theme.textTheme.bodyText1), ) ])), IconButton( @@ -73,14 +73,16 @@ class OpenFlutterViewOptions extends StatelessWidget { } void _showFilterWindow(BuildContext context) { - Navigator.of(context).pushNamed(OpenFlutterEcommerceRoutes.filters, arguments: filterRules); + Navigator.of(context) + .pushNamed(OpenFlutterEcommerceRoutes.filters, arguments: filterRules); } void _showSortOptions(BuildContext context) { showModalBottomSheet( context: context, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only(topLeft: Radius.circular(34.0), topRight: Radius.circular(34.0)), + borderRadius: BorderRadius.only( + topLeft: Radius.circular(34.0), topRight: Radius.circular(34.0)), ), backgroundColor: Colors.white, builder: (context) { @@ -100,42 +102,53 @@ class OpenFlutterViewOptions extends StatelessWidget { Padding( padding: EdgeInsets.only(top: AppSizes.sidePadding), ), - ...sortRules.sortTextVariants + ...sortRules!.sortTextVariants .map((key, value) => MapEntry( key, Container( - padding: EdgeInsets.symmetric(horizontal: AppSizes.sidePadding, vertical: AppSizes.linePadding), + padding: EdgeInsets.symmetric( + horizontal: AppSizes.sidePadding, + vertical: AppSizes.linePadding), alignment: Alignment.centerLeft, - color: sortRules.sortType == key ? AppColors.red : AppColors.white, + color: sortRules!.sortType == key + ? AppColors.red + : AppColors.white, child: Row( children: [ Expanded( child: InkWell( child: Text(value, - style: Theme.of(context).textTheme.headline4?.copyWith( - fontWeight: FontWeight.normal, - color: sortRules.sortType == key ? AppColors.white : AppColors.black)), + style: Theme.of(context) + .textTheme + .headline4 + ?.copyWith( + fontWeight: FontWeight.normal, + color: sortRules!.sortType == key + ? AppColors.white + : AppColors.black)), onTap: () { onSortChanged(SortRules( - sortOrder: sortRules.sortType == key - ? (sortRules.sortOrder == SortOrder.FromLowestToHighest + sortOrder: sortRules!.sortType == key + ? (sortRules!.sortOrder == + SortOrder.FromLowestToHighest ? SortOrder.FromHighestToLowest : SortOrder.FromLowestToHighest) - : sortRules.sortOrder, + : sortRules!.sortOrder, sortType: key)); Navigator.pop(context); }, ), ), IconButton( - icon: Icon(sortRules.sortOrder == SortOrder.FromHighestToLowest + icon: Icon(sortRules!.sortOrder == + SortOrder.FromHighestToLowest ? FontAwesomeIcons.sortAlphaUp : FontAwesomeIcons.sortAlphaDown), - color: sortRules.sortType == key + color: sortRules!.sortType == key ? Theme.of(context).primaryColor : Theme.of(context).backgroundColor, onPressed: () { - onSortChanged(sortRules.copyWithChangedOrder()); + onSortChanged(sortRules!.copyWithChangedOrder()); Navigator.pop(context); }, ) diff --git a/pubspec.yaml b/pubspec.yaml index a867ecbf..6616f703 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -34,12 +34,11 @@ dependencies: flutter_bloc: ^7.3.0 bubble_tab_indicator: ^0.1.6 cupertino_icons: ^1.0.3 - data_connection_checker: ^0.3.4 equatable: ^2.0.3 sqflite: ^2.0.0+4 dev_dependencies: - pedantic: ^1.9.0 + pedantic: ^1.11.1 flutter_test: sdk: flutter diff --git a/test/data/abstract/model/filter_rules_test.dart b/test/data/abstract/model/filter_rules_test.dart index ad6b621c..85c8ea26 100644 --- a/test/data/abstract/model/filter_rules_test.dart +++ b/test/data/abstract/model/filter_rules_test.dart @@ -6,14 +6,16 @@ import 'package:openflutterecommerce/data/model/filter_rules.dart'; import 'package:openflutterecommerce/data/model/product.dart'; import 'package:openflutterecommerce/data/woocommerce/repositories/product_remote_repository.dart'; import 'package:openflutterecommerce/data/woocommerce/repositories/woocommerce_wrapper.dart'; +import 'package:openflutterecommerce/domain/usecases/products/products_by_filter_params.dart'; import '../../../fixtures/fixture_reader.dart'; -class MockWoocommerceWrapper extends Mock implements WoocommercWrapperAbstract { } +class MockWoocommerceWrapper extends Mock implements WoocommercWrapperAbstract { +} void main() { - MockWoocommerceWrapper woocommerce; - RemoteProductRepository remoteProductRepository; + late MockWoocommerceWrapper woocommerce; + late RemoteProductRepository remoteProductRepository; setUp(() { woocommerce = MockWoocommerceWrapper(); @@ -24,9 +26,9 @@ void main() { 'should return list of categories when findProductsByFilterUseCase.execute is successful', () async { // arrange - when(woocommerce.getProductList(any)) - .thenAnswer((_) async => json.decode(fixture('woocommerce/products.json')) - ); + when(woocommerce.getProductList(ProductsByFilterParams(categoryId: 0))) + .thenAnswer( + (_) async => json.decode(fixture('woocommerce/products.json'))); // act List products = await remoteProductRepository.getProducts(categoryId: 1); @@ -41,4 +43,3 @@ void main() { ); }); } - \ No newline at end of file diff --git a/test/data/local/all_tests.dart b/test/data/local/all_tests.dart index dee4da5a..98af63fc 100644 --- a/test/data/local/all_tests.dart +++ b/test/data/local/all_tests.dart @@ -40,23 +40,23 @@ Future main(List args) async { //Use after database update await SQLiteDbProvider.clear(); // run tests on all data sources (tables) - await delivery_method_data_source_test.main(); - await category_hashtag_data_source_test.main(); - await hash_tag_data_source_test.main(); - await product_hashtag_data_source_test.main(); - await order_product_data_source_test.main(); - await order_product_parameter_data_source_test.main(); - await user_order_data_source_test.main(); - await product_category_data_source_test.main(); - await product_cart_data_source_test.main(); - await product_data_source_test.main(); - await product_image_data_source_test.main(); - await product_parameter_data_source_test.main(); - await product_parameter_variant_data_source_test.main(); - await product_review_data_source_test.main(); - await product_review_photo_data_source_test.main(); - await product2parameter_data_source_test.main(); - await promo_code_data_source_test.main(); - await shipping_address_data_source_test.main(); - await user_data_source_test.main();/**/ + delivery_method_data_source_test.main(); + category_hashtag_data_source_test.main(); + hash_tag_data_source_test.main(); + product_hashtag_data_source_test.main(); + order_product_data_source_test.main(); + order_product_parameter_data_source_test.main(); + user_order_data_source_test.main(); + product_category_data_source_test.main(); + product_cart_data_source_test.main(); + product_data_source_test.main(); + product_image_data_source_test.main(); + product_parameter_data_source_test.main(); + product_parameter_variant_data_source_test.main(); + product_review_data_source_test.main(); + product_review_photo_data_source_test.main(); + product2parameter_data_source_test.main(); + promo_code_data_source_test.main(); + shipping_address_data_source_test.main(); + user_data_source_test.main();/**/ } diff --git a/test/data/local/cart/product_cart_data_source_test.dart b/test/data/local/cart/product_cart_data_source_test.dart index 73bb3281..d90132bb 100644 --- a/test/data/local/cart/product_cart_data_source_test.dart +++ b/test/data/local/cart/product_cart_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ProductCart Data Source', () { - ProductCartDataSource dataSource; + late ProductCartDataSource dataSource; setUp(() async { dataSource = ProductCartDataSource(); diff --git a/test/data/local/delivery/delivery_method_data_source_test.dart b/test/data/local/delivery/delivery_method_data_source_test.dart index 24d1ad08..4a36102d 100644 --- a/test/data/local/delivery/delivery_method_data_source_test.dart +++ b/test/data/local/delivery/delivery_method_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test DeliveryMethod Data Source', () { - DeliveryMethodDataSource dataSource; + late DeliveryMethodDataSource dataSource; setUp(() async { dataSource = DeliveryMethodDataSource(); diff --git a/test/data/local/hashtag/category_hashtag_data_source_test.dart b/test/data/local/hashtag/category_hashtag_data_source_test.dart index e68ee729..c194222d 100644 --- a/test/data/local/hashtag/category_hashtag_data_source_test.dart +++ b/test/data/local/hashtag/category_hashtag_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test CategoryHashTag Data Source', () { - CategoryHashTagDataSource dataSource; + late CategoryHashTagDataSource dataSource; setUp(() async { dataSource = CategoryHashTagDataSource(); diff --git a/test/data/local/hashtag/hashtag_data_source_test.dart b/test/data/local/hashtag/hashtag_data_source_test.dart index f8ec1b06..574ff327 100644 --- a/test/data/local/hashtag/hashtag_data_source_test.dart +++ b/test/data/local/hashtag/hashtag_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test HashTag Data Source', () { - HashTagDataSource dataSource; + late HashTagDataSource dataSource; setUp(() async { dataSource = HashTagDataSource(); diff --git a/test/data/local/hashtag/product_hashtag_data_source_test.dart b/test/data/local/hashtag/product_hashtag_data_source_test.dart index 8b565ad2..55f65fa7 100644 --- a/test/data/local/hashtag/product_hashtag_data_source_test.dart +++ b/test/data/local/hashtag/product_hashtag_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ProductHashTag Data Source', () { - ProductHashTagDataSource dataSource; + late ProductHashTagDataSource dataSource; setUp(() async { dataSource = ProductHashTagDataSource(); diff --git a/test/data/local/order/order_product_data_source_test.dart b/test/data/local/order/order_product_data_source_test.dart index f9d80d62..19514711 100644 --- a/test/data/local/order/order_product_data_source_test.dart +++ b/test/data/local/order/order_product_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test OrderProduct Data Source', () { - OrderProductDataSource dataSource; + late OrderProductDataSource dataSource; setUp(() async { dataSource = OrderProductDataSource(); diff --git a/test/data/local/order/order_product_parameter_data_source_test.dart b/test/data/local/order/order_product_parameter_data_source_test.dart index 30626e52..08152782 100644 --- a/test/data/local/order/order_product_parameter_data_source_test.dart +++ b/test/data/local/order/order_product_parameter_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test OrderProductParameter Data Source', () { - OrderProductParameterDataSource dataSource; + late OrderProductParameterDataSource dataSource; setUp(() async { dataSource = OrderProductParameterDataSource(); diff --git a/test/data/local/order/user_order_data_source_test.dart b/test/data/local/order/user_order_data_source_test.dart index a1e692f5..89961110 100644 --- a/test/data/local/order/user_order_data_source_test.dart +++ b/test/data/local/order/user_order_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test UserOrder Data Source', () { - UserOrderDataSource dataSource; + late UserOrderDataSource dataSource; setUp(() async { dataSource = UserOrderDataSource(); diff --git a/test/data/local/product/product2parameter_data_source_test.dart b/test/data/local/product/product2parameter_data_source_test.dart index a34969d6..00fc7593 100644 --- a/test/data/local/product/product2parameter_data_source_test.dart +++ b/test/data/local/product/product2parameter_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test Product2Parameter Data Source', () { - Product2ParameterDataSource dataSource; + late Product2ParameterDataSource dataSource; setUp(() async { dataSource = Product2ParameterDataSource(); diff --git a/test/data/local/product/product_category_data_source_test.dart b/test/data/local/product/product_category_data_source_test.dart index 70c5b162..f88e1054 100644 --- a/test/data/local/product/product_category_data_source_test.dart +++ b/test/data/local/product/product_category_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ProductCategory Data Source', () { - ProductCategoryDataSource dataSource; + late ProductCategoryDataSource dataSource; setUp(() async { dataSource = ProductCategoryDataSource(); diff --git a/test/data/local/product/product_data_source_test.dart b/test/data/local/product/product_data_source_test.dart index 041343ff..1395614c 100644 --- a/test/data/local/product/product_data_source_test.dart +++ b/test/data/local/product/product_data_source_test.dart @@ -8,7 +8,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test Product Data Source', () { - ProductDataSource productDataSource; + late ProductDataSource productDataSource; setUp(() async { productDataSource = ProductDataSource(); diff --git a/test/data/local/product/product_image_data_source_test.dart b/test/data/local/product/product_image_data_source_test.dart index 168742a5..200e0b13 100644 --- a/test/data/local/product/product_image_data_source_test.dart +++ b/test/data/local/product/product_image_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ProductImage Data Source', () { - ProductImageDataSource dataSource; + late ProductImageDataSource dataSource; setUp(() async { dataSource = ProductImageDataSource(); diff --git a/test/data/local/product/product_parameter_data_source_test.dart b/test/data/local/product/product_parameter_data_source_test.dart index 90d4724c..5ca47025 100644 --- a/test/data/local/product/product_parameter_data_source_test.dart +++ b/test/data/local/product/product_parameter_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ProductParameter Data Source', () { - ProductParameterDataSource dataSource; + late ProductParameterDataSource dataSource; setUp(() async { dataSource = ProductParameterDataSource(); diff --git a/test/data/local/product/product_parameter_variant_data_source_test.dart b/test/data/local/product/product_parameter_variant_data_source_test.dart index a146d01a..964fc754 100644 --- a/test/data/local/product/product_parameter_variant_data_source_test.dart +++ b/test/data/local/product/product_parameter_variant_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ProductParameterVariant Data Source', () { - ProductParameterVariantDataSource dataSource; + late ProductParameterVariantDataSource dataSource; setUp(() async { dataSource = ProductParameterVariantDataSource(); diff --git a/test/data/local/product/product_review_data_source_test.dart b/test/data/local/product/product_review_data_source_test.dart index 3e4dd1f4..d70b5118 100644 --- a/test/data/local/product/product_review_data_source_test.dart +++ b/test/data/local/product/product_review_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ProductReview Data Source', () { - ProductReviewDataSource dataSource; + late ProductReviewDataSource dataSource; setUp(() async { dataSource = ProductReviewDataSource(); diff --git a/test/data/local/product/product_review_photo_data_source_test.dart b/test/data/local/product/product_review_photo_data_source_test.dart index 632f6405..26bfb987 100644 --- a/test/data/local/product/product_review_photo_data_source_test.dart +++ b/test/data/local/product/product_review_photo_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ProductReviewPhoto Data Source', () { - ProductReviewPhotoDataSource dataSource; + late ProductReviewPhotoDataSource dataSource; setUp(() async { dataSource = ProductReviewPhotoDataSource(); diff --git a/test/data/local/promo/promo_code_data_source_test.dart b/test/data/local/promo/promo_code_data_source_test.dart index c0e7acae..d948c6b9 100644 --- a/test/data/local/promo/promo_code_data_source_test.dart +++ b/test/data/local/promo/promo_code_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test PromoCode Data Source', () { - PromoCodeDataSource dataSource; + late PromoCodeDataSource dataSource; setUp(() async { dataSource = PromoCodeDataSource(); diff --git a/test/data/local/user/shipping_address_data_source_test.dart b/test/data/local/user/shipping_address_data_source_test.dart index f705385a..c3187293 100644 --- a/test/data/local/user/shipping_address_data_source_test.dart +++ b/test/data/local/user/shipping_address_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test ShippingAddress Data Source', () { - ShippingAddressDataSource dataSource; + late ShippingAddressDataSource dataSource; setUp(() async { dataSource = ShippingAddressDataSource(); diff --git a/test/data/local/user/user_data_source_test.dart b/test/data/local/user/user_data_source_test.dart index 588afe4f..0660c8e6 100644 --- a/test/data/local/user/user_data_source_test.dart +++ b/test/data/local/user/user_data_source_test.dart @@ -7,7 +7,7 @@ void main() { WidgetsFlutterBinding.ensureInitialized(); group('Test User Data Source', () { - UserDataSource dataSource; + late UserDataSource dataSource; setUp(() async { dataSource = UserDataSource(); diff --git a/test/data/woocommerce/repositories/category_remote_repository_test.dart b/test/data/woocommerce/repositories/category_remote_repository_test.dart index d28b888f..98033e2b 100644 --- a/test/data/woocommerce/repositories/category_remote_repository_test.dart +++ b/test/data/woocommerce/repositories/category_remote_repository_test.dart @@ -15,9 +15,9 @@ class MockWoocommerceWrapper extends Mock class MockNetworkStatus extends Mock implements NetworkStatus {} void main() { - MockWoocommerceWrapper woocommerce; - MockNetworkStatus mockNetworkStatus; - RemoteCategoryRepository remoteCategoryRepository; + late MockWoocommerceWrapper woocommerce; + late MockNetworkStatus mockNetworkStatus; + late RemoteCategoryRepository remoteCategoryRepository; setUp(() { woocommerce = MockWoocommerceWrapper(); diff --git a/test/data/woocommerce/repositories/product_remote_repository_test.dart b/test/data/woocommerce/repositories/product_remote_repository_test.dart index 4275ff9e..f8b7687c 100644 --- a/test/data/woocommerce/repositories/product_remote_repository_test.dart +++ b/test/data/woocommerce/repositories/product_remote_repository_test.dart @@ -6,6 +6,7 @@ import 'package:openflutterecommerce/data/error/exceptions.dart'; import 'package:openflutterecommerce/data/network/network_status.dart'; import 'package:openflutterecommerce/data/woocommerce/repositories/product_remote_repository.dart'; import 'package:openflutterecommerce/data/woocommerce/repositories/woocommerce_wrapper.dart'; +import 'package:openflutterecommerce/domain/usecases/products/products_by_filter_params.dart'; import '../../../fixtures/fixture_reader.dart'; @@ -14,9 +15,9 @@ class MockWoocommerceWrapper extends Mock implements WoocommercWrapperAbstract { class MockNetworkStatus extends Mock implements NetworkStatus {} void main() { - MockWoocommerceWrapper woocommerce; - MockNetworkStatus mockNetworkStatus; - RemoteProductRepository remoteProductRepository; + late MockWoocommerceWrapper woocommerce; + late MockNetworkStatus mockNetworkStatus; + late RemoteProductRepository remoteProductRepository; setUp(() { woocommerce = MockWoocommerceWrapper(); @@ -40,7 +41,7 @@ void main() { 'should return list of products when getProducts is successful', () async { // arrange - when(woocommerce.getProductList(any)) + when(woocommerce.getProductList(ProductsByFilterParams(categoryId: 0))) .thenAnswer((_) async => json.decode(fixture('woocommerce/products.json')) ); // act @@ -54,7 +55,7 @@ void main() { 'should return server failure when getProducts is unsuccessful', () async { // arrange - when(woocommerce.getProductList(any)) + when(woocommerce.getProductList(ProductsByFilterParams(categoryId: 0))) .thenThrow(HttpRequestException()); // act // assert diff --git a/test/domain/usecases/categories/categories_by_filter_use_case_test.dart b/test/domain/usecases/categories/categories_by_filter_use_case_test.dart index 69bc437c..930d0b02 100644 --- a/test/domain/usecases/categories/categories_by_filter_use_case_test.dart +++ b/test/domain/usecases/categories/categories_by_filter_use_case_test.dart @@ -12,9 +12,9 @@ import '../use_case_test_include.dart'; void main() { setupLocator(); - MockWoocommerceWrapper woocommerce; - FindCategoriesByFilterUseCase findCategoriesByFilterUseCase; - CategoriesByFilterParams categoriesByFilterParams; + late MockWoocommerceWrapper woocommerce; + late FindCategoriesByFilterUseCase findCategoriesByFilterUseCase; + late CategoriesByFilterParams categoriesByFilterParams; setUp(() { woocommerce = sl(); diff --git a/test/domain/usecases/products/find_products_by_filter_use_case_test.dart b/test/domain/usecases/products/find_products_by_filter_use_case_test.dart index 3033d55d..0507f048 100644 --- a/test/domain/usecases/products/find_products_by_filter_use_case_test.dart +++ b/test/domain/usecases/products/find_products_by_filter_use_case_test.dart @@ -10,8 +10,8 @@ import '../../../fixtures/fixture_reader.dart'; import '../use_case_test_include.dart'; void main() { - FindProductsByFilterUseCase findProductsByFilterUseCase; - ProductsByFilterParams productsByFilterParams; + late FindProductsByFilterUseCase findProductsByFilterUseCase; + late ProductsByFilterParams productsByFilterParams; setupLocator(); @@ -29,7 +29,7 @@ void main() { 'should return list of categories when findProductsByFilterUseCase.execute is successful', () async { // arrange - when(woocommerce.getProductList(any)) + when(woocommerce.getProductList(ProductsByFilterParams(categoryId: 0))) .thenAnswer((_) async => json.decode(fixture('woocommerce/products.json')) ); // act @@ -43,7 +43,7 @@ void main() { 'should return server failure when findProductsByFilterUseCase.execute is unsuccessful', () async { // arrange - when(woocommerce.getProductList(any)) + when(woocommerce.getProductList(ProductsByFilterParams(categoryId: 0))) .thenThrow(HttpRequestException()); // act final productsData = await findProductsByFilterUseCase.execute(productsByFilterParams); diff --git a/test/domain/usecases/use_case_test_include.dart b/test/domain/usecases/use_case_test_include.dart index d53389c6..4c5ac9d2 100644 --- a/test/domain/usecases/use_case_test_include.dart +++ b/test/domain/usecases/use_case_test_include.dart @@ -1,6 +1,4 @@ - -import 'package:data_connection_checker/data_connection_checker.dart'; import 'package:get_it/get_it.dart'; import 'package:mockito/mockito.dart'; import 'package:openflutterecommerce/data/repositories/abstract/category_repository.dart'; @@ -16,8 +14,8 @@ final sl = GetIt.instance; void setupLocator() { sl.allowReassignment = true; - - MockWoocommerceWrapper woocommerce = MockWoocommerceWrapper(); + + late MockWoocommerceWrapper woocommerce = MockWoocommerceWrapper(); sl.registerLazySingleton( () => woocommerce, @@ -35,5 +33,5 @@ void setupLocator() { () => RemoteProductRepository(woocommerce: sl()), ); - sl.registerLazySingleton(() => NetworkStatusImpl(DataConnectionChecker())); + sl.registerLazySingleton(() => NetworkStatusImpl()); } \ No newline at end of file