From 3033fa951325995322eb9c95c01e68165a2d9ef4 Mon Sep 17 00:00:00 2001 From: Umair Adil Date: Sat, 4 Feb 2023 15:42:05 +0500 Subject: [PATCH] #142 - Migrated to null-safety - Added support v2 embedding --- android/app/build.gradle | 4 +- android/app/src/main/AndroidManifest.xml | 4 +- lib/config/app_settings.dart | 2 +- lib/config/theme.dart | 162 +++++++++--------- lib/data/error/exceptions.dart | 2 +- lib/data/local/data_source.dart | 6 +- lib/data/local/db_provider.dart | 2 +- lib/data/local/local_category_repository.dart | 4 +- lib/data/local/local_product_repository.dart | 6 +- lib/data/local/local_promo_repository.dart | 2 +- .../product/product_category_data_source.dart | 4 +- .../local/product/product_data_source.dart | 8 +- .../local/promo/promo_code_data_source.dart | 4 +- lib/data/local/user/user_data_source.dart | 4 +- lib/data/model/app_user.dart | 2 +- lib/data/model/cart_item.dart | 8 +- lib/data/model/category.dart | 10 +- lib/data/model/favorite_product.dart | 2 +- lib/data/model/filter_rules.dart | 111 ++++++------ lib/data/model/hashtag.dart | 2 +- lib/data/model/payment_method.dart | 61 ++++--- .../color_attribute.dart | 4 +- lib/data/model/product.dart | 32 ++-- lib/data/model/product_attribute.dart | 2 +- lib/data/model/product_review.dart | 18 +- lib/data/model/promo.dart | 14 +- lib/data/model/shipping_address.dart | 48 +++--- lib/data/model/user_order.dart | 32 ++-- lib/data/network/network_request.dart | 12 +- .../abstract/favorites_repository.dart | 2 +- .../abstract/product_repository.dart | 2 +- .../abstract/user_repository.dart | 12 +- .../repositories/cart_repository_impl.dart | 2 +- .../category_repository_impl.dart | 2 +- .../fake_repos/order_repository.dart | 22 +-- .../fake_repos/product_review_repository.dart | 11 +- .../payment_method_repository_impl.dart | 4 +- .../repositories/product_repository_impl.dart | 51 +++--- .../shipping_address_repository_impl.dart | 2 +- .../repositories/user_repository_impl.dart | 14 +- .../models/product_category_model.dart | 10 +- .../woocommerce/models/product_model.dart | 142 ++++++++------- .../woocommerce/models/promo_code_model.dart | 15 +- .../category_remote_repository.dart | 4 +- .../product_remote_repository.dart | 6 +- .../repositories/promo_remote_repository.dart | 2 +- .../repositories/remote_user_repository.dart | 14 +- .../repositories/woocommerce_wrapper.dart | 2 +- lib/domain/data_objects/product_rating.dart | 4 +- .../entities/cart/product_cart_entity.dart | 8 +- .../checkout/payment_method_entity.dart | 14 +- .../checkout/shipping_address_entity.dart | 16 +- .../delivery/delivery_method_entity.dart | 6 +- .../hashtag/category_hashtag_entity.dart | 2 +- .../entities/hashtag/hashtag_entity.dart | 4 +- .../hashtag/product_hashtag_entity.dart | 2 +- .../entities/order/order_product_entity.dart | 14 +- .../order/order_product_parameter_entity.dart | 8 +- .../entities/order/user_order_entity.dart | 24 +-- .../product/product2parameter_entity.dart | 6 +- .../product/product_category_entity.dart | 16 +- .../entities/product/product_entity.dart | 26 +-- .../product/product_image_entity.dart | 8 +- .../product/product_parameter_entity.dart | 4 +- .../product_parameter_variant_entity.dart | 8 +- .../product/product_review_entity.dart | 16 +- .../product/product_review_photo_entity.dart | 6 +- .../entities/promo/promo_code_entity.dart | 16 +- lib/domain/entities/user/settings.dart | 10 +- .../user/shipping_address_entity.dart | 14 +- lib/domain/entities/user/user_entity.dart | 20 +-- lib/domain/entities/validator.dart | 6 +- lib/domain/usecases/base_use_case.dart | 4 +- .../cart/add_product_to_cart_use_case.dart | 4 +- .../change_cart_item_quantity_use_case.dart | 8 +- .../cart/get_cart_products_use_case.dart | 18 +- .../remove_product_from_cart_use_case.dart | 4 +- .../categories_by_filter_params.dart | 2 +- .../categories_by_filter_result.dart | 2 +- .../find_categories_by_filter_use_case.dart | 4 +- .../checkout/checkout_start_use_case.dart | 26 +-- .../favorites/add_to_favorites_use_case.dart | 4 +- .../get_favorite_products_use_case.dart | 16 +- .../remove_from_favorites_use_case.dart | 4 +- .../find_products_by_filter_use_case.dart | 10 +- .../products/get_home_products_use_case.dart | 8 +- .../products/get_product_by_id_use_case.dart | 8 +- .../products/products_by_filter_params.dart | 10 +- .../products/products_by_filter_result.dart | 13 +- .../usecases/promos/get_promos_use_case.dart | 4 +- lib/main.dart | 25 +-- lib/presentation/features/cart/cart_bloc.dart | 6 +- .../features/cart/cart_event.dart | 10 +- .../features/cart/cart_screen.dart | 2 +- .../features/cart/cart_state.dart | 26 +-- .../features/cart/views/cart_view.dart | 21 ++- .../cart/views/selected_attribute_view.dart | 3 +- .../categories/categories_screen.dart | 11 +- .../features/categories/categories_state.dart | 8 +- .../features/categories/views/list_view.dart | 7 +- .../features/categories/views/tile_view.dart | 14 +- .../features/checkout/checkout_event.dart | 14 +- .../features/checkout/checkout_state.dart | 30 ++-- .../views/add_shipping_address_view.dart | 23 ++- .../features/checkout/views/cart_view.dart | 19 +- .../checkout/views/payment_method_view.dart | 19 +- .../checkout/views/shipping_address_view.dart | 17 +- .../checkout/views/success1_view.dart | 2 +- .../checkout/views/success2_view.dart | 2 +- .../features/favorites/favorites_bloc.dart | 4 +- .../features/favorites/favorites_screen.dart | 6 +- .../features/favorites/favorites_state.dart | 27 +-- .../favorites/views/favourites_list_view.dart | 16 +- .../favorites/views/favourites_tile_view.dart | 16 +- .../filters/accept_bottom_navigation.dart | 6 +- .../filters/filter_selectable_item.dart | 4 +- .../filter_selectable_visible_option.dart | 4 +- .../features/filters/filters_screen.dart | 30 ++-- .../forget_password/forget_password_bloc.dart | 4 +- .../forget_password_screen.dart | 8 +- lib/presentation/features/home/home_bloc.dart | 6 +- .../features/home/home_event.dart | 6 +- .../features/home/home_screen.dart | 18 +- .../features/home/home_state.dart | 6 +- .../features/home/views/main1_view.dart | 12 +- .../features/home/views/main2_view.dart | 16 +- .../features/home/views/main3_view.dart | 14 +- .../product_details/product_bloc.dart | 2 +- .../product_details/product_event.dart | 4 +- .../product_details/product_screen.dart | 20 +-- .../product_details/product_state.dart | 10 +- .../views/attribute_bottom_sheet.dart | 57 +++--- .../product_details/views/details.dart | 52 +++--- .../product_review_and_rating_screen.dart | 25 +-- .../features/products/products_bloc.dart | 20 +-- .../features/products/products_event.dart | 4 +- .../features/products/products_screen.dart | 15 +- .../features/products/products_state.dart | 52 +++--- .../features/products/views/list_view.dart | 10 +- .../features/products/views/tile_view.dart | 12 +- .../products/views/visual_filter.dart | 4 +- .../features/profile/password_bloc.dart | 2 +- .../features/profile/password_event.dart | 6 +- .../features/profile/password_state.dart | 4 +- .../features/profile/profile_screen.dart | 2 +- .../features/profile/profile_state.dart | 4 +- .../features/profile/settings_bloc.dart | 28 +-- .../features/profile/settings_event.dart | 20 +-- .../features/profile/settings_state.dart | 22 +-- .../features/profile/views/order_details.dart | 30 ++-- .../features/profile/views/orders.dart | 14 +- .../profile/views/payment_methods.dart | 4 +- .../features/profile/views/profile.dart | 16 +- .../features/profile/views/promos.dart | 4 +- .../features/profile/views/reviews.dart | 4 +- .../features/profile/views/settings.dart | 28 +-- .../profile/views/shipping_addresses.dart | 4 +- .../features/sign_in/sign_in_bloc.dart | 10 +- .../features/sign_in/sign_in_event.dart | 2 +- .../features/sign_in/signin_screen.dart | 8 +- .../features/sign_up/sign_up_bloc.dart | 10 +- .../features/sign_up/sign_up_event.dart | 2 +- .../features/sign_up/sign_up_state.dart | 4 +- .../features/sign_up/signup_screen.dart | 10 +- lib/presentation/features/wrapper.dart | 4 +- .../widgets/data_driven/box_value_select.dart | 17 +- .../widgets/data_driven/cart_tile.dart | 17 +- .../data_driven/category_list_element.dart | 6 +- .../widgets/data_driven/category_tile.dart | 5 +- .../widgets/data_driven/hashtag_list.dart | 3 +- .../widgets/data_driven/order_tile.dart | 18 +- .../data_driven/product_list_view.dart | 9 +- .../widgets/data_driven/promo_tile.dart | 15 +- .../widgets/data_driven/rating_summary.dart | 19 +- .../data_driven/size_changing_app_bar.dart | 16 +- .../widgets/extensions/product_view.dart | 85 +++++---- .../widgets/independent/action_card.dart | 7 +- .../independent/base_product_list_item.dart | 41 ++--- .../independent/base_product_tile.dart | 21 ++- .../widgets/independent/block_header.dart | 18 +- .../widgets/independent/block_subtitle.dart | 26 +-- .../widgets/independent/bottom_menu.dart | 9 +- .../widgets/independent/bottom_popup.dart | 2 +- .../widgets/independent/clickable_line.dart | 20 +-- .../widgets/independent/color_select.dart | 16 +- .../widgets/independent/custom_button.dart | 25 ++- .../widgets/independent/custom_checkbox.dart | 15 +- .../widgets/independent/delivery_method.dart | 2 +- .../widgets/independent/error_dialog.dart | 4 +- .../widgets/independent/expansion_tile.dart | 8 +- .../widgets/independent/favourite_button.dart | 17 +- .../widgets/independent/input_button.dart | 6 +- .../widgets/independent/input_field.dart | 28 +-- .../independent/label_right_checkbox.dart | 12 +- .../widgets/independent/menu_line.dart | 10 +- .../widgets/independent/payment_card.dart | 4 +- .../independent/payment_card_preview.dart | 20 +-- .../widgets/independent/price_slider.dart | 20 +-- .../widgets/independent/product_rating.dart | 22 ++- .../independent/product_review_item.dart | 25 ++- .../independent/right_arrow_action.dart | 3 +- .../widgets/independent/scaffold.dart | 28 +-- .../independent/scaffold_collapsing.dart | 12 +- .../widgets/independent/search_bar.dart | 6 +- .../widgets/independent/service_button.dart | 4 +- .../widgets/independent/sortby.dart | 8 +- .../widgets/independent/summary_line.dart | 4 +- .../widgets/independent/text_tile.dart | 2 +- .../widgets/independent/view_options.dart | 19 +- pubspec.yaml | 2 +- 210 files changed, 1465 insertions(+), 1500 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 19a79c8c..c822467c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 29 + compileSdkVersion 31 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -40,7 +40,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.openflutter.openflutterecommerce" minSdkVersion 18 - targetSdkVersion 29 + targetSdkVersion 31 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 303a06f5..3906d35a 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -7,7 +7,6 @@ FlutterApplication and put your custom class here. --> + android:windowSoftInputMode="adjustResize" + android:exported="true"> diff --git a/lib/config/app_settings.dart b/lib/config/app_settings.dart index f0f953ed..6d31b012 100644 --- a/lib/config/app_settings.dart +++ b/lib/config/app_settings.dart @@ -1,4 +1,4 @@ class AppSettings { - static bool cacheIsEnabled; + static bool cacheIsEnabled = true; static bool profileEnabled = true; } diff --git a/lib/config/theme.dart b/lib/config/theme.dart index fee44f4b..09cfeb62 100644 --- a/lib/config/theme.dart +++ b/lib/config/theme.dart @@ -58,93 +58,93 @@ class OpenFlutterEcommerceTheme { iconTheme: IconThemeData(color: AppColors.black), textTheme: theme.textTheme.copyWith( caption: TextStyle( - color: AppColors.black, - fontSize: 18, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w400, - ))), + color: AppColors.black, + fontSize: 18, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w400, + ))), textTheme: theme.textTheme .copyWith( - //over image white text - headline5: theme.textTheme.headline5.copyWith( - fontSize: 48, - color: AppColors.white, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w900, - ), - headline6: theme.textTheme.headline6.copyWith( - fontSize: 24, - color: AppColors.black, - fontWeight: FontWeight.w900, - fontFamily: 'Metropolis', - ), // + //over image white text + headline5: theme.textTheme.headline5?.copyWith( + fontSize: 48, + color: AppColors.white, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w900, + ), + headline6: theme.textTheme.headline6?.copyWith( + fontSize: 24, + color: AppColors.black, + fontWeight: FontWeight.w900, + fontFamily: 'Metropolis', + ), // - //product title - headline4: theme.textTheme.headline4.copyWith( - color: AppColors.black, - fontSize: 16, - fontWeight: FontWeight.w400, - fontFamily: 'Metropolis', - ), + //product title + headline4: theme.textTheme.headline4?.copyWith( + color: AppColors.black, + fontSize: 16, + fontWeight: FontWeight.w400, + fontFamily: 'Metropolis', + ), - headline3: theme.textTheme.headline3.copyWith( - fontFamily: 'Metropolis', - fontWeight: FontWeight.w400, - ), - //product price - headline2: theme.textTheme.headline2.copyWith( - color: AppColors.lightGray, - fontSize: 14, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w400, - ), - headline1: theme.textTheme.headline1.copyWith( - fontFamily: 'Metropolis', - fontWeight: FontWeight.w500, - ), + headline3: theme.textTheme.headline3?.copyWith( + fontFamily: 'Metropolis', + fontWeight: FontWeight.w400, + ), + //product price + headline2: theme.textTheme.headline2?.copyWith( + color: AppColors.lightGray, + fontSize: 14, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w400, + ), + headline1: theme.textTheme.headline1?.copyWith( + fontFamily: 'Metropolis', + fontWeight: FontWeight.w500, + ), - subtitle2: theme.textTheme.subtitle2.copyWith( - fontSize: 18, - color: AppColors.black, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w400, - ), + subtitle2: theme.textTheme.subtitle2?.copyWith( + fontSize: 18, + color: AppColors.black, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w400, + ), - subtitle1: theme.textTheme.subtitle1.copyWith( - fontSize: 24, - color: AppColors.darkGray, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w500, - ), - //red button with white text - button: theme.textTheme.button.copyWith( - fontSize: 14, - color: AppColors.white, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w500, - ), - //black caption title - caption: theme.textTheme.caption.copyWith( - fontSize: 34, - color: AppColors.black, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w700, - ), - //light gray small text - bodyText1: theme.textTheme.bodyText1.copyWith( - color: AppColors.lightGray, - fontSize: 11, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w400, - ), - //view all link - bodyText2: theme.textTheme.bodyText2.copyWith( - color: AppColors.black, - fontSize: 11, - fontFamily: 'Metropolis', - fontWeight: FontWeight.w400, - ), - ) + subtitle1: theme.textTheme.subtitle1?.copyWith( + fontSize: 24, + color: AppColors.darkGray, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w500, + ), + //red button with white text + button: theme.textTheme.button?.copyWith( + fontSize: 14, + color: AppColors.white, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w500, + ), + //black caption title + caption: theme.textTheme.caption?.copyWith( + fontSize: 34, + color: AppColors.black, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w700, + ), + //light gray small text + bodyText1: theme.textTheme.bodyText1?.copyWith( + color: AppColors.lightGray, + fontSize: 11, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w400, + ), + //view all link + bodyText2: theme.textTheme.bodyText2?.copyWith( + color: AppColors.black, + fontSize: 11, + fontFamily: 'Metropolis', + fontWeight: FontWeight.w400, + ), + ) .apply(fontFamily: 'Metropolis'), buttonTheme: theme.buttonTheme.copyWith( minWidth: 50, diff --git a/lib/data/error/exceptions.dart b/lib/data/error/exceptions.dart index 4f09f487..820f7cc0 100644 --- a/lib/data/error/exceptions.dart +++ b/lib/data/error/exceptions.dart @@ -10,7 +10,7 @@ class LocalDbExceptionimplements implements Exception {} class EntityModelMapperException implements Exception { final String message; - EntityModelMapperException({@required this.message}); + EntityModelMapperException({required this.message}); } class RemoteServerException implements Exception {} diff --git a/lib/data/local/data_source.dart b/lib/data/local/data_source.dart index a8329754..bae6a12e 100644 --- a/lib/data/local/data_source.dart +++ b/lib/data/local/data_source.dart @@ -3,7 +3,7 @@ import 'package:openflutterecommerce/domain/entities/entity.dart'; import 'package:sqflite/sqflite.dart'; abstract class DataSource { - Database db; + late Database db; String get tableName; @@ -19,12 +19,12 @@ abstract class DataSource { // get a record in the table Future get(int id) async { - return null; + return Future.value(null); } // get all records in the table Future> all() async { - return null; + return []; } // insert a record into the table diff --git a/lib/data/local/db_provider.dart b/lib/data/local/db_provider.dart index 94d163ca..9f616a19 100644 --- a/lib/data/local/db_provider.dart +++ b/lib/data/local/db_provider.dart @@ -4,7 +4,7 @@ import 'package:sqflite/sqflite.dart'; class SQLiteDbProvider { - static Database db; + static late Database db; static Future open() async { db = await openDatabase( diff --git a/lib/data/local/local_category_repository.dart b/lib/data/local/local_category_repository.dart index 5be1668d..f47ee0ea 100644 --- a/lib/data/local/local_category_repository.dart +++ b/lib/data/local/local_category_repository.dart @@ -5,13 +5,13 @@ class LocalCategoryRepository extends CategoryRepository{ @override Future> getCategories({int parentCategoryId = 0}) async { // TODO: implement getCategories - return null; + return Future.value(null); } @override Future getCategoryDetails(int categoryId) { // TODO: implement getCategoryDetails - return null; + return Future.value(null); } } \ No newline at end of file diff --git a/lib/data/local/local_product_repository.dart b/lib/data/local/local_product_repository.dart index d5764c86..5a4174ab 100644 --- a/lib/data/local/local_product_repository.dart +++ b/lib/data/local/local_product_repository.dart @@ -25,14 +25,14 @@ class LocalProductRepository implements ProductRepository { int categoryId = 0, bool isFavorite = false, SortRules sortRules = const SortRules(), - FilterRules filterRules}) { + required FilterRules filterRules}) { // TODO: implement getProducts - return null; + return Future.value(null); } @override Future getPossibleFilterOptions(int categoryId) { // TODO: implement getPossibleFilterOptions - return null; + return Future.value(null); } } diff --git a/lib/data/local/local_promo_repository.dart b/lib/data/local/local_promo_repository.dart index 781597fc..57304fc7 100644 --- a/lib/data/local/local_promo_repository.dart +++ b/lib/data/local/local_promo_repository.dart @@ -5,7 +5,7 @@ class LocalPromoRepository implements PromoRepository { @override Future> getPromoList() { // TODO: implement getPromoList - return null; + return Future.value(null); } } diff --git a/lib/data/local/product/product_category_data_source.dart b/lib/data/local/product/product_category_data_source.dart index 4444c7d7..5149c896 100644 --- a/lib/data/local/product/product_category_data_source.dart +++ b/lib/data/local/product/product_category_data_source.dart @@ -15,7 +15,7 @@ class ProductCategoryDataSource extends DataSource { description: maps[i]['description'], image: maps[i]['image'], thumb: maps[i]['thumb'], - parentId: maps[i]['parentId'], + parentId: maps[i]['parentId'], orderNumber: null!, count: null!, ); }); } @@ -33,7 +33,7 @@ class ProductCategoryDataSource extends DataSource { description: maps[0]['description'], image: maps[0]['image'], thumb: maps[0]['thumb'], - parentId: maps[0]['parentId'], + parentId: maps[0]['parentId'], orderNumber: null!, count: null!, ); } diff --git a/lib/data/local/product/product_data_source.dart b/lib/data/local/product/product_data_source.dart index d382c74c..8c3753a7 100644 --- a/lib/data/local/product/product_data_source.dart +++ b/lib/data/local/product/product_data_source.dart @@ -18,7 +18,7 @@ class ProductDataSource extends DataSource { price: (maps[i]['price'] as num).toDouble(), discountPercent: (maps[i]['discountPercent'] as num).toDouble(), //TODO: get full list of categories - categories: [ProductCategoryEntity(id: (maps[i]['categoryId'] as num).toInt())], + categories: [ProductCategoryEntity(id: (maps[i]['categoryId'] as num).toInt(), title: '', description: '', image: '', thumb: '', parentId: null!, orderNumber: null!, count: null!)], amount: maps[i]['amount'], description: maps[i]['description'], isFavourite: maps[i]['isFavourite'].toString() == '1', @@ -27,7 +27,7 @@ class ProductDataSource extends DataSource { rating2Count: maps[i]['rating2Count'], rating3Count: maps[i]['rating3Count'], rating4Count: maps[i]['rating4Count'], - rating5Count: maps[i]['rating5Count'], + rating5Count: maps[i]['rating5Count'], subTitle: '', hashTags: [], selectableAttributes: [], ); }); } @@ -46,7 +46,7 @@ class ProductDataSource extends DataSource { thumb: maps[0]['thumb'], price: maps[0]['price'], discountPercent: (maps[0]['discountPercent'] as num).toDouble(), - categories: [ProductCategoryEntity(id: (maps[0]['categoryId'] as num).toInt())], + categories: [ProductCategoryEntity(id: (maps[0]['categoryId'] as num).toInt(), title: '', description: '', image: '', thumb: '', parentId: null!, orderNumber: null!, count: null!)], amount: maps[0]['amount'], description: maps[0]['description'], isFavourite: maps[0]['isFavourite'].toString() == '1', @@ -55,7 +55,7 @@ class ProductDataSource extends DataSource { rating2Count: maps[0]['rating2Count'], rating3Count: maps[0]['rating3Count'], rating4Count: maps[0]['rating4Count'], - rating5Count: maps[0]['rating5Count'], + rating5Count: maps[0]['rating5Count'], subTitle: '', hashTags: [], selectableAttributes: [], ); } diff --git a/lib/data/local/promo/promo_code_data_source.dart b/lib/data/local/promo/promo_code_data_source.dart index 823e52aa..47f829da 100644 --- a/lib/data/local/promo/promo_code_data_source.dart +++ b/lib/data/local/promo/promo_code_data_source.dart @@ -16,7 +16,7 @@ class PromoCodeDataSource extends DataSource { promoCode: maps[i]['promoCode'], discountPercent: maps[i]['discountPercent'], belongsToUser: maps[i]['belongsToUser'].toString() == '1', - wasUsed: maps[i]['wasUsed'].toString() == '1', + wasUsed: maps[i]['wasUsed'].toString() == '1', dateExpires: null!, ); }); } @@ -35,7 +35,7 @@ class PromoCodeDataSource extends DataSource { promoCode: maps[0]['promoCode'], discountPercent: maps[0]['discountPercent'], belongsToUser: maps[0]['belongsToUser'].toString() == '1', - wasUsed: maps[0]['wasUsed'].toString() == '1', + wasUsed: maps[0]['wasUsed'].toString() == '1', dateExpires: null!, ); } diff --git a/lib/data/local/user/user_data_source.dart b/lib/data/local/user/user_data_source.dart index 4936c691..71228525 100644 --- a/lib/data/local/user/user_data_source.dart +++ b/lib/data/local/user/user_data_source.dart @@ -20,7 +20,7 @@ class UserDataSource extends DataSource { newArrivalsNotification: maps[i]['newArrivalsNotification'].toString() == '1', deliveryStatusChanges: - maps[i]['deliveryStatusChanges'].toString() == '1', + maps[i]['deliveryStatusChanges'].toString() == '1', token: '', ); }); } @@ -42,7 +42,7 @@ class UserDataSource extends DataSource { salesNotification: maps[0]['salesNotification'].toString() == '1', newArrivalsNotification: maps[0]['newArrivalsNotification'].toString() == '1', - deliveryStatusChanges: maps[0]['deliveryStatusChanges'].toString() == '1', + deliveryStatusChanges: maps[0]['deliveryStatusChanges'].toString() == '1', token: '', ); } diff --git a/lib/data/model/app_user.dart b/lib/data/model/app_user.dart index 8ef1c268..cb78043e 100644 --- a/lib/data/model/app_user.dart +++ b/lib/data/model/app_user.dart @@ -3,5 +3,5 @@ class AppUser { final String password; final String token; - AppUser({this.email, this.password, this.token}); + AppUser({required this.email, required this.password, required this.token}); } diff --git a/lib/data/model/cart_item.dart b/lib/data/model/cart_item.dart index 1589f0a1..6164ce59 100644 --- a/lib/data/model/cart_item.dart +++ b/lib/data/model/cart_item.dart @@ -8,15 +8,15 @@ import 'product.dart'; class CartItem extends Equatable { final Product product; - final HashMap selectedAttributes; + final Map selectedAttributes; final ProductQuantity productQuantity; double get price => productQuantity.quantity * product.price; CartItem({ - @required this.product, - @required this.productQuantity, - @required this.selectedAttributes, + required this.product, + required this.productQuantity, + required this.selectedAttributes, }); void changeQuantity(int quantity){ diff --git a/lib/data/model/category.dart b/lib/data/model/category.dart index dda91d21..924fd07c 100644 --- a/lib/data/model/category.dart +++ b/lib/data/model/category.dart @@ -9,17 +9,17 @@ class ProductCategory extends Equatable { final int id; final int parentId; final String name; - final String description; + final String? description; final CommerceImage image; final bool isCategoryContainer; ProductCategory( this.id, { - int parentId, - this.name, + int? parentId, + required this.name, this.description, - this.image, - bool isCategoryContainer, + required this.image, + bool? isCategoryContainer, }) : parentId = parentId ?? 0, isCategoryContainer = isCategoryContainer ?? false; diff --git a/lib/data/model/favorite_product.dart b/lib/data/model/favorite_product.dart index 824b84da..6d0be91f 100644 --- a/lib/data/model/favorite_product.dart +++ b/lib/data/model/favorite_product.dart @@ -5,7 +5,7 @@ import 'package:openflutterecommerce/data/model/product_attribute.dart'; class FavoriteProduct { final Product product; - final HashMap favoriteForm; + final Map favoriteForm; FavoriteProduct(this.product, this.favoriteForm); } diff --git a/lib/data/model/filter_rules.dart b/lib/data/model/filter_rules.dart index a11c5e16..ad0700e4 100644 --- a/lib/data/model/filter_rules.dart +++ b/lib/data/model/filter_rules.dart @@ -16,22 +16,22 @@ class FilterRules { final List hashTags; final HashMap selectedHashTags; - FilterRules( - {this.categories, - @required this.hashTags, - @required this.selectedHashTags, - selectedAttributes, - this.selectableAttributes, - this.selectedPriceRange}) - : selectedAttributes = selectedAttributes ?? - HashMap>(); + FilterRules( + {required this.categories, + required this.hashTags, + required this.selectedHashTags, + selectedAttributes, + required this.selectableAttributes, + required this.selectedPriceRange}) + : selectedAttributes = + selectedAttributes ?? HashMap>(); FilterRules copyWithAdditionalAttribute( ProductAttribute attribute, String value) { HashMap> updatedAttributes = selectableAttributes; if (updatedAttributes.containsKey(attribute)) { - updatedAttributes[attribute].add(value); + updatedAttributes[attribute]?.add(value); } else { updatedAttributes[attribute] = [value]; } @@ -44,20 +44,18 @@ class FilterRules { } /// this behavior can be changed in subclasses to show special attribute instead of first - MapEntry> get topmostOption => - selectableAttributes?.entries?.isNotEmpty ? - selectableAttributes?.entries?.first - : MapEntry>( - ProductAttribute(name: ''), - [] - ); + MapEntry>? get topmostOption => + selectableAttributes?.entries?.isNotEmpty == true + ? selectableAttributes?.entries?.first + : MapEntry>( + ProductAttribute(name: '', id: -1, options: [], info: ''), []); FilterRules copyWithRemovedAttributeValue( ProductAttribute attribute, String value) { HashMap> updatedAttributes = selectableAttributes; - updatedAttributes[attribute].remove(value); - if (updatedAttributes[attribute].isEmpty) { + updatedAttributes[attribute]?.remove(value); + if (updatedAttributes[attribute]?.isEmpty == true) { updatedAttributes.remove(attribute); } return FilterRules( @@ -89,53 +87,56 @@ class FilterRules { List categoryIds = []; HashMap categories = HashMap(); List hashTagIds = []; - List hashTags = []; + List hashTags = []; products.forEach((product) => { - product.hashTags != null ? - product.hashTags.forEach((HashTag hashTag) => { - if ( !hashTagIds.contains(hashTag.id) ) { - hashTagIds.add(hashTag.id), - hashTags.add(hashTag) - } - }) : { }, - product.selectableAttributes != null ? - // returnAttributes.addAll({for (var attribute in product.selectableAttributes) attribute: []}) - product.selectableAttributes.forEach((attribute)=> { - if ( attribute != null ) { - if ( attributesIdToString[attribute.id] == null ) { - attributesIdToString[attribute.id] = [], - attributesIdToAttribute[attribute.id] = attribute - }, - attributesIdToString[attribute.id].addAll(attribute.options) - } - }) : { }, - if ( product.price > maxPrice ) maxPrice = product.price, - if ( product.price < minPrice ) minPrice = product.price, - //TOOD: change to categories instead of categoryIds - product.categories.forEach((ProductCategory category) => { - if ( !categoryIds.contains(category.id) ) { - categoryIds.add(category.id), - categories[category] = false - } - }) - }); + product.hashTags != null + ? product.hashTags.forEach((HashTag hashTag) => { + if (!hashTagIds.contains(hashTag.id)) + {hashTagIds.add(hashTag.id), hashTags.add(hashTag)} + }) + : {}, + product.selectableAttributes != null + ? + // returnAttributes.addAll({for (var attribute in product.selectableAttributes) attribute: []}) + product.selectableAttributes.forEach((attribute) => { + if (attribute != null) + { + if (attributesIdToString[attribute.id] == null) + { + attributesIdToString[attribute.id] = [], + attributesIdToAttribute[attribute.id] = attribute + }, + attributesIdToString[attribute.id] + ?.addAll(attribute.options) + } + }) + : {}, + if (product.price > maxPrice) maxPrice = product.price, + if (product.price < minPrice) minPrice = product.price, + //TOOD: change to categories instead of categoryIds + product.categories.forEach((ProductCategory category) => { + if (!categoryIds.contains(category.id)) + {categoryIds.add(category.id), categories[category] = false} + }) + }); attributesIdToString.keys.forEach((attributeById) => { - returnAttributes[attributesIdToAttribute[attributeById]]=attributesIdToString[attributeById].toSet().toList() - }); + returnAttributes[attributesIdToAttribute[attributeById]!!] = + attributesIdToString[attributeById]!.toSet().toList() + }); - return FilterRules( + return FilterRules( categories: categories, selectableAttributes: returnAttributes, hashTags: hashTags, selectedHashTags: HashMap(), - selectedPriceRange: PriceRange(minPrice, maxPrice) - ); + selectedPriceRange: PriceRange(minPrice, maxPrice)); } - factory FilterRules.getFavoriteSelectableAttributes(List favoriteProducts) { + factory FilterRules.getFavoriteSelectableAttributes( + List favoriteProducts) { List products = []; - favoriteProducts.forEach((favoriteProduct) { + favoriteProducts.forEach((favoriteProduct) { products.add(favoriteProduct.product); }); return FilterRules.getSelectableAttributes(products); diff --git a/lib/data/model/hashtag.dart b/lib/data/model/hashtag.dart index a5517f2a..2b4c15da 100644 --- a/lib/data/model/hashtag.dart +++ b/lib/data/model/hashtag.dart @@ -9,7 +9,7 @@ class HashTag extends Equatable { final int id; final String title; - HashTag({@required this.id, @required this.title}); + HashTag({required this.id, required this.title}); @override List get props => [id, title]; diff --git a/lib/data/model/payment_method.dart b/lib/data/model/payment_method.dart index 0f67ee0f..7e4bc3c9 100644 --- a/lib/data/model/payment_method.dart +++ b/lib/data/model/payment_method.dart @@ -1,42 +1,39 @@ - import 'package:flutter/material.dart'; import 'package:openflutterecommerce/domain/entities/checkout/payment_method_entity.dart'; class PaymentMethodModel extends PaymentMethodEntity { PaymentMethodModel( - {@required int id, - String nameOnCard, - String cardNumber, - int expiryDateMonth, - int expiryDateYear, - int cvv, - bool isDefault} - ) : super( - id: id, - nameOnCard: nameOnCard, - cardNumber: cardNumber, - expiryDateMonth: expiryDateMonth, - expiryDateYear: expiryDateYear, - cvv: cvv, - isDefault: isDefault); + {required int id, + required String nameOnCard, + required String cardNumber, + required int expiryDateMonth, + required int expiryDateYear, + required int cvv, + required bool isDefault}) + : super( + id: id, + nameOnCard: nameOnCard, + cardNumber: cardNumber, + expiryDateMonth: expiryDateMonth, + expiryDateYear: expiryDateYear, + cvv: cvv, + isDefault: isDefault); PaymentMethodModel copyWith( - {int id, - String nameOnCard, - String cardNumber, - int expiryDateMonth, - int expiryDateYear, - int cvv, - bool isDefault}) - { + {int? id, + String? nameOnCard, + String? cardNumber, + int? expiryDateMonth, + int? expiryDateYear, + int? cvv, + bool? isDefault}) { return PaymentMethodModel( - id: id ?? id, - nameOnCard: nameOnCard ?? nameOnCard, - cardNumber: cardNumber ?? cardNumber, - expiryDateMonth: expiryDateMonth ?? expiryDateMonth, - expiryDateYear: expiryDateYear ?? expiryDateYear, - cvv: cvv ?? cvv, - isDefault: isDefault ?? isDefault - ); + id: id! ?? id, + nameOnCard: nameOnCard! ?? nameOnCard, + cardNumber: cardNumber! ?? cardNumber, + expiryDateMonth: expiryDateMonth! ?? expiryDateMonth, + expiryDateYear: expiryDateYear! ?? expiryDateYear, + cvv: cvv! ?? cvv, + isDefault: isDefault! ?? isDefault); } } diff --git a/lib/data/model/predefined_attributes/color_attribute.dart b/lib/data/model/predefined_attributes/color_attribute.dart index f0828311..52fce293 100644 --- a/lib/data/model/predefined_attributes/color_attribute.dart +++ b/lib/data/model/predefined_attributes/color_attribute.dart @@ -5,6 +5,6 @@ import 'package:openflutterecommerce/data/model/product_attribute.dart'; class ColorAttribute extends ProductAttribute { final Map visibleColors; - ColorAttribute({int id, String info, this.visibleColors}) - : super(id: id, name: 'Color', info: info, options: visibleColors.keys); + ColorAttribute({required int id, required String info, required this.visibleColors}) + : super(id: id, name: 'Color', info: info, options: []); } diff --git a/lib/data/model/product.dart b/lib/data/model/product.dart index f4c0272e..372b24ac 100644 --- a/lib/data/model/product.dart +++ b/lib/data/model/product.dart @@ -36,26 +36,26 @@ class Product extends Equatable { Product( this.id, { - @required this.title, - @required this.subTitle, - this.shortDescription, - this.description, - @required this.price, + required this.title, + required this.subTitle, + required this.shortDescription, + required this.description, + required this.price, this.discountPercent = 0, this.amountAvailable = 0, - DateTime created, - this.averageRating, + required DateTime created, + required this.averageRating, this.ratingCount = 0, this.rating1Count = 0, this.rating2Count = 0, this.rating3Count = 0, this.rating4Count = 0, this.rating5Count = 0, - this.images, - this.properties, - this.selectableAttributes, - @required this.categories, - @required this.hashTags, + required this.images, + required this.properties, + required this.selectableAttributes, + required this.categories, + required this.hashTags, this.isFavorite = false, }) : created = created ?? DateTime.now(); @@ -80,7 +80,7 @@ class Product extends Equatable { categories: categories, hashTags: hashTags, selectableAttributes: selectableAttributes, - isFavorite: isFavorite??false); + isFavorite: isFavorite??false, properties: {}); } //Method mapping domain entity with presentation level model @@ -93,7 +93,7 @@ class Product extends Equatable { } List categories = []; if ( entity.categories.isNotEmpty ){ - entity.categories.forEach((category) => categories.add(ProductCategory(category.id, name: category.title))); + entity.categories.forEach((category) => categories.add(ProductCategory(category.id, name: category.title, image: CommerceImage.placeHolder()))); } List hashTags = []; if ( entity.hashTags.isNotEmpty ){ @@ -117,7 +117,7 @@ class Product extends Equatable { images: images, //TODO: add selectable attributes selectableAttributes: [], isFavorite: entity.isFavourite, - selectableAttributes: entity.selectableAttributes + selectableAttributes: entity.selectableAttributes, created: DateTime.now(), properties: {} ); } else { throw EntityModelMapperException(message: 'Entity should be of type ProductEntity'); @@ -160,7 +160,7 @@ class Product extends Equatable { } else if (isNew) { return 'New'; } else { - return null; + return ''; } } diff --git a/lib/data/model/product_attribute.dart b/lib/data/model/product_attribute.dart index 64c8382f..db74c527 100644 --- a/lib/data/model/product_attribute.dart +++ b/lib/data/model/product_attribute.dart @@ -8,7 +8,7 @@ class ProductAttribute extends Equatable { final String info; const ProductAttribute( - {this.id, @required this.name, this.options, this.info}); + {required this.id, required this.name, required this.options, required this.info}); @override List get props => [id, name, options, info]; diff --git a/lib/data/model/product_review.dart b/lib/data/model/product_review.dart index 73805e3a..5e5da9e6 100644 --- a/lib/data/model/product_review.dart +++ b/lib/data/model/product_review.dart @@ -12,15 +12,15 @@ class ProductReview extends Equatable { final List photos; ProductReview({ - this.id, - this.productId, - this.authorName, - this.authorPhotoUrl, - this.rating, - this.comment, - DateTime reviewDate, - this.isHelpful, - this.photos, + required this.id, + required this.productId, + required this.authorName, + required this.authorPhotoUrl, + required this.rating, + required this.comment, + DateTime? reviewDate, + required this.isHelpful, + required this.photos, }) : reviewDate = reviewDate ?? DateTime.now(); @override diff --git a/lib/data/model/promo.dart b/lib/data/model/promo.dart index c8c9e7b4..89a4a754 100644 --- a/lib/data/model/promo.dart +++ b/lib/data/model/promo.dart @@ -13,12 +13,12 @@ class Promo extends Equatable { final Color textColor; Promo( - {@required this.discount, - @required this.title, - @required this.promoCode, - @required this.daysLeft, - @required this.image, - @required this.textColor}); + {required this.discount, + required this.title, + required this.promoCode, + required this.daysLeft, + required this.image, + required this.textColor}); @override factory Promo.fromEntity(Entity entity) { @@ -29,7 +29,7 @@ class Promo extends Equatable { discount: entity.discountPercent, textColor: Colors.white, daysLeft: entity.dateExpires.difference(DateTime.now()).inDays, - image: null + image: "" ); } else { throw EntityModelMapperException(message: 'Entity should be of type ProductEntity'); diff --git a/lib/data/model/shipping_address.dart b/lib/data/model/shipping_address.dart index b11c6223..d27c2a09 100644 --- a/lib/data/model/shipping_address.dart +++ b/lib/data/model/shipping_address.dart @@ -4,14 +4,14 @@ import 'package:openflutterecommerce/domain/entities/checkout/shipping_address_e class ShippingAddressModel extends ShippingAddressEntity { ShippingAddressModel( - {@required int id, - String fullName, - String address, - String city, - String state, - String postal, - String country, - bool isDefault} + {required int id, + required String fullName, + required String address, + required String city, + required String state, + required String postal, + required country, + required bool isDefault} ) : super( id: id, fullName: fullName, @@ -23,24 +23,24 @@ class ShippingAddressModel extends ShippingAddressEntity { isDefault: isDefault); ShippingAddressModel copyWith( - {int id, - String fullName, - String address, - String city, - String state, - String postal, - String country, - bool isDefault}) + {int? id, + String? fullName, + String? address, + String? city, + String? state, + String? postal, + String? country, + bool? isDefault}) { return ShippingAddressModel( - id: id ?? id, - fullName: fullName ?? fullName, - address: address ?? address, - city: city ?? city, - state: state ?? state, - postal: postal ?? postal, - country: country ?? country, - isDefault: isDefault ?? isDefault + id: id! ?? id, + fullName: fullName! ?? fullName, + address: address! ?? address, + city: city! ?? city, + state: state! ?? state, + postal: postal! ?? postal, + country: country! ?? country, + isDefault: isDefault! ?? isDefault ); } } diff --git a/lib/data/model/user_order.dart b/lib/data/model/user_order.dart index 9b240d06..9de30b27 100644 --- a/lib/data/model/user_order.dart +++ b/lib/data/model/user_order.dart @@ -22,27 +22,29 @@ class UserOrder extends Equatable { final String trackingNumber; final DateTime orderDate; - double get totalPrice => - products.fold( + double get totalPrice => 0.0; + /*products.fold( 0, - (previousValue, element) => - previousValue += element.productQuantity.quantity * element.price) - - promo.discount; + (previousValue, element) => previousValue += + element.productQuantity.quantity * element.price) - + promo.discount;*/ int get totalQuantity => products.fold( - 0, (previousValue, element) => previousValue += element.productQuantity.quantity); + 0, + (previousValue, element) => + previousValue += element.productQuantity.quantity); UserOrder({ - this.id, - List products, - this.orderNumber, + required this.id, + required List products, + required this.orderNumber, this.orderStatus = UserOrderStatus.InProgress, - this.shippingAddress, - this.paymentMethod, - this.deliveryMethod, - this.trackingNumber, - this.promo, - DateTime orderCreated, + required this.shippingAddress, + required this.paymentMethod, + required this.deliveryMethod, + required this.trackingNumber, + required this.promo, + required DateTime orderCreated, }) : products = products ?? [], orderDate = orderCreated ?? DateTime.now(); diff --git a/lib/data/network/network_request.dart b/lib/data/network/network_request.dart index c3295503..ea709e49 100644 --- a/lib/data/network/network_request.dart +++ b/lib/data/network/network_request.dart @@ -22,11 +22,11 @@ class NetworkRequest { final String plainBody; NetworkRequest(this.type, this.address, - {@required this.client, - this.body, - this.plainBody, - this.listBody, - this.headers}); + {required this.client, + required this.body, + required this.plainBody, + required this.listBody, + required this.headers}); Future getResult() async { print('ADDRESS: $address'); @@ -103,7 +103,7 @@ class NetworkRequest { return NetworkRequest( RequestType.get, serverAddress, - client: client, + client: client, body: {}, plainBody: '', listBody: [], headers: {}, ); } } diff --git a/lib/data/repositories/abstract/favorites_repository.dart b/lib/data/repositories/abstract/favorites_repository.dart index a9b6c02e..e77d1107 100644 --- a/lib/data/repositories/abstract/favorites_repository.dart +++ b/lib/data/repositories/abstract/favorites_repository.dart @@ -30,7 +30,7 @@ abstract class FavoritesRepository { Product product, HashMap selectedAttributes); ///removes product with [productId] from the list of favorites - Future> removeFromFavorites(int productId, HashMap selectedAttributes); + Future> removeFromFavorites(int productId, Map selectedAttributes); //check if product was added to favorite bool checkFavorite(int productId); diff --git a/lib/data/repositories/abstract/product_repository.dart b/lib/data/repositories/abstract/product_repository.dart index 4c51cd5a..e0bd998d 100644 --- a/lib/data/repositories/abstract/product_repository.dart +++ b/lib/data/repositories/abstract/product_repository.dart @@ -30,7 +30,7 @@ abstract class ProductRepository { int pageSize = AppConsts.page_size, int categoryId = 0, SortRules sortRules = const SortRules(), - FilterRules filterRules, + required FilterRules filterRules, }); ///returns filter options available for products in category with diff --git a/lib/data/repositories/abstract/user_repository.dart b/lib/data/repositories/abstract/user_repository.dart index 3a08dc1f..2e23fa01 100644 --- a/lib/data/repositories/abstract/user_repository.dart +++ b/lib/data/repositories/abstract/user_repository.dart @@ -11,16 +11,16 @@ abstract class UserRepository { /// Sign in with [email] and [password] and return /// an access token as [String] Future signIn({ - @required String email, - @required String password, + required String email, + required String password, }); /// Sign up with [username] and [password] and return /// an access token as [String] Future signUp({ - @required String name, - @required String email, - @required String password, + required String name, + required String email, + required String password, }); /// Get the user information and return it as [AppUser] @@ -28,6 +28,6 @@ abstract class UserRepository { /// Send to [email] a user forget email Future forgotPassword({ - @required String email, + required String email, }); } diff --git a/lib/data/repositories/cart_repository_impl.dart b/lib/data/repositories/cart_repository_impl.dart index d2e5457d..97a1fab7 100644 --- a/lib/data/repositories/cart_repository_impl.dart +++ b/lib/data/repositories/cart_repository_impl.dart @@ -72,5 +72,5 @@ class CartRepositoryImpl extends CartRepository{ class CartProductDataStorage { List items = []; - Promo appliedPromo; + late Promo appliedPromo; } \ No newline at end of file diff --git a/lib/data/repositories/category_repository_impl.dart b/lib/data/repositories/category_repository_impl.dart index 9afb9de5..1af24060 100644 --- a/lib/data/repositories/category_repository_impl.dart +++ b/lib/data/repositories/category_repository_impl.dart @@ -32,6 +32,6 @@ class CategoryRepositoryImpl extends CategoryRepository { Future getCategoryDetails(int categoryId) async { // TODO: implement getCategoryDetails List categories = await getCategories(); - return categories.isNotEmpty ? categories[0] : null; + return categories.isNotEmpty ? categories[0] : null!; } } diff --git a/lib/data/repositories/fake_repos/order_repository.dart b/lib/data/repositories/fake_repos/order_repository.dart index 07e53037..5f80013d 100644 --- a/lib/data/repositories/fake_repos/order_repository.dart +++ b/lib/data/repositories/fake_repos/order_repository.dart @@ -20,9 +20,9 @@ class OrderRepository { } static const sizeAttribute = - ProductAttribute(name: 'size', options: ['S', 'M', 'L', 'XL']); + ProductAttribute(name: 'size', options: ['S', 'M', 'L', 'XL'], id: -1, info: ''); static const colorAttribute = - ProductAttribute(name: 'color', options: ['grey', 'red', 'yellow']); + ProductAttribute(name: 'color', options: ['grey', 'red', 'yellow'], id: -1, info: ''); final _myOrders = [ UserOrder( @@ -33,7 +33,7 @@ class OrderRepository { promo: Promo( daysLeft: 6, discount: 10, - image: null, + image: "", promoCode: 'promo12', textColor: Colors.white, title: 'Promo 12'), @@ -44,7 +44,7 @@ class OrderRepository { country: 'United States', fullName: 'John Smith', postal: '91709', - state: 'CA'), + state: 'CA', isDefault: false), paymentMethod: '**** **** **** 3947', deliveryMethod: 'FedEx, 3 days, \$15', trackingNumber: 'IW3475453455', @@ -58,7 +58,7 @@ class OrderRepository { promo: Promo( daysLeft: 6, discount: 10, - image: null, + image: "", promoCode: 'promo12', textColor: Colors.white, title: 'Promo 12'), @@ -69,7 +69,7 @@ class OrderRepository { country: 'United States', fullName: 'John Smith', postal: '91709', - state: 'CA'), + state: 'CA', isDefault: false), paymentMethod: '**** **** **** 3947', deliveryMethod: 'FedEx, 3 days, \$15', trackingNumber: 'IW3475453456', @@ -89,7 +89,7 @@ class OrderRepository { ratingCount: 10, price: 15, title: 'Pullover', - selectableAttributes: [sizeAttribute, colorAttribute], categories: [], hashTags: [], subTitle: null, + selectableAttributes: [sizeAttribute, colorAttribute], categories: [], hashTags: [], subTitle: "", shortDescription: '', description: '', created: DateTime.now(), properties: {}, ), selectedAttributes: HashMap.fromEntries([ MapEntry(sizeAttribute, 'S'), @@ -107,7 +107,7 @@ class OrderRepository { price: 15, title: 'T-shirt', selectableAttributes: [sizeAttribute, colorAttribute], - categories: [], hashTags: [], subTitle: null, + categories: [], hashTags: [], subTitle: "", shortDescription: '', description: '', created: DateTime.now(), properties: {}, ), selectedAttributes: HashMap.fromEntries([ MapEntry(sizeAttribute, 'S'), @@ -126,7 +126,7 @@ class OrderRepository { price: 15, title: 'Sport Dress', selectableAttributes: [sizeAttribute, colorAttribute], - categories: [], hashTags: [], subTitle: null, + categories: [], hashTags: [], subTitle: "", shortDescription: '', description: '', created: DateTime.now(), properties: {}, ), selectedAttributes: HashMap.fromEntries([ MapEntry(sizeAttribute, 'S'), @@ -138,7 +138,7 @@ class OrderRepository { promo: Promo( daysLeft: 6, discount: 10, - image: null, + image: "", promoCode: 'promo12', textColor: Colors.white, title: 'Promo 12'), @@ -149,7 +149,7 @@ class OrderRepository { country: 'United States', fullName: 'John Smith', postal: '91709', - state: 'CA'), + state: 'CA', isDefault: false), paymentMethod: '**** **** **** 3947', deliveryMethod: 'FedEx, 3 days, \$15', trackingNumber: 'IW3475453456', diff --git a/lib/data/repositories/fake_repos/product_review_repository.dart b/lib/data/repositories/fake_repos/product_review_repository.dart index 9c8caf4f..dd7ef7df 100644 --- a/lib/data/repositories/fake_repos/product_review_repository.dart +++ b/lib/data/repositories/fake_repos/product_review_repository.dart @@ -12,7 +12,7 @@ class ProductReviewRepository { 'https://images.unsplash.com/photo-1518806118471-f28b20a1d79d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80', rating: 4, comment: - 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'), + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua', isHelpful: null!, photos: []), ProductReview( id: 2, productId: 2, @@ -25,7 +25,7 @@ class ProductReviewRepository { photos: [ 'https://images.unsplash.com/photo-1518806118471-f28b20a1d79d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80', 'http://personal.psu.edu/xqz5228/jpg.jpg' - ], + ], isHelpful: null! ), ProductReview( id: 3, @@ -43,6 +43,7 @@ class ProductReviewRepository { 'https://images.unsplash.com/photo-1518806118471-f28b20a1d79d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80', 'http://personal.psu.edu/xqz5228/jpg.jpg' ], + isHelpful: null! ), ProductReview( id: 4, @@ -53,6 +54,7 @@ class ProductReviewRepository { rating: 1, comment: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua', + isHelpful: null!, photos: [] ), ProductReview( id: 5, @@ -81,6 +83,7 @@ class ProductReviewRepository { 'https://images.unsplash.com/photo-1518806118471-f28b20a1d79d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80', 'http://personal.psu.edu/xqz5228/jpg.jpg' ], + isHelpful: null! ), ProductReview( id: 7, @@ -91,7 +94,7 @@ class ProductReviewRepository { rating: 4, comment: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua', - isHelpful: true, + isHelpful: true, photos: [], ), ProductReview( id: 8, @@ -102,7 +105,7 @@ class ProductReviewRepository { rating: 5, comment: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua', - isHelpful: false, + isHelpful: false, photos: [], ), ]; diff --git a/lib/data/repositories/payment_method_repository_impl.dart b/lib/data/repositories/payment_method_repository_impl.dart index 107e2f71..5ac270e0 100644 --- a/lib/data/repositories/payment_method_repository_impl.dart +++ b/lib/data/repositories/payment_method_repository_impl.dart @@ -22,7 +22,7 @@ class PaymentMethodRepositoryImpl implements PaymentMethodRepository{ @override Future> getPaymentMethodList() async { - if ( dataStorage.paymentMethods?.isEmpty ) { + if ( dataStorage.paymentMethods?.isEmpty == true ) { FakePaymentMethodRepository repo = FakePaymentMethodRepository(); dataStorage.paymentMethods = await repo.getPaymentMethodList(); } @@ -43,7 +43,7 @@ class PaymentMethodRepositoryImpl implements PaymentMethodRepository{ dataStorage.paymentMethods.add( paymentMethod .copyWith( - isDefault: paymentMethod.id == paymentMethodId + isDefault: paymentMethod.id == paymentMethodId ) ); }); diff --git a/lib/data/repositories/product_repository_impl.dart b/lib/data/repositories/product_repository_impl.dart index 0db363ad..14ef60b9 100644 --- a/lib/data/repositories/product_repository_impl.dart +++ b/lib/data/repositories/product_repository_impl.dart @@ -17,9 +17,8 @@ import 'package:openflutterecommerce/locator.dart'; //Uses remote or local data depending on NetworkStatus class ProductRepositoryImpl extends ProductRepository with FavoritesRepository { - static ProductDataStorage dataStorage = ProductDataStorage(); - + @override Future getProduct(int id) { // TODO: implement getProduct @@ -52,29 +51,25 @@ class ProductRepositoryImpl extends ProductRepository with FavoritesRepository { int categoryId = 0, bool isFavorite = false, SortRules sortRules = const SortRules(), - FilterRules filterRules}) async { + FilterRules? filterRules}) async { // TODO: implement getProducts - try - { + try { NetworkStatus networkStatus = sl(); ProductRepository productRepository; - if ( networkStatus.isConnected != null ) { + if (networkStatus.isConnected != null) { productRepository = RemoteProductRepository(woocommerce: sl()); } else { productRepository = LocalProductRepository(); } - List products = await productRepository.getProducts(); + List products = await productRepository.getProducts(filterRules: null!); //check favorites dataStorage.products = []; - products.forEach( (product) =>{ - dataStorage.products.add( - product.favorite( - checkFavorite(product.id) - ) - ) - }); + products.forEach((product) => { + dataStorage.products + .add(product.favorite(checkFavorite(product.id))) + }); return dataStorage.products; } on HttpRequestException { @@ -83,16 +78,20 @@ class ProductRepositoryImpl extends ProductRepository with FavoritesRepository { } @override - Future addToFavorites(Product product, HashMap selectedAttributes) async { + Future addToFavorites(Product product, + HashMap selectedAttributes) async { dataStorage.favProducts.add(FavoriteProduct(product, selectedAttributes)); } @override - Future> getFavoriteProducts({int pageIndex = 0, int pageSize = AppConsts.page_size, - SortRules sortRules = const SortRules(), FilterRules filterRules}) async { + Future> getFavoriteProducts( + {int pageIndex = 0, + int pageSize = AppConsts.page_size, + SortRules sortRules = const SortRules(), + FilterRules? filterRules}) async { //TODO: remove when favorite feature will be implemented /*_dataStorage.products = await getProducts(); - _dataStorage.products.forEach((product) => + _dataStorage.products.forEach((product) => _dataStorage.favProducts.add(FavoriteProduct(product, HashMap())));*/ return dataStorage.favProducts; } @@ -104,11 +103,13 @@ class ProductRepositoryImpl extends ProductRepository with FavoritesRepository { } @override - Future> removeFromFavorites(int productId, HashMap selectedAttributes) async { + Future> removeFromFavorites(int productId, + Map selectedAttributes) async { //TODO: remove from database in the future - dataStorage.favProducts.removeWhere((product) => product.product.id == productId && - (selectedAttributes == null || product.favoriteForm == selectedAttributes) - ); + dataStorage.favProducts.removeWhere((product) => + product.product.id == productId && + (selectedAttributes == null || + product.favoriteForm == selectedAttributes)); return dataStorage.favProducts; } @@ -116,8 +117,8 @@ class ProductRepositoryImpl extends ProductRepository with FavoritesRepository { bool checkFavorite(int productId) { // TODO: implement checkFavorite bool isFavorite = false; - for( int i = 0; i < dataStorage.favProducts.length; i++) { - if ( dataStorage.favProducts[i].product.id == productId) { + for (int i = 0; i < dataStorage.favProducts.length; i++) { + if (dataStorage.favProducts[i].product.id == productId) { isFavorite = true; break; } @@ -129,4 +130,4 @@ class ProductRepositoryImpl extends ProductRepository with FavoritesRepository { class ProductDataStorage { List products = []; List favProducts = []; -} \ No newline at end of file +} diff --git a/lib/data/repositories/shipping_address_repository_impl.dart b/lib/data/repositories/shipping_address_repository_impl.dart index f7ba16e9..c2ce21de 100644 --- a/lib/data/repositories/shipping_address_repository_impl.dart +++ b/lib/data/repositories/shipping_address_repository_impl.dart @@ -20,7 +20,7 @@ class ShippingAddressRepositoryImpl implements ShippingAddressRepository{ @override Future> getShippingAddressList() async { - if ( dataStorage.shippingAddresses?.isEmpty ) { + if ( dataStorage.shippingAddresses?.isEmpty == true ) { FakeShippingAddressRepository repo = FakeShippingAddressRepository(); dataStorage.shippingAddresses = await repo.getShippingAddressList(); } diff --git a/lib/data/repositories/user_repository_impl.dart b/lib/data/repositories/user_repository_impl.dart index edf31bd5..58228db9 100644 --- a/lib/data/repositories/user_repository_impl.dart +++ b/lib/data/repositories/user_repository_impl.dart @@ -12,21 +12,21 @@ import 'package:openflutterecommerce/data/woocommerce/repositories/remote_user_r class UserRepositoryImpl extends UserRepository { final RemoteUserRepository remoteUserRepository; - UserRepositoryImpl({@required this.remoteUserRepository}); + UserRepositoryImpl({required this.remoteUserRepository}); @override Future signIn({ - @required String email, - @required String password, + required String email, + required String password, }) async { return remoteUserRepository.signIn(email: email, password: password); } @override Future signUp({ - @required String name, - @required String email, - @required String password, + required String name, + required String email, + required String password, }) async { return remoteUserRepository.signUp(name: name, email: email, password: password); } @@ -42,7 +42,7 @@ class UserRepositoryImpl extends UserRepository { @override Future forgotPassword({ - @required String email, + required String email, }) async { return remoteUserRepository.forgotPassword(email: email); } diff --git a/lib/data/woocommerce/models/product_category_model.dart b/lib/data/woocommerce/models/product_category_model.dart index 39bc47cf..a9cd8e0a 100644 --- a/lib/data/woocommerce/models/product_category_model.dart +++ b/lib/data/woocommerce/models/product_category_model.dart @@ -5,11 +5,11 @@ import 'package:openflutterecommerce/domain/entities/product/product_category_en class ProductCategoryModel extends ProductCategoryEntity { ProductCategoryModel( - {@required int id, - @required title, - @required description, - @required image, - @required thumb, + {required int id, + required title, + required description, + required image, + required thumb, parentId, orderNumber, count}) : super( diff --git a/lib/data/woocommerce/models/product_model.dart b/lib/data/woocommerce/models/product_model.dart index b34e0075..5b403451 100644 --- a/lib/data/woocommerce/models/product_model.dart +++ b/lib/data/woocommerce/models/product_model.dart @@ -5,53 +5,60 @@ import 'package:openflutterecommerce/domain/entities/product/product_category_en import 'package:openflutterecommerce/domain/entities/product/product_entity.dart'; class ProductModel extends ProductEntity { - ProductModel( - {@required int id, - @required title, - @required subTitle, - @required description, - @required images, - @required double price, - @required salePrice, - @required thumb, - @required selectableAttributes, - rating, - List categories, - List hashTags, - orderNumber, - count}) : super( - id: id, - title: title, - subTitle: subTitle, - price: price, - discountPercent: salePrice != 0 ? ((price - salePrice)/price*100).round().toDouble() : 0, - description: description, - selectableAttributes: selectableAttributes, - images: images, - thumb: thumb, - rating: rating, - categories: categories, - hashTags: hashTags - ); - + {required int id, + required title, + required subTitle, + required description, + required images, + required double price, + required salePrice, + required thumb, + required selectableAttributes, + rating, + required List categories, + required List hashTags, + orderNumber, + count}) + : super( + id: id, + title: title, + subTitle: subTitle, + price: price, + discountPercent: salePrice != 0 + ? ((price - salePrice) / price * 100).round().toDouble() + : 0, + description: description, + selectableAttributes: selectableAttributes, + images: images, + thumb: thumb, + rating: rating, + categories: categories, + hashTags: hashTags, + amount: -1, + isFavourite: false); + factory ProductModel.fromJson(Map json) { List images = []; - if ( json['images']!=null ) { + if (json['images'] != null) { (json['images'] as List).forEach((f) => images.add(f['src'])); } return ProductModel( - id: (json['id'] as num).toInt(), + id: (json['id'] as num).toInt(), title: json['name'], - subTitle: json['categories']!=null? json['categories'][0]['name']:'', + subTitle: json['categories'] != null ? json['categories'][0]['name'] : '', description: stripTags(json['description']), - rating: json['average_rating'] !=null ? double.parse(json['average_rating']) : 0, + rating: json['average_rating'] != null + ? double.parse(json['average_rating']) + : 0, images: images, - price: json['regular_price'] !=null && json['regular_price'] != '' ? - double.parse(json['regular_price']) : 0, - salePrice: json['sale_price'] !=null && json['sale_price'] != '' ? - double.parse(json['sale_price']) : 0, - thumb: json['images']!=null ? json['images'][0]['src'] : '', + price: json['regular_price'] != null && json['regular_price'] != '' + ? double.parse(json['regular_price']) + : 0, + salePrice: json['sale_price'] != null && json['sale_price'] != '' + ? double.parse(json['sale_price']) + : 0, + thumb: json['images'] != null ? json['images'][0]['src'] : '', //TODO: add all categories related to product categories: _getCategoriesFromJson(json), orderNumber: (json['menu_order'] as num).toInt(), @@ -60,47 +67,39 @@ class ProductModel extends ProductEntity { ); } - static List _getHashTagsFromJson(Map json){ + static List _getHashTagsFromJson(Map json) { List tags = []; - if ( json['tags']!= null ) { - for (var hashTag in json['tags']) { - tags.add( - HashTagEntity( - id: hashTag['id']??0, - title: hashTag['name']??'' - ) - ); + if (json['tags'] != null) { + for (var hashTag in json['tags']) { + tags.add(HashTagEntity( + id: hashTag['id'] ?? 0, title: hashTag['name'] ?? '')); } } return tags; } - static List _getCategoriesFromJson(Map json){ + static List _getCategoriesFromJson( + Map json) { List categories = []; - if ( json['categories']!= null ) { - for (var category in json['categories']) { - categories.add( - ProductCategoryEntity( - id: category['id']??0, - title: category['name']??'' - ) - ); + if (json['categories'] != null) { + for (var category in json['categories']) { + categories.add(ProductCategoryEntity( + id: category['id'] ?? 0, title: category['name'] ?? '', description: '', image: '', thumb: '', parentId: null!, orderNumber: null!, count: null!)); } } return categories; } - static List _getSelectableAttributesFromJson(Map json){ + static List _getSelectableAttributesFromJson( + Map json) { List selectableAttributes = []; - if ( json['attributes']!= null ) { - for (var attribute in json['attributes']) { - selectableAttributes.add( - ProductAttribute( - id: attribute['id']??0, - name: attribute['name']??'', - options: List.from(attribute['options']) - ) - ); + if (json['attributes'] != null) { + for (var attribute in json['attributes']) { + selectableAttributes.add(ProductAttribute( + id: attribute['id'] ?? 0, + name: attribute['name'] ?? '', + options: List.from(attribute['options']), + info: '')); } } return selectableAttributes; @@ -108,20 +107,17 @@ class ProductModel extends ProductEntity { Map toJson() { return { - 'id': id, + 'id': id, 'name': title, 'description': description, 'image': { - 'src': images.isNotEmpty?images[0]:'', + 'src': images.isNotEmpty ? images[0] : '', } }; } + static String stripTags(String htmlText) { - RegExp exp = RegExp( - r'<[^>]*>', - multiLine: true, - caseSensitive: true - ); + RegExp exp = RegExp(r'<[^>]*>', multiLine: true, caseSensitive: true); return htmlText.replaceAll(exp, ''); } } diff --git a/lib/data/woocommerce/models/promo_code_model.dart b/lib/data/woocommerce/models/promo_code_model.dart index 0711dcd1..2fd8ed5c 100644 --- a/lib/data/woocommerce/models/promo_code_model.dart +++ b/lib/data/woocommerce/models/promo_code_model.dart @@ -9,17 +9,20 @@ import 'package:openflutterecommerce/domain/entities/promo/promo_code_entity.dar class PromoCodeModel extends PromoCodeEntity { PromoCodeModel({ - int id, - String title, - String promoCode, - double discountPercent, - DateTime dateExpires + required int id, + required String title, + required String promoCode, + required double discountPercent, + required DateTime dateExpires }) : super( id: id, title: title, promoCode: promoCode, discountPercent: discountPercent, - dateExpires: dateExpires + dateExpires: dateExpires, + belongsToUser: false, + image: "", + wasUsed: false ); factory PromoCodeModel.fromJson(Map json) { diff --git a/lib/data/woocommerce/repositories/category_remote_repository.dart b/lib/data/woocommerce/repositories/category_remote_repository.dart index bf91472d..cc7d14f5 100644 --- a/lib/data/woocommerce/repositories/category_remote_repository.dart +++ b/lib/data/woocommerce/repositories/category_remote_repository.dart @@ -8,7 +8,7 @@ import 'package:openflutterecommerce/data/woocommerce/repositories/woocommerce_w class RemoteCategoryRepository extends CategoryRepository { final WoocommercWrapperAbstract woocommerce; - RemoteCategoryRepository({@required this.woocommerce}); + RemoteCategoryRepository({required this.woocommerce}); @override Future> getCategories({int parentCategoryId = 0}) async { @@ -28,6 +28,6 @@ class RemoteCategoryRepository extends CategoryRepository { @override Future getCategoryDetails(int categoryId) { // TODO: implement getCategoryDetails - return null; + return Future.value(null); } } diff --git a/lib/data/woocommerce/repositories/product_remote_repository.dart b/lib/data/woocommerce/repositories/product_remote_repository.dart index 779fb6f3..d2c7b809 100644 --- a/lib/data/woocommerce/repositories/product_remote_repository.dart +++ b/lib/data/woocommerce/repositories/product_remote_repository.dart @@ -13,7 +13,7 @@ class RemoteProductRepository extends ProductRepository { final WoocommercWrapperAbstract woocommerce; - RemoteProductRepository({@required this.woocommerce}); + RemoteProductRepository({required this.woocommerce}); @override Future getProduct(int id) { @@ -31,7 +31,7 @@ class RemoteProductRepository extends ProductRepository { @override Future getPossibleFilterOptions(int categoryId) { // TODO: implement getPossibleFilterOptions - return null; + return Future.value(null); } @override @@ -41,7 +41,7 @@ class RemoteProductRepository extends ProductRepository { int categoryId = 0, bool isFavorite = false, SortRules sortRules = const SortRules(), - FilterRules filterRules}) async { + required FilterRules filterRules}) async { // TODO: implement getProducts try { diff --git a/lib/data/woocommerce/repositories/promo_remote_repository.dart b/lib/data/woocommerce/repositories/promo_remote_repository.dart index da09213d..0d711153 100644 --- a/lib/data/woocommerce/repositories/promo_remote_repository.dart +++ b/lib/data/woocommerce/repositories/promo_remote_repository.dart @@ -8,7 +8,7 @@ import 'package:openflutterecommerce/data/woocommerce/repositories/woocommerce_w class RemotePromoRepository extends PromoRepository { final WoocommercWrapperAbstract woocommerce; - RemotePromoRepository({@required this.woocommerce}); + RemotePromoRepository({required this.woocommerce}); @override Future> getPromoList() async { diff --git a/lib/data/woocommerce/repositories/remote_user_repository.dart b/lib/data/woocommerce/repositories/remote_user_repository.dart index 994dcb12..f4d7bed4 100644 --- a/lib/data/woocommerce/repositories/remote_user_repository.dart +++ b/lib/data/woocommerce/repositories/remote_user_repository.dart @@ -17,8 +17,8 @@ import '../utils.dart'; class RemoteUserRepository extends UserRepository { @override Future signIn({ - @required String email, - @required String password, + required String email, + required String password, }) async { var route = HttpClient().createUri(ServerAddresses.authToken); var data = { @@ -36,9 +36,9 @@ class RemoteUserRepository extends UserRepository { @override Future signUp({ - @required String name, - @required String email, - @required String password, + required String name, + required String email, + required String password, }) async { try { var route = HttpClient().createUri(ServerAddresses.signUp); @@ -65,7 +65,7 @@ class RemoteUserRepository extends UserRepository { // TODO api call for user information await Future.delayed(Duration(seconds: 2)); - return AppUser(); + return AppUser(email: '', password: '', token: ''); } catch (error) { rethrow; } @@ -73,7 +73,7 @@ class RemoteUserRepository extends UserRepository { @override Future forgotPassword({ - @required String email, + required String email, }) async { try { var route = HttpClient().createUri(ServerAddresses.forgotPassword); diff --git a/lib/data/woocommerce/repositories/woocommerce_wrapper.dart b/lib/data/woocommerce/repositories/woocommerce_wrapper.dart index a31c232e..b89b0ed2 100644 --- a/lib/data/woocommerce/repositories/woocommerce_wrapper.dart +++ b/lib/data/woocommerce/repositories/woocommerce_wrapper.dart @@ -14,7 +14,7 @@ abstract class WoocommercWrapperAbstract { class WoocommerceWrapper implements WoocommercWrapperAbstract { final http.Client client; - WoocommerceWrapper({@required this.client}); + WoocommerceWrapper({required this.client}); @override Future> getProductList(ProductsByFilterParams params) { diff --git a/lib/domain/data_objects/product_rating.dart b/lib/domain/data_objects/product_rating.dart index 6c8f2488..4ca783d8 100644 --- a/lib/domain/data_objects/product_rating.dart +++ b/lib/domain/data_objects/product_rating.dart @@ -3,7 +3,7 @@ class ProductRating { final int quantity; ProductRating({ - this.rating, - this.quantity, + required this.rating, + required this.quantity, }); } diff --git a/lib/domain/entities/cart/product_cart_entity.dart b/lib/domain/entities/cart/product_cart_entity.dart index c1d74d81..938a25fc 100644 --- a/lib/domain/entities/cart/product_cart_entity.dart +++ b/lib/domain/entities/cart/product_cart_entity.dart @@ -6,10 +6,10 @@ class ProductCartEntity extends Entity { final double totalPrice; ProductCartEntity( - {int id, - this.productId, - this.productCount, - this.totalPrice}) : super(id); + {required int id, + required this.productId, + required this.productCount, + required this.totalPrice}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/checkout/payment_method_entity.dart b/lib/domain/entities/checkout/payment_method_entity.dart index a729c45b..19ab03c2 100644 --- a/lib/domain/entities/checkout/payment_method_entity.dart +++ b/lib/domain/entities/checkout/payment_method_entity.dart @@ -9,13 +9,13 @@ class PaymentMethodEntity extends Entity { final bool isDefault; PaymentMethodEntity( - {int id, - this.nameOnCard, - this.cardNumber, - this.expiryDateMonth, - this.expiryDateYear, - this.cvv, - this.isDefault}) : super(id); + {required int id, + required this.nameOnCard, + required this.cardNumber, + required this.expiryDateMonth, + required this.expiryDateYear, + required this.cvv, + required this.isDefault}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/checkout/shipping_address_entity.dart b/lib/domain/entities/checkout/shipping_address_entity.dart index 6a48bafa..37470866 100644 --- a/lib/domain/entities/checkout/shipping_address_entity.dart +++ b/lib/domain/entities/checkout/shipping_address_entity.dart @@ -11,14 +11,14 @@ class ShippingAddressEntity extends Entity { final bool isDefault; ShippingAddressEntity( - {int id, - @required this.fullName, - @required this.address, - @required this.city, - @required this.state, - @required this.postal, - @required this.country, - @required this.isDefault}) : super(id); + {required int id, + required this.fullName, + required this.address, + required this.city, + required this.state, + required this.postal, + required this.country, + required this.isDefault}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/delivery/delivery_method_entity.dart b/lib/domain/entities/delivery/delivery_method_entity.dart index 1637c630..84cdbbb0 100644 --- a/lib/domain/entities/delivery/delivery_method_entity.dart +++ b/lib/domain/entities/delivery/delivery_method_entity.dart @@ -5,9 +5,9 @@ class DeliveryMethodEntity extends Entity { final double price; DeliveryMethodEntity( - {int id, - this.title, - this.price}) : super(id); + {required int id, + required this.title, + required this.price}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/hashtag/category_hashtag_entity.dart b/lib/domain/entities/hashtag/category_hashtag_entity.dart index 468e6c4a..dbb50287 100644 --- a/lib/domain/entities/hashtag/category_hashtag_entity.dart +++ b/lib/domain/entities/hashtag/category_hashtag_entity.dart @@ -4,7 +4,7 @@ class CategoryHashTagEntity extends Entity { final int hashTagId; final int categoryId; - CategoryHashTagEntity({int id, this.hashTagId, this.categoryId}) : super(id); + CategoryHashTagEntity({required int id, required this.hashTagId, required this.categoryId}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/hashtag/hashtag_entity.dart b/lib/domain/entities/hashtag/hashtag_entity.dart index 1bde6185..063e4919 100644 --- a/lib/domain/entities/hashtag/hashtag_entity.dart +++ b/lib/domain/entities/hashtag/hashtag_entity.dart @@ -4,8 +4,8 @@ class HashTagEntity extends Entity { final String title; HashTagEntity({ - int id, - this.title, + required int id, + required this.title, }) : super(id); @override diff --git a/lib/domain/entities/hashtag/product_hashtag_entity.dart b/lib/domain/entities/hashtag/product_hashtag_entity.dart index ea604b14..4d63bb86 100644 --- a/lib/domain/entities/hashtag/product_hashtag_entity.dart +++ b/lib/domain/entities/hashtag/product_hashtag_entity.dart @@ -4,7 +4,7 @@ class ProductHashTagEntity extends Entity { final int hashTagId; final int productId; - ProductHashTagEntity({int id, this.hashTagId, this.productId}) : super(id); + ProductHashTagEntity({required int id, required this.hashTagId, required this.productId}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/order/order_product_entity.dart b/lib/domain/entities/order/order_product_entity.dart index 3c3db802..57166bb4 100644 --- a/lib/domain/entities/order/order_product_entity.dart +++ b/lib/domain/entities/order/order_product_entity.dart @@ -9,13 +9,13 @@ class OrderProductEntity extends Entity { final String thumb; OrderProductEntity( - {int id, - this.productId, - this.productCount, - this.totalPrice, - this.title, - this.discountPercent, - this.thumb}) : super(id); + {required int id, + required this.productId, + required this.productCount, + required this.totalPrice, + required this.title, + required this.discountPercent, + required this.thumb}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/order/order_product_parameter_entity.dart b/lib/domain/entities/order/order_product_parameter_entity.dart index 4532b429..7a1c0971 100644 --- a/lib/domain/entities/order/order_product_parameter_entity.dart +++ b/lib/domain/entities/order/order_product_parameter_entity.dart @@ -6,10 +6,10 @@ class OrderProductParameterEntity extends Entity { final int parameterValueId; OrderProductParameterEntity( - {int id, - this.productId, - this.parameterId, - this.parameterValueId}) : super(id); + {required int id, + required this.productId, + required this.parameterId, + required this.parameterValueId}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/order/user_order_entity.dart b/lib/domain/entities/order/user_order_entity.dart index 824b990e..84380cb7 100644 --- a/lib/domain/entities/order/user_order_entity.dart +++ b/lib/domain/entities/order/user_order_entity.dart @@ -14,18 +14,18 @@ class UserOrderEntity extends Entity { final double deliveryPrice; UserOrderEntity( - {int id, - this.orderNumber, - this.trackingNumber, - this.productCount, - this.promoCodeId, - this.discountPercent, - this.discountTitle, - this.shippingAddressId, - this.orderStatus, - this.totalAmount, - this.deliveryMethodId, - this.deliveryPrice}) : super(id); + {required int id, + required this.orderNumber, + required this.trackingNumber, + required this.productCount, + required this.promoCodeId, + required this.discountPercent, + required this.discountTitle, + required this.shippingAddressId, + required this.orderStatus, + required this.totalAmount, + required this.deliveryMethodId, + required this.deliveryPrice}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/product/product2parameter_entity.dart b/lib/domain/entities/product/product2parameter_entity.dart index ea795bc6..fabda846 100644 --- a/lib/domain/entities/product/product2parameter_entity.dart +++ b/lib/domain/entities/product/product2parameter_entity.dart @@ -5,9 +5,9 @@ class Product2ParameterEntity extends Entity { final int productId; Product2ParameterEntity( - {int id, - this.productParameterId, - this.productId}) : super(id); + {required int id, + required this.productParameterId, + required this.productId}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/product/product_category_entity.dart b/lib/domain/entities/product/product_category_entity.dart index 6154b19f..b35feb93 100644 --- a/lib/domain/entities/product/product_category_entity.dart +++ b/lib/domain/entities/product/product_category_entity.dart @@ -10,14 +10,14 @@ class ProductCategoryEntity extends Entity { final int count; ProductCategoryEntity( - {int id, - this.title, - this.description, - this.image, - this.thumb, - this.parentId, - this.orderNumber, - this.count}) : super(id); + {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); @override Map toMap() { diff --git a/lib/domain/entities/product/product_entity.dart b/lib/domain/entities/product/product_entity.dart index 1da30ff1..9095a734 100644 --- a/lib/domain/entities/product/product_entity.dart +++ b/lib/domain/entities/product/product_entity.dart @@ -25,19 +25,19 @@ class ProductEntity extends Entity { final List selectableAttributes; ProductEntity( - {int id, - this.title, - this.subTitle, - this.images, - this.thumb, - double price, - double discountPercent, - List categories, - List hashTags, - this.amount, - this.description, - this.selectableAttributes, - bool isFavourite, + {required int id, + required this.title, + required this.subTitle, + required this.images, + required this.thumb, + required double price, + required double discountPercent, + required List categories, + required List hashTags, + required this.amount, + required this.description, + required this.selectableAttributes, + required bool isFavourite, rating, rating1Count, rating2Count, diff --git a/lib/domain/entities/product/product_image_entity.dart b/lib/domain/entities/product/product_image_entity.dart index d0282bab..25780e5e 100644 --- a/lib/domain/entities/product/product_image_entity.dart +++ b/lib/domain/entities/product/product_image_entity.dart @@ -6,10 +6,10 @@ class ProductImageEntity extends Entity { final String image; ProductImageEntity({ - int id, - this.title, - this.thumb, - this.image}) : super(id); + required int id, + required this.title, + required this.thumb, + required this.image}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/product/product_parameter_entity.dart b/lib/domain/entities/product/product_parameter_entity.dart index c848fd3c..7874888c 100644 --- a/lib/domain/entities/product/product_parameter_entity.dart +++ b/lib/domain/entities/product/product_parameter_entity.dart @@ -4,8 +4,8 @@ class ProductParameterEntity extends Entity { final String title; ProductParameterEntity( - {int id, - this.title}) : super(id); + {required int id, + required this.title}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/product/product_parameter_variant_entity.dart b/lib/domain/entities/product/product_parameter_variant_entity.dart index 7370b92c..6c93300b 100644 --- a/lib/domain/entities/product/product_parameter_variant_entity.dart +++ b/lib/domain/entities/product/product_parameter_variant_entity.dart @@ -6,10 +6,10 @@ class ProductParameterVariantEntity extends Entity { final double additionalPrice; ProductParameterVariantEntity( - {int id, - this.title, - this.productParameterId, - this.additionalPrice}) : super(id); + {required int id, + required this.title, + required this.productParameterId, + required this.additionalPrice}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/product/product_review_entity.dart b/lib/domain/entities/product/product_review_entity.dart index 4b90098e..03f8ae53 100644 --- a/lib/domain/entities/product/product_review_entity.dart +++ b/lib/domain/entities/product/product_review_entity.dart @@ -10,14 +10,14 @@ class ProductReviewEntity extends Entity { final String thumb; ProductReviewEntity( - {int id, - this.description, - this.productId, - this.rating, - this.hasPhoto, - this.date, - this.author, - this.thumb}) : super(id); + {required int id, + required this.description, + required this.productId, + required this.rating, + required this.hasPhoto, + required this.date, + required this.author, + required this.thumb}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/product/product_review_photo_entity.dart b/lib/domain/entities/product/product_review_photo_entity.dart index e8e421f5..cd3c6334 100644 --- a/lib/domain/entities/product/product_review_photo_entity.dart +++ b/lib/domain/entities/product/product_review_photo_entity.dart @@ -5,9 +5,9 @@ class ProductReviewPhotoEntity extends Entity { final int reviewId; ProductReviewPhotoEntity({ - int id, - this.image, - this.reviewId, + required int id, + required this.image, + required this.reviewId, }) : super(id); @override diff --git a/lib/domain/entities/promo/promo_code_entity.dart b/lib/domain/entities/promo/promo_code_entity.dart index c0bf25cb..1754c15e 100644 --- a/lib/domain/entities/promo/promo_code_entity.dart +++ b/lib/domain/entities/promo/promo_code_entity.dart @@ -10,14 +10,14 @@ class PromoCodeEntity extends Entity { final DateTime dateExpires; PromoCodeEntity( - {int id, - this.title, - this.image, - this.promoCode, - this.discountPercent, - this.belongsToUser, - this.wasUsed, - this.dateExpires}) : super(id); + {required int id, + required this.title, + required this.image, + required this.promoCode, + required this.discountPercent, + required this.belongsToUser, + required this.wasUsed, + required this.dateExpires}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/user/settings.dart b/lib/domain/entities/user/settings.dart index a7df53f9..b53acb33 100644 --- a/lib/domain/entities/user/settings.dart +++ b/lib/domain/entities/user/settings.dart @@ -8,9 +8,9 @@ class UserSettingsEntity { bool notifyDelivery; UserSettingsEntity( - {@required this.fullName, - @required this.dateOfBirth, - @required this.notifySales, - @required this.notifyArrivals, - @required this.notifyDelivery}); + {required this.fullName, + required this.dateOfBirth, + required this.notifySales, + required this.notifyArrivals, + required this.notifyDelivery}); } diff --git a/lib/domain/entities/user/shipping_address_entity.dart b/lib/domain/entities/user/shipping_address_entity.dart index 8c482a2f..580c1e8d 100644 --- a/lib/domain/entities/user/shipping_address_entity.dart +++ b/lib/domain/entities/user/shipping_address_entity.dart @@ -9,13 +9,13 @@ class ShippingAddressEntity extends Entity { final bool isDefault; ShippingAddressEntity( - {int id, - this.title, - this.address, - this.city, - this.country, - this.postal, - this.isDefault}) : super(id); + {required int id, + required this.title, + required this.address, + required this.city, + required this.country, + required this.postal, + required this.isDefault}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/user/user_entity.dart b/lib/domain/entities/user/user_entity.dart index f5d06e50..02882c49 100644 --- a/lib/domain/entities/user/user_entity.dart +++ b/lib/domain/entities/user/user_entity.dart @@ -12,16 +12,16 @@ class UserEntity extends Entity { final bool deliveryStatusChanges; UserEntity( - {int id, - this.name, - this.avatar, - this.email, - this.password, - this.birthDate, - this.token, - this.salesNotification, - this.newArrivalsNotification, - this.deliveryStatusChanges}) : super(id); + {required int id, + required this.name, + required this.avatar, + required this.email, + required this.password, + required this.birthDate, + required this.token, + required this.salesNotification, + required this.newArrivalsNotification, + required this.deliveryStatusChanges}) : super(id); @override Map toMap() { diff --git a/lib/domain/entities/validator.dart b/lib/domain/entities/validator.dart index 07ab0e57..be2b2976 100644 --- a/lib/domain/entities/validator.dart +++ b/lib/domain/entities/validator.dart @@ -3,7 +3,7 @@ class Validator { if (value == null || value.isEmpty) { return 'Please fill this field'; } else { - return null; + return null!; } } @@ -15,7 +15,7 @@ class Validator { if (!regExp.hasMatch(value)) { return 'Your password must be at least 8 symbols with number, big and small letter and special character (!@#\$%^&*).'; } else { - return null; + return null!; } } else { return emptyResult; @@ -32,7 +32,7 @@ class Validator { } else if (!regExp.hasMatch(value)) { return 'Not a valid email address. Should be your@email.com'; } else { - return null; + return null!; } } } diff --git a/lib/domain/usecases/base_use_case.dart b/lib/domain/usecases/base_use_case.dart index 9eafcfc0..0886c25d 100644 --- a/lib/domain/usecases/base_use_case.dart +++ b/lib/domain/usecases/base_use_case.dart @@ -8,8 +8,8 @@ class UseCaseResult { final bool result; UseCaseResult({ - this.exception, - this.result + required this.exception, + required this.result }); bool get validResults => exception == null; diff --git a/lib/domain/usecases/cart/add_product_to_cart_use_case.dart b/lib/domain/usecases/cart/add_product_to_cart_use_case.dart index 37f21b42..c7cf3239 100644 --- a/lib/domain/usecases/cart/add_product_to_cart_use_case.dart +++ b/lib/domain/usecases/cart/add_product_to_cart_use_case.dart @@ -21,7 +21,7 @@ class AddProductToCartUseCaseImpl implements AddProductToCartUseCase { Future execute(CartItem item) async { try { CartRepositoryImpl.cartProductDataStorage.items.add(item); - return AddToCartResult(result: true); + return AddToCartResult(result: true, exception: null!); } catch (e) { return AddToCartResult( result: false, @@ -35,6 +35,6 @@ class AddProductToCartUseCaseImpl implements AddProductToCartUseCase { class AddProductToCartException implements Exception {} class AddToCartResult extends UseCaseResult { - AddToCartResult({Exception exception, bool result}) + AddToCartResult({required Exception exception, required bool result}) : super(exception: exception, result: result); } \ No newline at end of file diff --git a/lib/domain/usecases/cart/change_cart_item_quantity_use_case.dart b/lib/domain/usecases/cart/change_cart_item_quantity_use_case.dart index f88a656f..081b2271 100644 --- a/lib/domain/usecases/cart/change_cart_item_quantity_use_case.dart +++ b/lib/domain/usecases/cart/change_cart_item_quantity_use_case.dart @@ -19,7 +19,7 @@ class ChangeCartItemQuantityUseCaseImpl implements ChangeCartItemQuantityUseCase try { CartRepository cartReposiory = sl(); await cartReposiory.changeQuantity(params.item, params.quantity); - return ChangeCartItemQuantityResult(result: true); + return ChangeCartItemQuantityResult(result: true, exception: null!); } catch (e) { return ChangeCartItemQuantityResult( result: false, @@ -34,13 +34,13 @@ class ChangeCartItemQuantityParams { final CartItem item; final int quantity; - ChangeCartItemQuantityParams({this.item, this.quantity}); + ChangeCartItemQuantityParams({required this.item, required this.quantity}); } class ChangeCartItemQuantityResult extends UseCaseResult { ChangeCartItemQuantityResult({ - Exception exception, - bool result + required Exception exception, + required bool result }) : super(exception: exception, result: result); } 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 8f3d79c0..e5c762b6 100644 --- a/lib/domain/usecases/cart/get_cart_products_use_case.dart +++ b/lib/domain/usecases/cart/get_cart_products_use_case.dart @@ -31,14 +31,14 @@ class GetCartProductsUseCaseImpl implements GetCartProductsUseCase { totalPrice: cartRepository.getTotalPrice(), calculatedPrice: cartRepository.getCalculatedPrice(), appliedPromo: await cartRepository.getAppliedPromo(), - result: true); + result: true, exception: null!); } catch (e) { return GetCartProductsResult( cartItems: [], totalPrice: 0, calculatedPrice: 0, result: false, - exception: GetCartProductsException() + exception: GetCartProductsException(), appliedPromo: null! ); } } @@ -48,7 +48,7 @@ class GetCartProductsUseCaseImpl implements GetCartProductsUseCase { class GetCartProductParams { final Promo appliedPromo; - GetCartProductParams({this.appliedPromo}); + GetCartProductParams({required this.appliedPromo}); } class GetCartProductsException implements Exception {} @@ -60,12 +60,12 @@ class GetCartProductsResult extends UseCaseResult { final Promo appliedPromo; GetCartProductsResult({ - @required this.cartItems, - @required this.totalPrice, - @required this.calculatedPrice, - this.appliedPromo, - Exception exception, - bool result + required this.cartItems, + required this.totalPrice, + required this.calculatedPrice, + required this.appliedPromo, + required Exception exception, + required bool result }) : super(exception: exception, result: result); } \ No newline at end of file diff --git a/lib/domain/usecases/cart/remove_product_from_cart_use_case.dart b/lib/domain/usecases/cart/remove_product_from_cart_use_case.dart index 05ae73d1..a8a36e1f 100644 --- a/lib/domain/usecases/cart/remove_product_from_cart_use_case.dart +++ b/lib/domain/usecases/cart/remove_product_from_cart_use_case.dart @@ -18,7 +18,7 @@ class RemoveProductFromCartUseCaseImpl implements RemoveProductFromCartUseCase { Future execute(CartItem item) async { try { CartRepositoryImpl.cartProductDataStorage.items.remove(item); - return RemoveProductFromCartResult(result: true); + return RemoveProductFromCartResult(result: true, exception: null!); } catch (e) { return RemoveProductFromCartResult( result: false, @@ -31,6 +31,6 @@ class RemoveProductFromCartUseCaseImpl implements RemoveProductFromCartUseCase { class AddProductToCartException implements Exception {} class RemoveProductFromCartResult extends UseCaseResult { - RemoveProductFromCartResult({Exception exception, bool result}) + RemoveProductFromCartResult({required Exception exception, required bool result}) : super(exception: exception, result: result); } \ No newline at end of file diff --git a/lib/domain/usecases/categories/categories_by_filter_params.dart b/lib/domain/usecases/categories/categories_by_filter_params.dart index 58400977..0993c1e4 100644 --- a/lib/domain/usecases/categories/categories_by_filter_params.dart +++ b/lib/domain/usecases/categories/categories_by_filter_params.dart @@ -3,6 +3,6 @@ class CategoriesByFilterParams { final int categoryId; CategoriesByFilterParams({ - this.categoryId + required this.categoryId }); } \ No newline at end of file diff --git a/lib/domain/usecases/categories/categories_by_filter_result.dart b/lib/domain/usecases/categories/categories_by_filter_result.dart index 5787ddc7..97359d22 100644 --- a/lib/domain/usecases/categories/categories_by_filter_result.dart +++ b/lib/domain/usecases/categories/categories_by_filter_result.dart @@ -10,7 +10,7 @@ class CategoriesByFilterResult { CategoriesByFilterResult( this.categories, this.quantity,{ - this.exception + required this.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 9fd8718b..a6d0b52c 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 @@ -23,12 +23,12 @@ class FindCategoriesByFilterUseCaseImpl implements FindCategoriesByFilterUseCase List categories = await _categoryRepository.getCategories(parentCategoryId: params.categoryId); return CategoriesByFilterResult( categories, - categories.length + categories.length, exception: null! ); } catch (e) { return CategoriesByFilterResult( - null, + null!, 0, exception: EmptyCategoriesException() ); diff --git a/lib/domain/usecases/checkout/checkout_start_use_case.dart b/lib/domain/usecases/checkout/checkout_start_use_case.dart index b2b6346e..2bec2fb3 100644 --- a/lib/domain/usecases/checkout/checkout_start_use_case.dart +++ b/lib/domain/usecases/checkout/checkout_start_use_case.dart @@ -40,15 +40,15 @@ class CheckoutStartUseCaseImpl implements CheckoutStartUseCase { currentShippingAddress: await shippingAddressRepository.getDefaultShippingAddress(), totalCalculatedPrice: calculatedPrice, deliveryPrice: deliveryPrice, - summaryPrice: calculatedPrice + deliveryPrice + summaryPrice: calculatedPrice + deliveryPrice, exception: null! ); } catch (e) { return ChekcoutStartResult( result: false, exception: CheckoutStartException(), - currentPaymentMethod: null, - deliveryPrice: null, - totalCalculatedPrice: null + currentPaymentMethod: null!, + deliveryPrice: null!, + totalCalculatedPrice: null!, paymentMethods: [], shippingAddress: [], cartItems: [], currentShippingAddress: null!, summaryPrice: null! ); } } @@ -65,15 +65,15 @@ class ChekcoutStartResult extends UseCaseResult { final double summaryPrice; ChekcoutStartResult({ - this.paymentMethods, - this.shippingAddress, - this.cartItems, - this.currentShippingAddress, - @required this.currentPaymentMethod, - @required this.totalCalculatedPrice, - @required this.deliveryPrice, - this.summaryPrice, - Exception exception, bool result}) + required this.paymentMethods, + required this.shippingAddress, + required this.cartItems, + required this.currentShippingAddress, + required this.currentPaymentMethod, + required this.totalCalculatedPrice, + required this.deliveryPrice, + required this.summaryPrice, + required Exception exception, required bool result}) : super(exception: exception, result: result); } diff --git a/lib/domain/usecases/favorites/add_to_favorites_use_case.dart b/lib/domain/usecases/favorites/add_to_favorites_use_case.dart index 2faf1446..ca53657a 100644 --- a/lib/domain/usecases/favorites/add_to_favorites_use_case.dart +++ b/lib/domain/usecases/favorites/add_to_favorites_use_case.dart @@ -24,7 +24,7 @@ class AddToFavoritesUseCaseImpl implements AddToFavoritesUseCase { item.favoriteForm ) ); - return AddToFavoriteResult(result: true); + return AddToFavoriteResult(result: true, exception: null!); } catch (e) { return AddToFavoriteResult( result: false, @@ -38,6 +38,6 @@ class AddToFavoritesUseCaseImpl implements AddToFavoritesUseCase { class AddProductToCartException implements Exception {} class AddToFavoriteResult extends UseCaseResult { - AddToFavoriteResult({Exception exception, bool result}) + AddToFavoriteResult({required Exception exception, required bool result}) : super(exception: exception, result: result); } \ No newline at end of file diff --git a/lib/domain/usecases/favorites/get_favorite_products_use_case.dart b/lib/domain/usecases/favorites/get_favorite_products_use_case.dart index 4fe8f25c..29b3e30e 100644 --- a/lib/domain/usecases/favorites/get_favorite_products_use_case.dart +++ b/lib/domain/usecases/favorites/get_favorite_products_use_case.dart @@ -27,18 +27,18 @@ class GetFavoriteProductsUseCaseImpl implements GetFavoriteProductsUseCase { pageIndex: params.pageIndex, pageSize: params.pageSize, sortRules: params.sortRules, - filterRules: params.filterRules, + filterRules: params.filterRules!, ); return GetFavoriteProductResult( products: favoriteProducts, filterRules: FilterRules.getFavoriteSelectableAttributes(favoriteProducts), - result: true + result: true, exception: null! ); } catch (e) { return GetFavoriteProductResult( result: false, - exception: GetFavoriteProductException() + exception: GetFavoriteProductException(), products: [], filterRules: null! ); } } @@ -48,7 +48,7 @@ class GetFavoriteProductParams { final int pageIndex; final int pageSize; final SortRules sortRules; - final FilterRules filterRules; + final FilterRules? filterRules; GetFavoriteProductParams( { @@ -65,10 +65,10 @@ class GetFavoriteProductResult extends UseCaseResult { final FilterRules filterRules; GetFavoriteProductResult({ - this.products, - this.filterRules, - Exception exception, - bool result + required this.products, + required this.filterRules, + required Exception exception, + required bool result }) : super(exception: exception, result: result); } diff --git a/lib/domain/usecases/favorites/remove_from_favorites_use_case.dart b/lib/domain/usecases/favorites/remove_from_favorites_use_case.dart index 1f69f2f1..bf1206f0 100644 --- a/lib/domain/usecases/favorites/remove_from_favorites_use_case.dart +++ b/lib/domain/usecases/favorites/remove_from_favorites_use_case.dart @@ -21,7 +21,7 @@ class RemoveFromFavoritesUseCaseImpl implements RemoveFromFavoritesUseCase { await favoritesRepository.removeFromFavorites( params.product.product.id, params.product.favoriteForm); - return RemoveFromFavoritesResult(result: true); + return RemoveFromFavoritesResult(result: true, exception: null!); } catch (e) { return RemoveFromFavoritesResult( result: false, @@ -39,7 +39,7 @@ class RemoveFromFavoritesParams { } class RemoveFromFavoritesResult extends UseCaseResult { - RemoveFromFavoritesResult({Exception exception, bool result}) + RemoveFromFavoritesResult({required Exception exception, required bool result}) : super(exception: exception, result: result); } diff --git a/lib/domain/usecases/products/find_products_by_filter_use_case.dart b/lib/domain/usecases/products/find_products_by_filter_use_case.dart index b2ec4720..8d3d5d61 100644 --- a/lib/domain/usecases/products/find_products_by_filter_use_case.dart +++ b/lib/domain/usecases/products/find_products_by_filter_use_case.dart @@ -28,7 +28,7 @@ class FindProductsByFilterUseCaseImpl implements FindProductsByFilterUseCase { return ProductsByFilterResult( products, products.length, - FilterRules.getSelectableAttributes(products) + FilterRules.getSelectableAttributes(products), exception: null! ); } @@ -36,25 +36,25 @@ class FindProductsByFilterUseCaseImpl implements FindProductsByFilterUseCase { return ProductsByFilterResult( [], 0, - null, + null!, exception: EmptyProductsException() ); } return ProductsByFilterResult( [], 0, - null, + null!, exception: EmptyProductsException() ); } Future> _findProductsByFilter( ProductsByFilterParams params) async { - List products; + List products = []; if (params.filterByCategory) { ProductRepository productRepository = sl(); products = - await productRepository.getProducts(categoryId: params.categoryId); + await productRepository.getProducts(categoryId: params.categoryId, filterRules: null!); } return products; } diff --git a/lib/domain/usecases/products/get_home_products_use_case.dart b/lib/domain/usecases/products/get_home_products_use_case.dart index 55063e7d..1fdb2361 100644 --- a/lib/domain/usecases/products/get_home_products_use_case.dart +++ b/lib/domain/usecases/products/get_home_products_use_case.dart @@ -20,9 +20,9 @@ class GetHomePageProductsUseCaseImpl implements GetHomePageProductsUseCase { try { ProductRepository productRepository = sl(); return HomeProductsResult( - salesProducts: await productRepository.getProducts(categoryId: 1), - newProducts: await productRepository.getProducts(categoryId: 2), - result: false, + salesProducts: await productRepository.getProducts(categoryId: 1, filterRules: null!), + newProducts: await productRepository.getProducts(categoryId: 2, filterRules: null!), + result: false, exception: null!, ); } catch (e) { return HomeProductsResult( @@ -40,7 +40,7 @@ class HomeProductsResult extends UseCaseResult { final List salesProducts; final List newProducts; - HomeProductsResult({this.salesProducts, this.newProducts, Exception exception, bool result}) + HomeProductsResult({required this.salesProducts, required this.newProducts, required Exception exception, required bool result}) : super(exception: exception, result: result); } diff --git a/lib/domain/usecases/products/get_product_by_id_use_case.dart b/lib/domain/usecases/products/get_product_by_id_use_case.dart index 4ec506d8..7d1c6102 100644 --- a/lib/domain/usecases/products/get_product_by_id_use_case.dart +++ b/lib/domain/usecases/products/get_product_by_id_use_case.dart @@ -16,8 +16,8 @@ class GetProductByIdUseCaseImpl implements GetProductByIdUseCase { ProductRepository productRepository = sl(); //TODO: List products = - await productRepository.getProducts(categoryId: params.categoryId); - Product product; + await productRepository.getProducts(categoryId: params.categoryId, filterRules: null!); + Product product = null!; products.forEach((Product f) => { if ( f.id == params.productId) product = f } @@ -32,11 +32,11 @@ class ProductDetailsResults{ final Product productDetails; final List similarProducts; - ProductDetailsResults({this.productDetails, this.similarProducts}); + ProductDetailsResults({required this.productDetails, required this.similarProducts}); } class ProductDetailsParams{ final int productId; final int categoryId; - ProductDetailsParams({this.productId, this.categoryId}); + ProductDetailsParams({required this.productId, required this.categoryId}); } \ No newline at end of file diff --git a/lib/domain/usecases/products/products_by_filter_params.dart b/lib/domain/usecases/products/products_by_filter_params.dart index 67db7bd3..31211484 100644 --- a/lib/domain/usecases/products/products_by_filter_params.dart +++ b/lib/domain/usecases/products/products_by_filter_params.dart @@ -3,13 +3,13 @@ import 'package:openflutterecommerce/data/model/sort_rules.dart'; class ProductsByFilterParams { final int categoryId; - final SortRules sortBy; - final FilterRules filterRules; + final SortRules? sortBy; + final FilterRules? filterRules; ProductsByFilterParams({ - this.categoryId, - this.sortBy, - this.filterRules, + required this.categoryId, + this.sortBy, + this.filterRules, }); bool get filterByCategory => categoryId != null; diff --git a/lib/domain/usecases/products/products_by_filter_result.dart b/lib/domain/usecases/products/products_by_filter_result.dart index 82145a73..ea2667de 100644 --- a/lib/domain/usecases/products/products_by_filter_result.dart +++ b/lib/domain/usecases/products/products_by_filter_result.dart @@ -1,5 +1,3 @@ - - import 'package:openflutterecommerce/data/model/filter_rules.dart'; import 'package:openflutterecommerce/data/model/product.dart'; @@ -9,13 +7,8 @@ class ProductsByFilterResult { final int quantity; final Exception exception; - ProductsByFilterResult( - this.products, - this.quantity, - this.filterRules,{ - this.exception - } - ); + ProductsByFilterResult(this.products, this.quantity, this.filterRules, + {required this.exception}); bool get validResults => exception == null; -} \ No newline at end of file +} diff --git a/lib/domain/usecases/promos/get_promos_use_case.dart b/lib/domain/usecases/promos/get_promos_use_case.dart index 66fcaa0e..f3e22f08 100644 --- a/lib/domain/usecases/promos/get_promos_use_case.dart +++ b/lib/domain/usecases/promos/get_promos_use_case.dart @@ -24,7 +24,7 @@ class GetPromosUseCaseImpl implements GetPromosUseCase { if (promos != null && promos.isNotEmpty) { return GetPromosResult( promos: promos, - result: true + result: true, exception: null! ); } @@ -47,7 +47,7 @@ class GetPromosUseCaseImpl implements GetPromosUseCase { class GetPromosResult extends UseCaseResult { List promos; - GetPromosResult({this.promos, Exception exception, bool result}) + GetPromosResult({required this.promos, required Exception exception, required bool result}) : super(exception: exception, result: result); } diff --git a/lib/main.dart b/lib/main.dart index 972b9dc5..c6d1a08f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -34,12 +34,6 @@ import 'presentation/features/profile/profile.dart'; import 'locator.dart' as service_locator; class SimpleBlocDelegate extends BlocObserver { - @override - void onEvent(Bloc bloc, Object event) { - super.onEvent(bloc, event); - print(event); - } - @override void onTransition(Bloc bloc, Transition transition) { super.onTransition(bloc, transition); @@ -54,7 +48,7 @@ class SimpleBlocDelegate extends BlocObserver { } void main() async { - await service_locator.init(); + service_locator.init(); var delegate = await LocalizationDelegate.create( fallbackLocale: 'en_US', @@ -178,31 +172,22 @@ class OpenFlutterEcommerceApp extends StatelessWidget { Route _registerRoutesWithParameters(RouteSettings settings) { if (settings.name == OpenFlutterEcommerceRoutes.shop) { - final CategoriesParameters args = settings.arguments; return MaterialPageRoute( builder: (context) { - return CategoriesScreen( - parameters: args, - ); + return CategoriesScreen(); }, ); } else if (settings.name == OpenFlutterEcommerceRoutes.productList) { - final ProductListScreenParameters productListScreenParameters = - settings.arguments; return MaterialPageRoute(builder: (context) { - return ProductsScreen( - parameters: productListScreenParameters, - ); + return ProductsScreen(); }); } else if (settings.name == OpenFlutterEcommerceRoutes.product) { - final ProductDetailsParameters parameters = settings.arguments; return MaterialPageRoute(builder: (context) { - return ProductDetailsScreen(parameters); + return ProductDetailsScreen(); }); } else if (settings.name == OpenFlutterEcommerceRoutes.filters) { - final FilterRules filterRules = settings.arguments; return MaterialPageRoute(builder: (context) { - return FiltersScreen(filterRules); + return FiltersScreen(); }); } else { return MaterialPageRoute( diff --git a/lib/presentation/features/cart/cart_bloc.dart b/lib/presentation/features/cart/cart_bloc.dart index 41bd3837..83416794 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()); + final cartResults = await getCartProductsUseCase.execute(GetCartProductParams(appliedPromo: null!)); var promos = await getPromosUseCase.execute(GetPromosParams()); yield CartLoadedState( @@ -55,7 +55,7 @@ class CartBloc extends Bloc { quantity: event.newQuantity )); } - final cartResults = await getCartProductsUseCase.execute(GetCartProductParams()); + final cartResults = await getCartProductsUseCase.execute(GetCartProductParams(appliedPromo: null!)); yield CartLoadedState( cartProducts: cartResults.cartItems, promos: state.promos, @@ -66,7 +66,7 @@ class CartBloc extends Bloc { var state = this.state as CartLoadedState; yield CartLoadingState(); await removeProductFromCartUseCase.execute(event.item); - final cartResults = await getCartProductsUseCase.execute(GetCartProductParams()); + final cartResults = await getCartProductsUseCase.execute(GetCartProductParams(appliedPromo: null!)); yield CartLoadedState( cartProducts: cartResults.cartItems, promos: state.promos, diff --git a/lib/presentation/features/cart/cart_event.dart b/lib/presentation/features/cart/cart_event.dart index 45834150..d368cc63 100644 --- a/lib/presentation/features/cart/cart_event.dart +++ b/lib/presentation/features/cart/cart_event.dart @@ -21,35 +21,35 @@ class CartQuantityChangedEvent extends CartEvent { final CartItem item; final int newQuantity; - CartQuantityChangedEvent({this.item, this.newQuantity}); + CartQuantityChangedEvent({required this.item, required this.newQuantity}); } @immutable class CartRemoveFromCartEvent extends CartEvent { final CartItem item; - CartRemoveFromCartEvent({this.item}); + CartRemoveFromCartEvent({required this.item}); } @immutable class CartAddToFavsEvent extends CartEvent { final CartItem item; - CartAddToFavsEvent({this.item}); + CartAddToFavsEvent({required this.item}); } @immutable class CartPromoAppliedEvent extends CartEvent { final Promo promo; - CartPromoAppliedEvent({this.promo}); + CartPromoAppliedEvent({required this.promo}); } @immutable class CartPromoCodeAppliedEvent extends CartEvent { final String promoCode; - CartPromoCodeAppliedEvent({this.promoCode}); + CartPromoCodeAppliedEvent({required this.promoCode}); } @immutable diff --git a/lib/presentation/features/cart/cart_screen.dart b/lib/presentation/features/cart/cart_screen.dart index a7e4edba..e8f36187 100644 --- a/lib/presentation/features/cart/cart_screen.dart +++ b/lib/presentation/features/cart/cart_screen.dart @@ -21,7 +21,7 @@ class _CartScreenState extends State { return SafeArea( child: OpenFlutterScaffold( background: null, - title: null, + title: '', body: BlocProvider( create: (context) { return CartBloc() diff --git a/lib/presentation/features/cart/cart_state.dart b/lib/presentation/features/cart/cart_state.dart index cff19ea0..6e2842b2 100644 --- a/lib/presentation/features/cart/cart_state.dart +++ b/lib/presentation/features/cart/cart_state.dart @@ -24,25 +24,25 @@ class CartLoadedState extends CartState { final List cartProducts; final List promos; final bool showPromoPopup; - final double totalPrice; - final double calculatedPrice; - final Promo appliedPromo; + final double? totalPrice; + final double? calculatedPrice; + final Promo? appliedPromo; CartLoadedState( - {@required this.showPromoPopup, - @required this.promos, + {required this.showPromoPopup, + required this.promos, this.totalPrice, this.calculatedPrice, this.appliedPromo, - @required this.cartProducts}); + required this.cartProducts}); CartLoadedState copyWith( - {List cartProducts, - double totalPrice, - List promos, - Promo appliedPromo, - double calculatedPrice, - bool showPromoPopup}) { + {List? cartProducts, + double? totalPrice, + List? promos, + Promo? appliedPromo, + double? calculatedPrice, + bool? showPromoPopup}) { return CartLoadedState( promos: promos ?? this.promos, cartProducts: cartProducts ?? this.cartProducts, @@ -53,7 +53,7 @@ class CartLoadedState extends CartState { } @override - List get props => [totalPrice, cartProducts, appliedPromo, showPromoPopup]; + List get props => [totalPrice!, cartProducts, appliedPromo!, showPromoPopup]; } @immutable diff --git a/lib/presentation/features/cart/views/cart_view.dart b/lib/presentation/features/cart/views/cart_view.dart index 83f5f569..e301b891 100644 --- a/lib/presentation/features/cart/views/cart_view.dart +++ b/lib/presentation/features/cart/views/cart_view.dart @@ -17,17 +17,17 @@ import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; import '../cart.dart'; class CartView extends StatefulWidget { - final List products; + final List? products; final Function changeView; - const CartView({Key key, this.products, this.changeView}) : super(key: key); + const CartView({this.products, required this.changeView}) ; @override _CartViewState createState() => _CartViewState(); } class _CartViewState extends State { - TextEditingController _promoController; + late TextEditingController _promoController; @override void initState() { @@ -48,13 +48,12 @@ class _CartViewState extends State { final bloc = BlocProvider.of(context); return BlocListener(listener: (context, state) { if (state is CartErrorState) { - return Container( + Container( padding: EdgeInsets.all(AppSizes.sidePadding), child: Text('An error occured', style: _theme.textTheme.headline4 - .copyWith(color: _theme.errorColor))); + ?.copyWith(color: _theme.errorColor))); } - return Container(); }, child: BlocBuilder(builder: (context, state) { if (state is CartLoadedState) { return Stack(children: [ @@ -70,7 +69,7 @@ class _CartViewState extends State { ), OpenFlutterInputButton( placeHolder: state.appliedPromo != null - ? state.appliedPromo.promoCode + ? state.appliedPromo!.promoCode : 'Enter your promo code', controller: _promoController, width: width, @@ -83,20 +82,20 @@ class _CartViewState extends State { ? Column(children: [ OpenFlutterSummaryLine( title: 'Subtotal:', - summary: '\$' + state.totalPrice?.toStringAsFixed(2)), + summary: '\$' + state.totalPrice!.toStringAsFixed(2)), OpenFlutterSummaryLine( title: 'Discount percent:', summary: - state.appliedPromo.discount.toStringAsFixed(0) + + state.appliedPromo!.discount.toStringAsFixed(0) + '%'), OpenFlutterSummaryLine( title: 'Total amount:', summary: - '\$' + state.calculatedPrice?.toStringAsFixed(2)), + '\$' + state.calculatedPrice!.toStringAsFixed(2)), ]) : OpenFlutterSummaryLine( title: 'Subtotal:', - summary: '\$' + state.totalPrice?.toStringAsFixed(2)), + summary: '\$' + state.totalPrice!.toStringAsFixed(2)), Padding( padding: EdgeInsets.only(bottom: AppSizes.sidePadding * 3), ), diff --git a/lib/presentation/features/cart/views/selected_attribute_view.dart b/lib/presentation/features/cart/views/selected_attribute_view.dart index bbfdce89..3cefc809 100644 --- a/lib/presentation/features/cart/views/selected_attribute_view.dart +++ b/lib/presentation/features/cart/views/selected_attribute_view.dart @@ -6,8 +6,7 @@ class SelectedAttributeView extends StatelessWidget { final String selectedValue; const SelectedAttributeView( - {Key key, @required this.productAttribute, @required this.selectedValue}) - : super(key: key); + {required this.productAttribute, required this.selectedValue}); @override Widget build(BuildContext context) { diff --git a/lib/presentation/features/categories/categories_screen.dart b/lib/presentation/features/categories/categories_screen.dart index 01c30bcd..094ab807 100644 --- a/lib/presentation/features/categories/categories_screen.dart +++ b/lib/presentation/features/categories/categories_screen.dart @@ -11,9 +11,8 @@ import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; import 'categories.dart'; class CategoriesScreen extends StatefulWidget { - final CategoriesParameters parameters; - const CategoriesScreen({Key key, this.parameters}) : super(key: key); + const CategoriesScreen() ; @override _CategoriesScreenState createState() => _CategoriesScreenState(); @@ -28,14 +27,16 @@ class CategoriesParameters { class _CategoriesScreenState extends State { @override Widget build(BuildContext context) { - print('widget parameters at categories screen ${widget.parameters}'); + final args = ModalRoute.of(context)!.settings.arguments as CategoriesParameters; + + print('widget parameters at categories screen ${args}'); return SafeArea( child: BlocProvider( create: (context) { return CategoryBloc() - ..add(CategoryShowListEvent(widget.parameters == null + ..add(CategoryShowListEvent(args == null ? 0 - : widget.parameters.categoryId)); + : args.categoryId)); }, child: CategoriesWrapper())); } diff --git a/lib/presentation/features/categories/categories_state.dart b/lib/presentation/features/categories/categories_state.dart index 936e9809..54b942d7 100644 --- a/lib/presentation/features/categories/categories_state.dart +++ b/lib/presentation/features/categories/categories_state.dart @@ -26,7 +26,7 @@ class CategoryLoadingState extends CategoryState { abstract class CategoryViewState extends CategoryState { final List categories; - CategoryViewState({int parentCategoryId, this.categories}) + CategoryViewState({required int parentCategoryId, required this.categories}) : super(parentCategoryId: parentCategoryId); @override @@ -35,7 +35,7 @@ abstract class CategoryViewState extends CategoryState { @immutable class CategoryListViewState extends CategoryViewState { - CategoryListViewState({int parentCategoryId, List categories}) + CategoryListViewState({required int parentCategoryId, required List categories}) : super(parentCategoryId: parentCategoryId, categories: categories); @override @@ -45,8 +45,8 @@ class CategoryListViewState extends CategoryViewState { @immutable class CategoryTileViewState extends CategoryViewState { CategoryTileViewState({ - int parentCategoryId, - List categories, + required int parentCategoryId, + required List categories, }) : super( parentCategoryId: parentCategoryId, categories: categories, diff --git a/lib/presentation/features/categories/views/list_view.dart b/lib/presentation/features/categories/views/list_view.dart index 0a7ca1cc..8c4da70b 100644 --- a/lib/presentation/features/categories/views/list_view.dart +++ b/lib/presentation/features/categories/views/list_view.dart @@ -13,7 +13,7 @@ import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; import '../categories.dart'; class CategoriesListView extends StatefulWidget { - const CategoriesListView({Key key}) : super(key: key); + const CategoriesListView() ; @override _CategoriesListViewState createState() => _CategoriesListViewState(); @@ -28,13 +28,12 @@ class _CategoriesListViewState extends State { return BlocListener( listener: (context, state) { if (state is CategoryErrorState) { - return Container( + Container( padding: EdgeInsets.all(AppSizes.sidePadding), child: Text('An error occured', style: _theme.textTheme.headline4 - .copyWith(color: _theme.errorColor))); + ?.copyWith(color: _theme.errorColor))); } - return Container(); }, child: BlocBuilder(builder: (context, state) { if (state is CategoryListViewState) { diff --git a/lib/presentation/features/categories/views/tile_view.dart b/lib/presentation/features/categories/views/tile_view.dart index f677f922..5df46143 100644 --- a/lib/presentation/features/categories/views/tile_view.dart +++ b/lib/presentation/features/categories/views/tile_view.dart @@ -12,9 +12,9 @@ import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; import '../categories.dart'; class CategoriesTileView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const CategoriesTileView({Key key, this.changeView}) : super(key: key); + const CategoriesTileView({ this.changeView}) ; @override _CategoriesTileViewState createState() => _CategoriesTileViewState(); @@ -24,7 +24,7 @@ class _CategoriesTileViewState extends State with SingleTickerProviderStateMixin { final List types = ['Women', 'Men', 'Kids']; final List categotyIds = [1, 2, 3]; - TabController _tabController; + late TabController _tabController; @override void initState() { @@ -43,11 +43,11 @@ class _CategoriesTileViewState extends State listenWhen: (context, state) { return state is CategoryErrorState; }, listener: (BuildContext context, CategoryState state) { - return Container( + Container( padding: EdgeInsets.all(AppSizes.sidePadding), child: Text('An error occured', style: _theme.textTheme.headline4 - .copyWith(color: _theme.errorColor))); + ?.copyWith(color: _theme.errorColor))); }, child: BlocBuilder(builder: (context, state) { if (state is CategoryTileViewState) { @@ -69,10 +69,10 @@ class _CategoriesTileViewState extends State children: [ Text('SUMMER SALES', style: _theme.textTheme.headline4 - .copyWith(color: AppColors.white)), + ?.copyWith(color: AppColors.white)), Text('Up to 50% off', style: _theme.textTheme.headline4 - .copyWith(color: AppColors.white)) + ?.copyWith(color: AppColors.white)) ], ))), Container( diff --git a/lib/presentation/features/checkout/checkout_event.dart b/lib/presentation/features/checkout/checkout_event.dart index be67240f..1fa4050c 100644 --- a/lib/presentation/features/checkout/checkout_event.dart +++ b/lib/presentation/features/checkout/checkout_event.dart @@ -41,14 +41,14 @@ class CheckoutAddNewCardEvent extends CheckoutEvent { final int expirationMonth; final int expirationYear; final int cvv; - final bool setAsDefault; + final bool? setAsDefault; - CheckoutAddNewCardEvent({this.nameOnCard, this.cardNumber, - this.expirationMonth, this.expirationYear, - this.cvv, this.setAsDefault}); + CheckoutAddNewCardEvent({required this.nameOnCard, required this.cardNumber, + required this.expirationMonth, required this.expirationYear, + required this.cvv, this.setAsDefault}); @override - List get props => [nameOnCard, cardNumber, expirationMonth, expirationYear, cvv, setAsDefault]; + List get props => [nameOnCard, cardNumber, expirationMonth, expirationYear, cvv, setAsDefault!]; } @immutable @@ -69,6 +69,6 @@ class CheckoutAddNewShippingAddressEvent extends CheckoutEvent { final String country; CheckoutAddNewShippingAddressEvent({ - this.fullName, this.address, this.city, - this.state, this.postal, this.country}); + required this.fullName, required this.address, required this.city, + required this.state, required this.postal, required this.country}); } diff --git a/lib/presentation/features/checkout/checkout_state.dart b/lib/presentation/features/checkout/checkout_state.dart index f34f6b8d..75639651 100644 --- a/lib/presentation/features/checkout/checkout_state.dart +++ b/lib/presentation/features/checkout/checkout_state.dart @@ -23,11 +23,11 @@ class CheckoutInitialState extends CheckoutState { @immutable class CheckoutProceedState extends CheckoutState { - final List cartProducts; - final List shippingAddresses; - final List paymentMethods; - final ShippingAddressModel currentShippingAddress; - final PaymentMethodModel currentPaymentMethod; + final List? cartProducts; + final List? shippingAddresses; + final List? paymentMethods; + final ShippingAddressModel? currentShippingAddress; + final PaymentMethodModel? currentPaymentMethod; final double orderPrice; final double deliveryPrice; final double summaryPrice; @@ -35,24 +35,24 @@ class CheckoutProceedState extends CheckoutState { final bool showAddNewCardForm; CheckoutProceedState( - {@required this.cardId, + {required this.cardId, this.shippingAddresses, this.paymentMethods, this.cartProducts, this.currentShippingAddress, this.currentPaymentMethod, - @required this.orderPrice, - @required this.deliveryPrice, - @required this.summaryPrice, + required this.orderPrice, + required this.deliveryPrice, + required this.summaryPrice, this.showAddNewCardForm = false}); CheckoutProceedState copyWith( - {List cartProducts, int cardId, bool showAddNewCardForm, - double orderPrice, - double deliveryPrice, - double summaryPrice, }) { + {List? cartProducts, int? cardId, bool? showAddNewCardForm, + double? orderPrice, + double? deliveryPrice, + double? summaryPrice, }) { return CheckoutProceedState( - cartProducts: cartProducts ?? this.cartProducts, + cartProducts: /*cartProducts ?? */this.cartProducts, showAddNewCardForm: showAddNewCardForm ?? this.showAddNewCardForm, cardId: cardId ?? this.cardId, orderPrice: orderPrice ?? this.orderPrice, @@ -62,7 +62,7 @@ class CheckoutProceedState extends CheckoutState { } @override - List get props => [cartProducts, cardId, showAddNewCardForm]; + List get props => [cartProducts!, cardId, showAddNewCardForm]; } @immutable diff --git a/lib/presentation/features/checkout/views/add_shipping_address_view.dart b/lib/presentation/features/checkout/views/add_shipping_address_view.dart index a32717fe..67d3723d 100644 --- a/lib/presentation/features/checkout/views/add_shipping_address_view.dart +++ b/lib/presentation/features/checkout/views/add_shipping_address_view.dart @@ -11,9 +11,9 @@ import '../../wrapper.dart'; import '../checkout.dart'; class AddShippingAddressView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const AddShippingAddressView({Key key, this.changeView}) : super(key: key); + const AddShippingAddressView({ this.changeView}) ; @override _AddShippingAddressViewState createState() => _AddShippingAddressViewState(); @@ -22,12 +22,12 @@ class AddShippingAddressView extends StatefulWidget { class _AddShippingAddressViewState extends State { int paymentCardIndex = 0; - TextEditingController _fullNameController; - TextEditingController _addressController; - TextEditingController _cityController; - TextEditingController _stateController; - TextEditingController _postalController; - TextEditingController _countryController; + late TextEditingController _fullNameController; + late TextEditingController _addressController; + late TextEditingController _cityController; + late TextEditingController _stateController; + late TextEditingController _postalController; + late TextEditingController _countryController; @override void initState() { @@ -61,13 +61,12 @@ class _AddShippingAddressViewState extends State { bloc: bloc, listener: (BuildContext context, CheckoutState state) { if (state is CheckoutErrorState) { - return Container( + Container( padding: EdgeInsets.all(AppSizes.sidePadding), child: Text('An error occured', style: _theme.textTheme.headline4 - .copyWith(color: _theme.errorColor))); + ?.copyWith(color: _theme.errorColor))); } - return Container(); }, child: BlocBuilder( bloc: bloc, @@ -133,7 +132,7 @@ class _AddShippingAddressViewState extends State { state: _stateController.text, postal: _postalController.text, country: _countryController.text)), - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Backward) }), ) diff --git a/lib/presentation/features/checkout/views/cart_view.dart b/lib/presentation/features/checkout/views/cart_view.dart index c1f200a3..7019ff2a 100644 --- a/lib/presentation/features/checkout/views/cart_view.dart +++ b/lib/presentation/features/checkout/views/cart_view.dart @@ -15,9 +15,9 @@ import '../../wrapper.dart'; import '../checkout.dart'; class CartView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const CartView({Key key, this.changeView}) : super(key: key); + const CartView({ this.changeView}) ; @override _CartViewState createState() => _CartViewState(); @@ -34,13 +34,12 @@ class _CartViewState extends State { bloc: bloc, listener: (context, state) { if (state is CheckoutErrorState) { - return Container( + Container( padding: EdgeInsets.all(AppSizes.sidePadding), child: Text('An error occured', style: _theme.textTheme.headline4 - .copyWith(color: _theme.errorColor))); + ?.copyWith(color: _theme.errorColor))); } - return Container(); }, child: BlocBuilder( bloc: bloc, @@ -52,17 +51,17 @@ class _CartViewState extends State { OpenFlutterBlockSubtitle( title: 'Shipping Address', width: width), OpenFlutterActionCard( - title: state.currentShippingAddress.fullName, + title: state.currentShippingAddress!.fullName, linkText: 'Change', onLinkTap: (() => { - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Exact, index: 2) }), child: RichText( text: TextSpan( text: state.currentShippingAddress.toString(), style: _theme.textTheme.headline2 - .copyWith(color: _theme.primaryColor)), + ?.copyWith(color: _theme.primaryColor)), maxLines: 2, )), OpenFlutterBlockSubtitle( @@ -70,7 +69,7 @@ class _CartViewState extends State { width: width, linkText: 'Change', onLinkTap: (() => { - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Forward) }), ), @@ -105,7 +104,7 @@ class _CartViewState extends State { OpenFlutterButton( title: 'SUBMIT ORDER', onPressed: (() => { - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Exact, index: 4) }), ) diff --git a/lib/presentation/features/checkout/views/payment_method_view.dart b/lib/presentation/features/checkout/views/payment_method_view.dart index 3da9ef52..d4bf8a04 100644 --- a/lib/presentation/features/checkout/views/payment_method_view.dart +++ b/lib/presentation/features/checkout/views/payment_method_view.dart @@ -12,9 +12,9 @@ import '../../wrapper.dart'; import '../checkout.dart'; class PaymentMethodView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const PaymentMethodView({Key key, this.changeView}) : super(key: key); + const PaymentMethodView({ this.changeView}) ; @override _PaymentMethodViewState createState() => _PaymentMethodViewState(); @@ -23,10 +23,10 @@ class PaymentMethodView extends StatefulWidget { class _PaymentMethodViewState extends State { int paymentCardIndex = 0; - TextEditingController _nameOnCardController; - TextEditingController _cardNumberController; - TextEditingController _expirationDateController; - TextEditingController _cvvController; + late TextEditingController _nameOnCardController; + late TextEditingController _cardNumberController; + late TextEditingController _expirationDateController; + late TextEditingController _cvvController; @override void initState() { @@ -57,13 +57,12 @@ class _PaymentMethodViewState extends State { bloc: bloc, listener: (BuildContext context, CheckoutState state) { if (state is CheckoutErrorState) { - return Container( + Container( padding: EdgeInsets.all(AppSizes.sidePadding), child: Text('An error occured', style: _theme.textTheme.headline4 - .copyWith(color: _theme.errorColor))); + ?.copyWith(color: _theme.errorColor))); } - return Container(); }, child: BlocBuilder( bloc: bloc, @@ -196,7 +195,7 @@ class _PaymentMethodViewState extends State { void _changeDefaultPaymentCard(CheckoutBloc bloc, int cardId) { bloc..add(CheckoutSetDefaultCardEvent(cardId)); - widget.changeView(changeType: ViewChangeType.Exact, index: 0); + widget.changeView!(changeType: ViewChangeType.Exact, index: 0); //TODO: implement change of default payment card } } diff --git a/lib/presentation/features/checkout/views/shipping_address_view.dart b/lib/presentation/features/checkout/views/shipping_address_view.dart index dfef591f..51c196b5 100644 --- a/lib/presentation/features/checkout/views/shipping_address_view.dart +++ b/lib/presentation/features/checkout/views/shipping_address_view.dart @@ -14,9 +14,9 @@ import '../checkout_event.dart'; import '../checkout_state.dart'; class ShippingAddressView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const ShippingAddressView({Key key, this.changeView}) : super(key: key); + const ShippingAddressView({ this.changeView}) ; @override _ShippingAddressViewState createState() => _ShippingAddressViewState(); @@ -33,11 +33,10 @@ class _ShippingAddressViewState extends State { bloc: bloc, listener: (context, state) { if (state is CheckoutErrorState) { - return Container( + Container( padding: EdgeInsets.all(AppSizes.sidePadding), - child: Text('An error occured', style: _theme.textTheme.headline4.copyWith(color: _theme.errorColor))); + child: Text('An error occured', style: _theme.textTheme.headline4?.copyWith(color: _theme.errorColor))); } - return Container(); }, child: BlocBuilder( bloc: bloc, @@ -57,7 +56,7 @@ class _ShippingAddressViewState extends State { child: FloatingActionButton( mini: true, backgroundColor: _theme.primaryColor, - onPressed: (() => {widget.changeView(changeType: ViewChangeType.Forward)}), + onPressed: (() => {widget.changeView!(changeType: ViewChangeType.Forward)}), child: Icon(Icons.add, size: 36)), ), ])); @@ -68,12 +67,12 @@ class _ShippingAddressViewState extends State { return OpenFlutterActionCard( title: 'Jane Doe', linkText: 'Edit', - onLinkTap: (() => {widget.changeView(changeType: ViewChangeType.Forward)}), + onLinkTap: (() => {widget.changeView!(changeType: ViewChangeType.Forward)}), child: Column(children: [ RichText( text: TextSpan( text: '3 Newbridge Court Chino Hills, CA 91709, United States', - style: _theme.textTheme.headline2.copyWith(color: _theme.primaryColor)), + style: _theme.textTheme.headline2?.copyWith(color: _theme.primaryColor)), maxLines: 2, ), Container( @@ -90,6 +89,6 @@ class _ShippingAddressViewState extends State { void _changeDefaultShippingAddress(CheckoutBloc bloc, int shippingAddressId) { //TODO: pass datat to state bloc..add(CheckoutSetDefaultShippingAddressEvent(shippingAddressId)); - widget.changeView(changeType: ViewChangeType.Exact, index: 0); + widget.changeView!(changeType: ViewChangeType.Exact, index: 0); } } diff --git a/lib/presentation/features/checkout/views/success1_view.dart b/lib/presentation/features/checkout/views/success1_view.dart index 66d90a6f..ee8420d7 100644 --- a/lib/presentation/features/checkout/views/success1_view.dart +++ b/lib/presentation/features/checkout/views/success1_view.dart @@ -11,7 +11,7 @@ import '../../wrapper.dart'; class Success1View extends StatefulWidget { final Function changeView; - const Success1View({Key key, this.changeView}) : super(key: key); + const Success1View({ required this.changeView}) ; @override _Success1ViewState createState() => _Success1ViewState(); diff --git a/lib/presentation/features/checkout/views/success2_view.dart b/lib/presentation/features/checkout/views/success2_view.dart index 9fb9ad14..1a8b9d1f 100644 --- a/lib/presentation/features/checkout/views/success2_view.dart +++ b/lib/presentation/features/checkout/views/success2_view.dart @@ -11,7 +11,7 @@ import '../../wrapper.dart'; class Success2View extends StatefulWidget { final Function changeView; - const Success2View({Key key, this.changeView}) : super(key: key); + const Success2View({ required this.changeView}) ; @override _Success2ViewState createState() => _Success2ViewState(); diff --git a/lib/presentation/features/favorites/favorites_bloc.dart b/lib/presentation/features/favorites/favorites_bloc.dart index c194411b..14e0ed46 100644 --- a/lib/presentation/features/favorites/favorites_bloc.dart +++ b/lib/presentation/features/favorites/favorites_bloc.dart @@ -56,7 +56,7 @@ class FavouriteBloc extends Bloc { final filteredData = await getFavoriteProductsUseCase.execute( GetFavoriteProductParams( filterRules: event.filterRules, - sortRules: state.sortBy + sortRules: state.sortBy! ) ); yield state.copyWith( @@ -79,7 +79,7 @@ class FavouriteBloc extends Bloc { final filteredData = await getFavoriteProductsUseCase.execute( GetFavoriteProductParams( filterRules: state.filterRules, - sortRules: state.sortBy + sortRules: state.sortBy! ) ); yield state.copyWith(data: filteredData.products); diff --git a/lib/presentation/features/favorites/favorites_screen.dart b/lib/presentation/features/favorites/favorites_screen.dart index bdbdce41..cc3aeb71 100644 --- a/lib/presentation/features/favorites/favorites_screen.dart +++ b/lib/presentation/features/favorites/favorites_screen.dart @@ -20,7 +20,7 @@ class _FavouriteScreenState extends State { return SafeArea( child: OpenFlutterScaffold( background: null, - title: null, + title: '', body: BlocProvider( create: (context) { return FavouriteBloc()..add(ScreenLoadedEvent()); @@ -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/features/favorites/favorites_state.dart b/lib/presentation/features/favorites/favorites_state.dart index 1adc0b39..c9b1c427 100644 --- a/lib/presentation/features/favorites/favorites_state.dart +++ b/lib/presentation/features/favorites/favorites_state.dart @@ -11,11 +11,11 @@ import 'package:openflutterecommerce/data/model/sort_rules.dart'; @immutable class FavouriteState extends Equatable { - final List data; - final List hashtags; - final SortRules sortBy; - final FilterRules filterRules; - final String error; + final List? data; + final List? hashtags; + final SortRules? sortBy; + final FilterRules? filterRules; + final String? error; final bool isList; FavouriteState( @@ -27,12 +27,12 @@ class FavouriteState extends Equatable { this.isList = true}); FavouriteState copyWith({ - List data, - List hashtags, - SortRules sortBy, - FilterRules filterRules, - String error, - bool isList, + List? data, + List? hashtags, + SortRules? sortBy, + FilterRules? filterRules, + String? error, + bool? isList, }) { return FavouriteState( data: data ?? this.data, @@ -43,7 +43,9 @@ class FavouriteState extends Equatable { } bool get isProductsLoading => data == null; + bool get isFilterRulesVisible => filterRules != null; + bool get hasError => error != null; FavouriteState getLoading() { @@ -51,5 +53,6 @@ class FavouriteState extends Equatable { } @override - List get props => [data, hashtags, sortBy, filterRules, error, isProductsLoading]; + List get props => + [data!, hashtags!, sortBy!, filterRules!, error!, isProductsLoading]; } diff --git a/lib/presentation/features/favorites/views/favourites_list_view.dart b/lib/presentation/features/favorites/views/favourites_list_view.dart index e3c1aa69..cc16f2df 100644 --- a/lib/presentation/features/favorites/views/favourites_list_view.dart +++ b/lib/presentation/features/favorites/views/favourites_list_view.dart @@ -28,30 +28,30 @@ class FavoritesListView extends StatelessWidget { return Padding( padding: EdgeInsets.symmetric(horizontal: AppSizes.sidePadding), - child: state.data[index]?.getListView( + child: state.data![index]?.getListView( context: context, showProductInfo: () { Navigator.of(context).pushNamed( OpenFlutterEcommerceRoutes.product, arguments: ProductDetailsParameters( - state.data[index].product.id, - state.data[index].product.categories.isNotEmpty ? - state.data[index].product.categories[0].id: 0, + state.data![index].product.id, + state.data![index].product.categories.isNotEmpty ? + state.data![index].product.categories[0].id: 0, selectedAttributes: - state.data[index].favoriteForm)); + state.data![index].favoriteForm)); }, onRemoveFromFavorites: () { BlocProvider.of(context).add( RemoveFromFavoriteEvent( - state.data[index])); + state.data![index])); }, onAddToCart: () { BlocProvider.of(context) - .add(AddToCartEvent(state.data[index])); + .add(AddToCartEvent(state.data![index])); Navigator.of(context) .pushNamed(OpenFlutterEcommerceRoutes.cart); }, - selectedAttributes: state.data[index]?.favoriteForm + selectedAttributes: state.data![index]!.favoriteForm )); } }, diff --git a/lib/presentation/features/favorites/views/favourites_tile_view.dart b/lib/presentation/features/favorites/views/favourites_tile_view.dart index 2267462b..f543e388 100644 --- a/lib/presentation/features/favorites/views/favourites_tile_view.dart +++ b/lib/presentation/features/favorites/views/favourites_tile_view.dart @@ -28,28 +28,28 @@ class FavouritesTileView extends StatelessWidget { (BuildContext context, int index) { return Padding( padding: EdgeInsets.symmetric(horizontal: AppSizes.sidePadding), - child: state.data[index].getTileView( + child: state.data![index].getTileView( context: context, showProductInfo: () { Navigator.of(context).pushNamed( OpenFlutterEcommerceRoutes.product, arguments: ProductDetailsParameters( - state.data[index].product.id, - state.data[index].product.categories.isNotEmpty ? - state.data[index].product.categories[0].id: 0, - selectedAttributes: state.data[index].favoriteForm)); + state.data![index].product.id, + state.data![index].product.categories.isNotEmpty ? + state.data![index].product.categories[0].id: 0, + selectedAttributes: state.data![index].favoriteForm)); }, onRemoveFromFavorites: () { BlocProvider.of(context).add( - RemoveFromFavoriteEvent(state.data[index])); + RemoveFromFavoriteEvent(state.data![index])); }, onAddToCart: () { BlocProvider.of(context) - .add(AddToCartEvent(state.data[index])); + .add(AddToCartEvent(state.data![index])); Navigator.of(context) .pushNamed(OpenFlutterEcommerceRoutes.cart); }, - selectedAttributes: state.data[index]?.favoriteForm + selectedAttributes: state.data![index]!.favoriteForm ), ); }, diff --git a/lib/presentation/features/filters/accept_bottom_navigation.dart b/lib/presentation/features/filters/accept_bottom_navigation.dart index aeb56778..cd7d929e 100644 --- a/lib/presentation/features/filters/accept_bottom_navigation.dart +++ b/lib/presentation/features/filters/accept_bottom_navigation.dart @@ -3,9 +3,9 @@ import 'package:openflutterecommerce/config/theme.dart'; import 'package:openflutterecommerce/presentation/widgets/independent/custom_button.dart'; class AcceptBottomNavigation extends StatelessWidget { - final VoidCallback onApply; + final VoidCallback? onApply; - const AcceptBottomNavigation({Key key, this.onApply}) : super(key: key); + const AcceptBottomNavigation({this.onApply}); @override Widget build(BuildContext context) { @@ -27,7 +27,7 @@ class AcceptBottomNavigation extends StatelessWidget { Expanded( child: OpenFlutterButton( title: 'Apply', - onPressed: onApply, + onPressed: onApply!, ), ) ], diff --git a/lib/presentation/features/filters/filter_selectable_item.dart b/lib/presentation/features/filters/filter_selectable_item.dart index da34e309..e3a69f4c 100644 --- a/lib/presentation/features/filters/filter_selectable_item.dart +++ b/lib/presentation/features/filters/filter_selectable_item.dart @@ -5,7 +5,7 @@ class FilterSelectableItem extends StatelessWidget { final bool isSelected; final String text; - const FilterSelectableItem({Key key, this.isSelected = false, @required this.text}) : super(key: key); + const FilterSelectableItem({ this.isSelected = false, required this.text}) ; @override Widget build(BuildContext context) { @@ -20,7 +20,7 @@ class FilterSelectableItem extends StatelessWidget { padding: EdgeInsets.symmetric(vertical: AppSizes.sidePadding, horizontal: AppSizes.sidePadding), child: Text( text, - style: Theme.of(context).textTheme.headline2.copyWith( + style: Theme.of(context).textTheme.headline2?.copyWith( color: isSelected ? AppColors.white : Theme.of(context).primaryColor, fontWeight: FontWeight.bold, ), diff --git a/lib/presentation/features/filters/filter_selectable_visible_option.dart b/lib/presentation/features/filters/filter_selectable_visible_option.dart index 2591d7e1..62bec0a5 100644 --- a/lib/presentation/features/filters/filter_selectable_visible_option.dart +++ b/lib/presentation/features/filters/filter_selectable_visible_option.dart @@ -8,8 +8,8 @@ class FilterSelectableVisibleOption extends StatelessWidget { final String title; const FilterSelectableVisibleOption( - {Key key, this.onSelected, this.children, this.title}) - : super(key: key); + { required this.onSelected, required this.children, required this.title}) + ; @override Widget build(BuildContext context) { diff --git a/lib/presentation/features/filters/filters_screen.dart b/lib/presentation/features/filters/filters_screen.dart index 13bb0c85..ddcd79ee 100644 --- a/lib/presentation/features/filters/filters_screen.dart +++ b/lib/presentation/features/filters/filters_screen.dart @@ -9,12 +9,7 @@ import 'filter_selectable_item.dart'; import 'filter_selectable_visible_option.dart'; class FiltersScreen extends StatefulWidget { - final FilterRules initialRules; - - const FiltersScreen( - this.initialRules, { - Key key, - }) : super(key: key); + const FiltersScreen(); @override State createState() { @@ -23,16 +18,17 @@ class FiltersScreen extends StatefulWidget { } class _FiltersScreenState extends State { - FilterRules rules; + late FilterRules rules; @override void initState() { - rules = widget.initialRules; super.initState(); } @override Widget build(BuildContext context) { + final args = ModalRoute.of(context)!.settings.arguments as FilterRules; + rules = args; print(' selected attributes: ${rules.selectableAttributes}'); return Scaffold( appBar: AppBar( @@ -64,8 +60,12 @@ class _FiltersScreenState extends State { option, FilterSelectableItem( text: option, - isSelected: rules.selectedAttributes[attribute] != null - ? rules.selectedAttributes[attribute].contains(option) : false, + isSelected: + rules.selectedAttributes[attribute] != + null + ? rules.selectedAttributes[attribute] + !.contains(option) + : false, )))), ))) .values @@ -95,21 +95,21 @@ class _FiltersScreenState extends State { void _onCategorySelected(ProductCategory value) { setState(() { - rules.categories[value] = !rules.categories[value]; + rules.categories[value] = !rules.categories[value]!; }); } void _onAttributeSelected(ProductAttribute attribute, String value) { - if ( rules.selectedAttributes[attribute] == null ) { + if (rules.selectedAttributes[attribute] == null) { rules.selectedAttributes[attribute] = []; } - if (rules.selectedAttributes[attribute].contains(value)) { + if (rules.selectedAttributes[attribute]!.contains(value)) { setState(() { - rules.selectedAttributes[attribute].remove(value); + rules.selectedAttributes[attribute]!.remove(value); }); } else { setState(() { - rules.selectedAttributes[attribute].add(value); + rules.selectedAttributes[attribute]!.add(value); }); } } diff --git a/lib/presentation/features/forget_password/forget_password_bloc.dart b/lib/presentation/features/forget_password/forget_password_bloc.dart index 8ab3df5b..b569b0bb 100644 --- a/lib/presentation/features/forget_password/forget_password_bloc.dart +++ b/lib/presentation/features/forget_password/forget_password_bloc.dart @@ -8,7 +8,7 @@ class ForgetPasswordBloc extends Bloc { final UserRepository userRepository; - ForgetPasswordBloc({@required this.userRepository}):super(ForgetPasswordInitialState()); + ForgetPasswordBloc({required this.userRepository}):super(ForgetPasswordInitialState()); @override Stream mapEventToState( @@ -22,7 +22,7 @@ class ForgetPasswordBloc ); yield ForgetPasswordFinishedState(event.email); } catch (error) { - yield ForgetPasswordErrorState(error); + yield ForgetPasswordErrorState(error.toString()); } } } diff --git a/lib/presentation/features/forget_password/forget_password_screen.dart b/lib/presentation/features/forget_password/forget_password_screen.dart index df667a12..afe2abef 100644 --- a/lib/presentation/features/forget_password/forget_password_screen.dart +++ b/lib/presentation/features/forget_password/forget_password_screen.dart @@ -19,7 +19,7 @@ class _ForgetPasswordScreenState extends State { final TextEditingController emailController = TextEditingController(); final GlobalKey emailKey = GlobalKey(); - double sizeBetween; + late double sizeBetween; @override Widget build(BuildContext context) { @@ -38,7 +38,7 @@ class _ForgetPasswordScreenState extends State { listener: (context, state) { // on success push back if (state is ForgetPasswordFinishedState) { - Scaffold.of(context).showSnackBar( + ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( 'An email with password reminder was sent to ${state.email}'), @@ -49,7 +49,7 @@ class _ForgetPasswordScreenState extends State { } // on failure show a snackbar if (state is ForgetPasswordErrorState) { - Scaffold.of(context).showSnackBar( + ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('${state.error}'), backgroundColor: Colors.red, // TODO use app colors @@ -140,7 +140,7 @@ class _ForgetPasswordScreenState extends State { } void _validateAndSend() { - if (emailKey.currentState.validate() != null) { + if (emailKey.currentState?.validate() != null) { return; } BlocProvider.of(context).add( diff --git a/lib/presentation/features/home/home_bloc.dart b/lib/presentation/features/home/home_bloc.dart index 57a2c0a2..b441a321 100644 --- a/lib/presentation/features/home/home_bloc.dart +++ b/lib/presentation/features/home/home_bloc.dart @@ -33,14 +33,14 @@ class HomeBloc extends Bloc { yield state; } } else if (event is HomeAddToFavoriteEvent) { - if (event.isFavorite) { + if (event.isFavorite!) { await addToFavoritesUseCase.execute( - FavoriteProduct(event.product, null) + FavoriteProduct(event.product!, null!) ); } else { await removeFromFavoritesUseCase.execute( RemoveFromFavoritesParams( - FavoriteProduct(event.product, null) + FavoriteProduct(event.product!, null!) ) ); } diff --git a/lib/presentation/features/home/home_event.dart b/lib/presentation/features/home/home_event.dart index b211441e..a32f3991 100644 --- a/lib/presentation/features/home/home_event.dart +++ b/lib/presentation/features/home/home_event.dart @@ -19,11 +19,11 @@ class HomeLoadEvent extends HomeEvent { } class HomeAddToFavoriteEvent extends HomeEvent { - final bool isFavorite; - final Product product; + final bool? isFavorite; + final Product? product; HomeAddToFavoriteEvent({this.isFavorite, this.product}); @override - List get props => [isFavorite, product]; + List get props => [isFavorite!, product!]; } diff --git a/lib/presentation/features/home/home_screen.dart b/lib/presentation/features/home/home_screen.dart index dfec3613..07e3f027 100644 --- a/lib/presentation/features/home/home_screen.dart +++ b/lib/presentation/features/home/home_screen.dart @@ -21,11 +21,10 @@ class _HomeScreenState extends State { return SafeArea( child: OpenFlutterScaffold( background: null, - title: null, + title: '', body: BlocProvider( create: (context) { - return HomeBloc() - ..add(HomeLoadEvent()); + return HomeBloc()..add(HomeLoadEvent()); }, child: HomeWrapper()), bottomMenuIndex: 0, @@ -48,13 +47,14 @@ class _HomeWrapperState extends OpenFlutterWrapperState { return getPageView([ Main1View( changeView: changePage, - products: state is HomeLoadedState ? state.newProducts : [],), + products: state is HomeLoadedState ? state.newProducts : [], + ), Main2View( - changeView: changePage, - salesProducts: - state is HomeLoadedState ? state.salesProducts : [], - newProducts: - state is HomeLoadedState ? state.newProducts : []), + changeView: changePage, + salesProducts: + state is HomeLoadedState ? state.salesProducts : [], + newProducts: + state is HomeLoadedState ? state.newProducts : []), Main3View(changeView: changePage) ]); }); diff --git a/lib/presentation/features/home/home_state.dart b/lib/presentation/features/home/home_state.dart index 5432a5a4..6e54c89b 100644 --- a/lib/presentation/features/home/home_state.dart +++ b/lib/presentation/features/home/home_state.dart @@ -20,8 +20,8 @@ class HomeInitialState extends HomeState { @immutable class HomeLoadedState extends HomeState { - final List salesProducts; - final List newProducts; + final List? salesProducts; + final List? newProducts; HomeLoadedState({this.salesProducts, this.newProducts}); @@ -29,5 +29,5 @@ class HomeLoadedState extends HomeState { String toString() => 'HomeLoadedState'; @override - List get props => [salesProducts, newProducts]; + List get props => [salesProducts!, newProducts!]; } diff --git a/lib/presentation/features/home/views/main1_view.dart b/lib/presentation/features/home/views/main1_view.dart index 63bd378f..b31e122f 100644 --- a/lib/presentation/features/home/views/main1_view.dart +++ b/lib/presentation/features/home/views/main1_view.dart @@ -16,10 +16,10 @@ import 'package:openflutterecommerce/presentation/features/wrapper.dart'; import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; class Main1View extends StatefulWidget { - final Function changeView; - final List products; + final Function? changeView; + final List? products; - const Main1View({Key key, this.products, this.changeView}) : super(key: key); + const Main1View({ this.products, this.changeView}) ; @override _Main1ViewState createState() => _Main1ViewState(); @@ -66,7 +66,7 @@ class _Main1ViewState extends State { title: 'Check', width: 160, height: 48, - onPressed: (() => widget.changeView(changeType: ViewChangeType.Forward)), + onPressed: (() => widget.changeView!(changeType: ViewChangeType.Forward)), ), ) ], @@ -82,7 +82,7 @@ class _Main1ViewState extends State { ), OpenFlutterProductListView( width: widgetWidth, - products: widget.products, + products: widget.products!, onFavoritesTap: ((Product product) => { BlocProvider.of(context) .add(HomeAddToFavoriteEvent(isFavorite: !product.isFavorite, product: product)) @@ -92,7 +92,7 @@ class _Main1ViewState extends State { title: 'Next Home Page', width: 160, height: 48, - onPressed: (() => widget.changeView(changeType: ViewChangeType.Forward)), + onPressed: (() => widget.changeView!(changeType: ViewChangeType.Forward)), ) ], ), diff --git a/lib/presentation/features/home/views/main2_view.dart b/lib/presentation/features/home/views/main2_view.dart index d8d1b399..b8232c73 100644 --- a/lib/presentation/features/home/views/main2_view.dart +++ b/lib/presentation/features/home/views/main2_view.dart @@ -14,11 +14,11 @@ import 'package:openflutterecommerce/presentation/features/wrapper.dart'; import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; class Main2View extends StatefulWidget { - final Function changeView; - final List salesProducts; - final List newProducts; + final Function? changeView; + final List? salesProducts; + final List? newProducts; - const Main2View({Key key, this.changeView, this.salesProducts, this.newProducts}) : super(key: key); + const Main2View({ this.changeView, this.salesProducts, this.newProducts}) ; @override _Main2ViewState createState() => _Main2ViewState(); @@ -48,7 +48,7 @@ class _Main2ViewState extends State { Container( padding: EdgeInsets.only(left: AppSizes.sidePadding), width: width, - child: Text('Street clothes', style: _theme.textTheme.headline5.copyWith(fontSize: 34))) + child: Text('Street clothes', style: _theme.textTheme.headline5?.copyWith(fontSize: 34))) ], )), OpenFlutterBlockHeader( @@ -61,7 +61,7 @@ class _Main2ViewState extends State { ), OpenFlutterProductListView( width: widgetWidth, - products: widget.salesProducts, + products: widget.salesProducts!, onFavoritesTap: ((Product product) => { BlocProvider.of(context) .add(HomeAddToFavoriteEvent(isFavorite: !product.isFavorite, product: product)) @@ -77,7 +77,7 @@ class _Main2ViewState extends State { ), OpenFlutterProductListView( width: widgetWidth, - products: widget.newProducts, + products: widget.newProducts!, onFavoritesTap: ((Product product) => { BlocProvider.of(context) .add(HomeAddToFavoriteEvent(isFavorite: !product.isFavorite, product: product)) @@ -87,7 +87,7 @@ class _Main2ViewState extends State { title: 'Next Home Page', width: 160, height: 48, - onPressed: (() => widget.changeView(changeType: ViewChangeType.Forward)), + onPressed: (() => widget.changeView!(changeType: ViewChangeType.Forward)), ) ])); } diff --git a/lib/presentation/features/home/views/main3_view.dart b/lib/presentation/features/home/views/main3_view.dart index 29a6a185..90d53988 100644 --- a/lib/presentation/features/home/views/main3_view.dart +++ b/lib/presentation/features/home/views/main3_view.dart @@ -8,9 +8,9 @@ import 'package:openflutterecommerce/presentation/features/wrapper.dart'; import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; class Main3View extends StatefulWidget { - final Function changeView; + final Function? changeView; - const Main3View({Key key, this.changeView}) : super(key: key); + const Main3View({ this.changeView}) ; @override _Main3ViewState createState() => _Main3ViewState(); @@ -40,7 +40,7 @@ class _Main3ViewState extends State { alignment: Alignment.centerRight, padding: EdgeInsets.only(left: AppSizes.sidePadding, bottom: AppSizes.sidePadding), width: width, - child: Text('New collection', style: _theme.textTheme.headline5.copyWith(fontSize: 34))) + child: Text('New collection', style: _theme.textTheme.headline5?.copyWith(fontSize: 34))) ], )), Row( @@ -53,7 +53,7 @@ class _Main3ViewState extends State { height: width / 2 - 2, padding: EdgeInsets.all(AppSizes.sidePadding), child: Text('Summer sale', - style: _theme.textTheme.headline5.copyWith(fontSize: 34, color: _theme.accentColor))), + style: _theme.textTheme.headline5?.copyWith(fontSize: 34, color: _theme.accentColor))), Container( height: width / 2, width: width / 2, @@ -65,7 +65,7 @@ class _Main3ViewState extends State { image: AssetImage('assets/splash/bottombanner.png'), ), ), - child: Text('Black', style: _theme.textTheme.headline5.copyWith(fontSize: 34))), + child: Text('Black', style: _theme.textTheme.headline5?.copyWith(fontSize: 34))), ], ), Container( @@ -79,7 +79,7 @@ class _Main3ViewState extends State { image: AssetImage('assets/splash/sidebanner.png'), ), ), - child: Text('Men’s hoodies', style: _theme.textTheme.headline5.copyWith(fontSize: 34))), + child: Text('Men’s hoodies', style: _theme.textTheme.headline5?.copyWith(fontSize: 34))), ], ), Padding(padding: EdgeInsets.only(top: AppSizes.sidePadding)), @@ -87,7 +87,7 @@ class _Main3ViewState extends State { title: 'Next Home Page', width: 160, height: 48, - onPressed: (() => widget.changeView(changeType: ViewChangeType.Start))) + onPressed: (() => widget.changeView!(changeType: ViewChangeType.Start))) ])); } } diff --git a/lib/presentation/features/product_details/product_bloc.dart b/lib/presentation/features/product_details/product_bloc.dart index ffb027ac..f6200772 100644 --- a/lib/presentation/features/product_details/product_bloc.dart +++ b/lib/presentation/features/product_details/product_bloc.dart @@ -18,7 +18,7 @@ class ProductBloc extends Bloc { final RemoveFromFavoritesUseCase removeFromFavoritesUseCase; final GetProductByIdUseCase getProductByIdUseCaseImpl; final AddProductToCartUseCase addProductToCartUseCase; - final int productId; + final int? productId; ProductBloc( {this.productId}): diff --git a/lib/presentation/features/product_details/product_event.dart b/lib/presentation/features/product_details/product_event.dart index eeadc07a..423c3ce5 100644 --- a/lib/presentation/features/product_details/product_event.dart +++ b/lib/presentation/features/product_details/product_event.dart @@ -16,8 +16,8 @@ class ProductScreenLoadedEvent extends ProductEvent { final int categoryId; ProductScreenLoadedEvent({ - @required this.productId, - @required this.categoryId + required this.productId, + required this.categoryId });} @immutable diff --git a/lib/presentation/features/product_details/product_screen.dart b/lib/presentation/features/product_details/product_screen.dart index 87fc0092..91a4507b 100644 --- a/lib/presentation/features/product_details/product_screen.dart +++ b/lib/presentation/features/product_details/product_screen.dart @@ -12,12 +12,7 @@ import 'product_state.dart'; import 'views/details.dart'; class ProductDetailsScreen extends StatefulWidget { - final ProductDetailsParameters parameters; - - const ProductDetailsScreen( - this.parameters, { - Key key, - }) : super(key: key); + const ProductDetailsScreen(); @override _ProductDetailsScreenState createState() => _ProductDetailsScreenState(); @@ -26,7 +21,7 @@ class ProductDetailsScreen extends StatefulWidget { class ProductDetailsParameters { final int productId; final int categoryId; - final HashMap selectedAttributes; + final Map? selectedAttributes; const ProductDetailsParameters(this.productId, this.categoryId, {this.selectedAttributes}); @@ -35,17 +30,18 @@ class ProductDetailsParameters { class _ProductDetailsScreenState extends State { @override Widget build(BuildContext context) { - print('productId: ${widget.parameters.productId}'); + final args = ModalRoute.of(context)!.settings.arguments as ProductDetailsParameters; + print('productId: ${args.productId}'); return SafeArea( child: OpenFlutterScaffold( background: null, - title: null, + title: '', body: BlocProvider( create: (context) { - return ProductBloc(productId: widget.parameters.productId) + return ProductBloc(productId: args.productId) ..add(ProductScreenLoadedEvent( - productId: widget.parameters.productId, - categoryId: widget.parameters.categoryId)); + productId: args.productId, + categoryId: args.categoryId)); }, child: ProductWrapper(), ), diff --git a/lib/presentation/features/product_details/product_state.dart b/lib/presentation/features/product_details/product_state.dart index 584a2834..108ec539 100644 --- a/lib/presentation/features/product_details/product_state.dart +++ b/lib/presentation/features/product_details/product_state.dart @@ -21,9 +21,9 @@ class ProductLoadedState extends ProductState { final SelectedProductAttributes productAttributes; ProductLoadedState( - {@required this.product, - @required this.similarProducts, - @required this.productAttributes}); + {required this.product, + required this.similarProducts, + required this.productAttributes}); ProductLoadedState copyWith( Product product, @@ -33,7 +33,7 @@ class ProductLoadedState extends ProductState { return ProductLoadedState( product: product ?? this.product, similarProducts: similarProducts ?? this.similarProducts, - productAttributes: productAttributes ?? this.productAttributes, + productAttributes: this.productAttributes, ); } @@ -46,7 +46,7 @@ class SelectedProductAttributes extends Equatable{ final HashMap selectedAttributes; SelectedProductAttributes({ - @required this.selectedAttributes + required this.selectedAttributes }); @override List get props => [selectedAttributes, selectedAttributes.values]; diff --git a/lib/presentation/features/product_details/views/attribute_bottom_sheet.dart b/lib/presentation/features/product_details/views/attribute_bottom_sheet.dart index 07b4f960..9f191766 100644 --- a/lib/presentation/features/product_details/views/attribute_bottom_sheet.dart +++ b/lib/presentation/features/product_details/views/attribute_bottom_sheet.dart @@ -8,19 +8,20 @@ class AttributeBottomSheet extends StatelessWidget { final Function(String, ProductAttribute) onValueSelect; const AttributeBottomSheet( - {Key key, this.productAttribute, this.selectedValue, this.onValueSelect}) - : super(key: key); + {required this.productAttribute, + required this.selectedValue, + required this.onValueSelect}); @override Widget build(BuildContext context) { return FractionallySizedBox( - heightFactor: 0.12 + productAttribute.options.length/3*0.1, + heightFactor: 0.12 + productAttribute.options.length / 3 * 0.1, child: Container( padding: AppSizes.bottomSheetPadding, decoration: BoxDecoration( color: AppColors.background, borderRadius: BorderRadius.only( - topLeft: Radius.circular(34), topRight: Radius.circular(34)), + topLeft: Radius.circular(34), topRight: Radius.circular(34)), boxShadow: []), child: SingleChildScrollView( child: Column( @@ -40,9 +41,9 @@ class AttributeBottomSheet extends StatelessWidget { Text( 'Select ${productAttribute.name}', style: TextStyle( - color: AppColors.black, - fontSize: 20, - fontWeight: FontWeight.bold), + color: AppColors.black, + fontSize: 20, + fontWeight: FontWeight.bold), ), SizedBox( height: 18, @@ -53,29 +54,27 @@ class AttributeBottomSheet extends StatelessWidget { crossAxisCount: 3, childAspectRatio: 100 / 60, children: productAttribute.options - .map((String value) => - InkWell( - onTap: () => { - onValueSelect(value, productAttribute) - }, - child: Container( - margin: EdgeInsets.all(10.0), - decoration: BoxDecoration( - border: Border.all( - color: selectedValue == value - ? AppColors.red - : AppColors.darkGray), - borderRadius: BorderRadius.all( - Radius.circular(15.0))), - child: Center( - child: Text( - value, - style: TextStyle(fontSize: 15.0), + .map((String value) => InkWell( + onTap: () => + {onValueSelect(value, productAttribute)}, + child: Container( + margin: EdgeInsets.all(10.0), + decoration: BoxDecoration( + border: Border.all( + color: selectedValue == value + ? AppColors.red + : AppColors.darkGray), + borderRadius: + BorderRadius.all(Radius.circular(15.0))), + child: Center( + child: Text( + value, + style: TextStyle(fontSize: 15.0), + ), + ), ), - ), - ), - ) - ).toList(), + )) + .toList(), ), ), SizedBox( diff --git a/lib/presentation/features/product_details/views/details.dart b/lib/presentation/features/product_details/views/details.dart index 9e1b524b..4bb26b0f 100644 --- a/lib/presentation/features/product_details/views/details.dart +++ b/lib/presentation/features/product_details/views/details.dart @@ -15,29 +15,28 @@ import '../product.dart'; class ProductDetailsView extends StatefulWidget { final Product product; final Function changeView; - final ProductCategory category; + final ProductCategory? category; final bool hasReviews; final List similarProducts; const ProductDetailsView( - {Key key, - @required this.product, - @required this.changeView, - @required this.similarProducts, + { + required this.product, + required this.changeView, + required this.similarProducts, this.category, this.hasReviews = false}) - : assert(product != null), - super(key: key); + : assert(product != null); @override _ProductDetailsViewState createState() => _ProductDetailsViewState(); } class _ProductDetailsViewState extends State { - Orientation orientation; - bool favorite; - ProductBloc bloc; + Orientation? orientation; + bool? favorite; + ProductBloc? bloc; @override void initState() { @@ -57,13 +56,12 @@ class _ProductDetailsViewState extends State { bloc: bloc, listener: (context, state) { if (state is ProductErrorState) { - return Container( + Container( padding: EdgeInsets.all(AppSizes.sidePadding), child: Text('An error occured', style: _theme.textTheme.headline4 - .copyWith(color: _theme.errorColor))); + ?.copyWith(color: _theme.errorColor))); } - return Container(); }, child: BlocBuilder( bloc: bloc, @@ -104,13 +102,13 @@ class _ProductDetailsViewState extends State { value, state.productAttributes .selectedAttributes[ - value])) + value]!)) .toList() - : List()) + + : []) + [ OpenFlutterFavouriteButton( favourite: favorite, - setFavourite: () => {setFavourite(bloc)}, + setFavourite: () => {setFavourite(bloc!)}, ) ]), ), @@ -196,20 +194,20 @@ class _ProductDetailsViewState extends State { } void setFavourite(ProductBloc bloc) { - if (!favorite) { + if (!favorite!) { bloc.add( ProductAddToFavoritesEvent()); //TODO ask for real parameters if required } else { bloc.add(ProductRemoveFromFavoritesEvent()); } setState(() { - favorite = !favorite; + favorite = !favorite!; }); } void _showSelectAttributeBottomSheet( BuildContext context, ProductAttribute attribute, - {Function onSelect, String selectedValue}) { + {Function? onSelect, String? selectedValue}) { showModalBottomSheet( context: context, isScrollControlled: true, @@ -219,19 +217,19 @@ class _ProductDetailsViewState extends State { ), builder: (BuildContext context) => AttributeBottomSheet( productAttribute: attribute, - selectedValue: selectedValue, + selectedValue: selectedValue!, onValueSelect: ((String value, ProductAttribute productAttribute) => { - bloc..add(ProductSetAttributeEvent(value, productAttribute)), + bloc!..add(ProductSetAttributeEvent(value, productAttribute)), Navigator.pop(context), - onSelect() + onSelect!() }))); } //modelBottomSheet for selecting size Widget selectionOutlineButton(var deviceWidth, ProductAttribute attribute, String alreadySelectedValue) { //select size and select color widget - return OutlineButton( + return MaterialButton( onPressed: () => _showSelectAttributeBottomSheet(context, attribute, selectedValue: alreadySelectedValue), child: Container( @@ -251,8 +249,8 @@ class _ProductDetailsViewState extends State { ), width: deviceWidth * 0.29, ), - borderSide: BorderSide(color: AppColors.darkGray), - highlightedBorderColor: AppColors.red, + /*borderSide: BorderSide(color: AppColors.darkGray), + highlightedBorderColor: AppColors.red,*/ focusColor: AppColors.white, highlightColor: Colors.white, hoverColor: AppColors.red, @@ -284,7 +282,7 @@ class _ProductDetailsViewState extends State { widget.category == null ? Container() : Text( - widget.category.name, + widget.category!.name, style: theme.textTheme.bodyText1, ), SizedBox( @@ -327,7 +325,7 @@ class _ProductDetailsViewState extends State { final attribute = state.product.selectableAttributes[i]; if (!state.productAttributes.selectedAttributes .containsKey(attribute)) { - await _showSelectAttributeBottomSheet(context, attribute, + _showSelectAttributeBottomSheet(context, attribute, onSelect: i == 0 ? (() => { BlocProvider.of(context) diff --git a/lib/presentation/features/product_reviews/product_review_and_rating_screen.dart b/lib/presentation/features/product_reviews/product_review_and_rating_screen.dart index fff6ed0c..90017bb4 100644 --- a/lib/presentation/features/product_reviews/product_review_and_rating_screen.dart +++ b/lib/presentation/features/product_reviews/product_review_and_rating_screen.dart @@ -13,9 +13,8 @@ class ProductReviewRatingScreen extends StatefulWidget { final Product product; const ProductReviewRatingScreen({ - Key key, - this.product, - }) : super(key: key); + required this.product, + }); @override State createState() { @@ -60,7 +59,8 @@ class ProductReviewRatingScreenState extends State { ), BlocProvider( create: (context) { - return ProductReviewBloc(ProductReviewRepository())..add(ProductReviewStartEvent(widget.product.id, false)); + return ProductReviewBloc(ProductReviewRepository()) + ..add(ProductReviewStartEvent(widget.product.id, false)); }, child: ProductReviewWrapper( product: widget.product, @@ -117,9 +117,8 @@ class ProductReviewWrapper extends StatefulWidget { final summaryAndFilterIndex = 2; const ProductReviewWrapper({ - Key key, - this.product, - }) : super(key: key); + required this.product, + }); @override State createState() { @@ -128,7 +127,7 @@ class ProductReviewWrapper extends StatefulWidget { } class ProductReviewWrapperState extends State { - List comments; + late List comments; int reviewCount = 0; bool withPhotos = false; @@ -149,8 +148,9 @@ class ProductReviewWrapperState extends State { child: _buildItem(context, index), ); }, - childCount: - comments != null ? comments.length + widget.summaryAndFilterIndex : widget.summaryAndFilterIndex + 1, + childCount: comments != null + ? comments.length + widget.summaryAndFilterIndex + : widget.summaryAndFilterIndex + 1, ), ); }); @@ -158,7 +158,7 @@ class ProductReviewWrapperState extends State { void _readState(ProductReviewState state) { if (state is ProductReviewLoadingState) { - comments = null; + comments = []; reviewCount = 0; } @@ -214,7 +214,8 @@ class ProductReviewWrapperState extends State { checked: withPhotos, title: 'with photos', onTap: (value) { - BlocProvider.of(context).add(ProductReviewStartEvent(widget.product.id, value)); + BlocProvider.of(context) + .add(ProductReviewStartEvent(widget.product.id, value)); }, ), ), diff --git a/lib/presentation/features/products/products_bloc.dart b/lib/presentation/features/products/products_bloc.dart index 6665001f..f1881c00 100644 --- a/lib/presentation/features/products/products_bloc.dart +++ b/lib/presentation/features/products/products_bloc.dart @@ -28,7 +28,7 @@ class ProductsBloc extends Bloc { final ProductCategory category; ProductsBloc({ - @required this.category, + required this.category, }) : findProductsByFilterUseCase = sl(), getFavoriteProductsUseCase = sl(), removeFromFavoritesUseCase = sl(), @@ -60,11 +60,11 @@ class ProductsBloc extends Bloc { final List filteredData = productResults.products; yield state.copyWith( sortBy: event.sortBy, - data: state.data.copyWith(filteredData), + data: state.data!.copyWith(filteredData), ); } else if (event is ProductChangeHashTagEvent) { yield state.getLoading(); - state.filterRules.selectedHashTags[event.hashTag] = event.isSelected; + state.filterRules!.selectedHashTags[event.hashTag] = event.isSelected; ProductsByFilterResult productResults = await findProductsByFilterUseCase.execute( ProductsByFilterParams( categoryId: category.id, @@ -73,8 +73,8 @@ class ProductsBloc extends Bloc { )); final List filteredData = productResults.products; yield state.copyWith( - data: state.data.copyWith(filteredData), - sortBy: state.sortBy, + data: state.data!.copyWith(filteredData), + sortBy: state.sortBy!, ); } else if (event is ProductChangeFilterRulesEvent) { yield state.getLoading(); @@ -87,26 +87,26 @@ class ProductsBloc extends Bloc { final List filteredData = productResults.products; yield state.copyWith( filterRules: event.filterRules, - data: state.data.copyWith(filteredData)); + data: state.data!.copyWith(filteredData)); } else if (event is ProductMakeFavoriteEvent) { if (event.isFavorite) { await addToFavoritesUseCase.execute(FavoriteProduct( event.product, - event.favoriteAttributes + event.favoriteAttributes! ) ); } else { await removeFromFavoritesUseCase.execute( RemoveFromFavoritesParams(FavoriteProduct( event.product, - event.favoriteAttributes + event.favoriteAttributes! ) ) ); } - final List data = state.data.products; + final List data = state.data!.products; yield state.copyWith( - data: state.data.copyWith(data.map((item) { + data: state.data!.copyWith(data.map((item) { if (event.product.id == item.id) { return item.favorite(event.isFavorite); } else { diff --git a/lib/presentation/features/products/products_event.dart b/lib/presentation/features/products/products_event.dart index c226ae2d..7cce814d 100644 --- a/lib/presentation/features/products/products_event.dart +++ b/lib/presentation/features/products/products_event.dart @@ -72,10 +72,10 @@ class ProductSearchEvent extends ProductsListEvent { class ProductMakeFavoriteEvent extends ProductsListEvent { final bool isFavorite; final Product product; - final HashMap favoriteAttributes; + final HashMap? favoriteAttributes; ProductMakeFavoriteEvent(this.isFavorite, this.product, {this.favoriteAttributes}); @override - List get props => [isFavorite, product, favoriteAttributes]; + List get props => [isFavorite, product, favoriteAttributes!]; } diff --git a/lib/presentation/features/products/products_screen.dart b/lib/presentation/features/products/products_screen.dart index fd0e46ce..424d7d36 100644 --- a/lib/presentation/features/products/products_screen.dart +++ b/lib/presentation/features/products/products_screen.dart @@ -12,9 +12,9 @@ import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; import 'products.dart'; class ProductsScreen extends StatefulWidget { - final ProductListScreenParameters parameters; + final ProductListScreenParameters? parameters; - const ProductsScreen({Key key, this.parameters}) : super(key: key); + const ProductsScreen({ this.parameters}) ; @override _ProductsScreenState createState() => _ProductsScreenState(); @@ -29,20 +29,21 @@ class ProductListScreenParameters { class _ProductsScreenState extends State { @override Widget build(BuildContext context) { + final args = ModalRoute.of(context)!.settings.arguments as ProductListScreenParameters; return SafeArea( child: OpenFlutterScaffold( background: null, - title: null, + title: '', body: BlocProvider( create: (context) { return ProductsBloc( - category: widget.parameters.category) + category: widget.parameters!.category) ..add(ScreenLoadedEvent()); }, child: BlocConsumer( listener: (context, state) { if (state.hasError) { - ErrorDialog.showErrorDialog(context, state.error); + ErrorDialog.showErrorDialog(context, state.error!); } }, builder: (context, state) { @@ -50,8 +51,8 @@ class _ProductsScreenState extends State { slivers: [ SizeChangingAppBar( title: state.data?.category?.name??'', - filterRules: state.filterRules, - sortRules: state.sortBy, + filterRules: state.filterRules!, + sortRules: state.sortBy!, isListView: state is ProductsListViewState, onFilterRulesChanged: (filter) { BlocProvider.of(context) diff --git a/lib/presentation/features/products/products_state.dart b/lib/presentation/features/products/products_state.dart index b3d97dc9..364b2cac 100644 --- a/lib/presentation/features/products/products_state.dart +++ b/lib/presentation/features/products/products_state.dart @@ -10,10 +10,10 @@ import 'package:openflutterecommerce/data/model/sort_rules.dart'; import 'bloc_list_data.dart'; abstract class ProductsState extends Equatable { - final ProductListData data; - final SortRules sortBy; - final FilterRules filterRules; - final String error; + final ProductListData? data; + final SortRules? sortBy; + final FilterRules? filterRules; + final String? error; ProductsState({ this.data, @@ -30,7 +30,7 @@ abstract class ProductsState extends Equatable { }); ProductsState getLoading() { - return copyWith(data: null); + return copyWith(data: null!); } bool get isProductsLoading => data == null; @@ -38,7 +38,7 @@ abstract class ProductsState extends Equatable { bool get hasError => error != null; @override - List get props => [data, filterRules, sortBy]; + List get props => [data!, filterRules!, sortBy!]; @override bool get stringify => true; @@ -47,10 +47,10 @@ abstract class ProductsState extends Equatable { @immutable class ProductsListViewState extends ProductsState { ProductsListViewState({ - ProductListData data, - SortRules sortBy, - FilterRules filterRules, - String error, + ProductListData? data, + SortRules? sortBy, + FilterRules? filterRules, + String? error, }) : super( data: data, sortBy: sortBy, filterRules: filterRules, error: error); @@ -61,10 +61,10 @@ class ProductsListViewState extends ProductsState { @override ProductsListViewState copyWith({ - ProductListData data, - SortRules sortBy, - FilterRules filterRules, - String error, + ProductListData? data, + SortRules? sortBy, + FilterRules? filterRules, + String? error, }) { return ProductsListViewState( data: data ?? this.data, @@ -78,25 +78,25 @@ class ProductsListViewState extends ProductsState { @immutable class ProductsTileViewState extends ProductsState { ProductsTileViewState( - {ProductListData data, - SortRules sortBy, - FilterRules filterRules, - String error}) + {ProductListData? data, + SortRules? sortBy, + FilterRules? filterRules, + String? error}) : super( data: data, sortBy: sortBy, filterRules: filterRules, error: error); @override ProductsTileViewState copyWith({ - ProductListData data, - SortRules sortBy, - FilterRules filterRules, - String error, + ProductListData? data, + SortRules? sortBy, + FilterRules? filterRules, + String? error, }) { return ProductsTileViewState( - data: data ?? this.data, - filterRules: filterRules ?? this.filterRules, - sortBy: sortBy ?? this.sortBy, - error: error, + data: this.data!, + filterRules: this.filterRules!, + sortBy: this.sortBy!, + error: error!, ); } diff --git a/lib/presentation/features/products/views/list_view.dart b/lib/presentation/features/products/views/list_view.dart index 7765934f..cb2ed6f1 100644 --- a/lib/presentation/features/products/views/list_view.dart +++ b/lib/presentation/features/products/views/list_view.dart @@ -28,20 +28,20 @@ class ProductsListView extends StatelessWidget { return Padding( padding: EdgeInsets.symmetric(horizontal: AppSizes.sidePadding), - child: state.data.products[index].getListView( + child: state.data!.products[index].getListView( context: context, showProductInfo: () { Navigator.of(context).pushNamed( OpenFlutterEcommerceRoutes.product, arguments: ProductDetailsParameters( - state.data.products[index].id, - state.data.category?.id)); + state.data!.products[index].id, + state.data!.category!.id)); }, onFavoritesClick: () { BlocProvider.of(context).add( ProductMakeFavoriteEvent( - !state.data.products[index].isFavorite, - state.data.products[index])); + !state.data!.products[index].isFavorite, + state.data!.products[index])); }, )) ; } diff --git a/lib/presentation/features/products/views/tile_view.dart b/lib/presentation/features/products/views/tile_view.dart index b06e282e..e1f160a3 100644 --- a/lib/presentation/features/products/views/tile_view.dart +++ b/lib/presentation/features/products/views/tile_view.dart @@ -26,24 +26,24 @@ class ProductsTileView extends StatelessWidget { (BuildContext context, int index) { return Padding( padding: EdgeInsets.symmetric(horizontal: AppSizes.sidePadding), - child: state.data.products[index].getTileView( + child: state.data?.products[index].getTileView( context: context, onFavoritesClick: () { BlocProvider.of(context).add( ProductMakeFavoriteEvent( - !state.data.products[index].isFavorite, - state.data.products[index])); + !state.data!.products[index].isFavorite, + state.data!.products[index])); }, showProductInfo: () { Navigator.of(context).pushNamed( OpenFlutterEcommerceRoutes.product, arguments: ProductDetailsParameters( - state.data.products[index].id, - state.data.category.id)); + state.data!.products[index].id, + state.data!.category.id)); }, )); }, - childCount: state.data.products.length, + childCount: state.data!.products.length, ), ); }); diff --git a/lib/presentation/features/products/views/visual_filter.dart b/lib/presentation/features/products/views/visual_filter.dart index 0e08ad3e..597481ef 100644 --- a/lib/presentation/features/products/views/visual_filter.dart +++ b/lib/presentation/features/products/views/visual_filter.dart @@ -12,9 +12,7 @@ class VisualFilter extends StatelessWidget { const VisualFilter( this.hashTags, this.selecteHashTags, - this.onFilterChanged, { - Key key, - }) : super(key: key); + this.onFilterChanged); @override Widget build(BuildContext context) { diff --git a/lib/presentation/features/profile/password_bloc.dart b/lib/presentation/features/profile/password_bloc.dart index 7210db00..b707bae9 100644 --- a/lib/presentation/features/profile/password_bloc.dart +++ b/lib/presentation/features/profile/password_bloc.dart @@ -7,7 +7,7 @@ import 'package:openflutterecommerce/presentation/features/profile/password_stat class PasswordBloc extends Bloc { final PasswordRepository passwordRepository; - PasswordBloc({@required this.passwordRepository}) + PasswordBloc({required this.passwordRepository}) : assert(passwordRepository != null), super(PasswordInitialState()); diff --git a/lib/presentation/features/profile/password_event.dart b/lib/presentation/features/profile/password_event.dart index a49c4782..62013599 100644 --- a/lib/presentation/features/profile/password_event.dart +++ b/lib/presentation/features/profile/password_event.dart @@ -14,9 +14,9 @@ class ChangePasswordEvent extends PasswordEvent { final String repeatNewPassword; ChangePasswordEvent( - {@required this.currentPassword, - @required this.newPassword, - @required this.repeatNewPassword}); + {required this.currentPassword, + required this.newPassword, + required this.repeatNewPassword}); @override List get props => [currentPassword, newPassword, repeatNewPassword]; diff --git a/lib/presentation/features/profile/password_state.dart b/lib/presentation/features/profile/password_state.dart index f4e8cfe4..aebca85b 100644 --- a/lib/presentation/features/profile/password_state.dart +++ b/lib/presentation/features/profile/password_state.dart @@ -33,10 +33,10 @@ class PasswordChangedState extends PasswordState {} @immutable class ChangePasswordErrorState extends PasswordState { - final String errorMessage; + final String? errorMessage; ChangePasswordErrorState({this.errorMessage}) : super(); @override - List get props => [errorMessage]; + List get props => [errorMessage!]; } diff --git a/lib/presentation/features/profile/profile_screen.dart b/lib/presentation/features/profile/profile_screen.dart index 078f92a1..6772bb8d 100644 --- a/lib/presentation/features/profile/profile_screen.dart +++ b/lib/presentation/features/profile/profile_screen.dart @@ -13,7 +13,7 @@ import 'views/settings.dart'; import 'views/shipping_addresses.dart'; class ProfileScreen extends StatefulWidget { - ProfileScreen({Key key}) : super(key: key); + ProfileScreen({Key? key}) ; @override _ProfileScreenState createState() => _ProfileScreenState(); diff --git a/lib/presentation/features/profile/profile_state.dart b/lib/presentation/features/profile/profile_state.dart index 9dcc8182..28678729 100644 --- a/lib/presentation/features/profile/profile_state.dart +++ b/lib/presentation/features/profile/profile_state.dart @@ -16,14 +16,14 @@ class ProfileMyOrdersProcessingState extends ProfileState {} @immutable class ProfileMyOrdersState extends ProfileState { - final List orderData; + final List? orderData; ProfileMyOrdersState({this.orderData}); } @immutable class ProfileMyOrderDetailsState extends ProfileState { - final UserOrder orderData; + final UserOrder? orderData; ProfileMyOrderDetailsState({this.orderData}); } diff --git a/lib/presentation/features/profile/settings_bloc.dart b/lib/presentation/features/profile/settings_bloc.dart index 37f3d7e8..976a0059 100644 --- a/lib/presentation/features/profile/settings_bloc.dart +++ b/lib/presentation/features/profile/settings_bloc.dart @@ -8,7 +8,7 @@ import 'package:openflutterecommerce/presentation/features/profile/settings_stat class SettingsBloc extends Bloc { final SettingsRepository settingsRepository; - SettingsBloc({@required this.settingsRepository}) + SettingsBloc({required this.settingsRepository}) : assert(settingsRepository != null), super(SettingsInitialState( settings: UserSettingsEntity( @@ -23,51 +23,51 @@ class SettingsBloc extends Bloc { var newSettings = state.settings; if (event is UpdateFullNameEvent) { - newSettings.fullName = event.fullName; + newSettings?.fullName = event.fullName!; try { - await settingsRepository.updateFullName(newSettings.fullName); + await settingsRepository.updateFullName(newSettings!.fullName); yield FullNameUpdatedState(settings: newSettings); } catch (error) { yield ChangeSettingsErrorState( - settings: newSettings, errorMessage: error); + settings: newSettings, errorMessage: error.toString()); } } else if (event is UpdateDateOfBirthEvent) { - newSettings.dateOfBirth = event.dateOfBirth; + newSettings!.dateOfBirth = event.dateOfBirth!; try { - await settingsRepository.updateDateOfBirth(newSettings.dateOfBirth); + await settingsRepository.updateDateOfBirth(newSettings!.dateOfBirth); yield DateOfBirthUpdatedState(settings: newSettings); } catch (error) { yield ChangeSettingsErrorState( - settings: newSettings, errorMessage: error); + settings: newSettings, errorMessage: error.toString()); } } else if (event is UpdateNotifySalesEvent) { - newSettings.notifySales = event.notifySales; + newSettings!.notifySales = event.notifySales!; try { - await settingsRepository.updateNotifySales(newSettings.notifySales); + await settingsRepository.updateNotifySales(newSettings!.notifySales); yield NotifySalesUpdatedState(settings: newSettings); } catch (error) { yield ChangeSettingsErrorState( - settings: newSettings, errorMessage: error); + settings: newSettings, errorMessage: error.toString()); } } else if (event is UpdateNotifyArrivalsEvent) { - newSettings.notifyArrivals = event.notifyArrivals; + newSettings!.notifyArrivals = event.notifyArrivals!; try { await settingsRepository .updateNotifyArrivals(newSettings.notifyArrivals); yield NotifyArrivalsUpdatedSate(settings: newSettings); } catch (error) { yield ChangeSettingsErrorState( - settings: newSettings, errorMessage: error); + settings: newSettings, errorMessage: error.toString()); } } else if (event is UpdateNotifyDeliveryEvent) { - newSettings.notifyDelivery = event.notifyDelivery; + newSettings!.notifyDelivery = event.notifyDelivery!; try { await settingsRepository .updateNotifyDelivery(newSettings.notifyDelivery); yield NotifyDeliveryUpdatedState(settings: newSettings); } catch (error) { yield ChangeSettingsErrorState( - settings: newSettings, errorMessage: error); + settings: newSettings, errorMessage: error.toString()); } } } diff --git a/lib/presentation/features/profile/settings_event.dart b/lib/presentation/features/profile/settings_event.dart index 791e2f9a..859a3fff 100644 --- a/lib/presentation/features/profile/settings_event.dart +++ b/lib/presentation/features/profile/settings_event.dart @@ -9,12 +9,12 @@ abstract class SettingsEvent extends Equatable { @immutable class UpdateFullNameEvent extends SettingsEvent { - final String fullName; + final String? fullName; UpdateFullNameEvent({this.fullName}); @override - List get props => [fullName]; + List get props => [fullName!]; @override String toString() => 'Update FullName Event'; @@ -22,12 +22,12 @@ class UpdateFullNameEvent extends SettingsEvent { @immutable class UpdateDateOfBirthEvent extends SettingsEvent { - final String dateOfBirth; + final String? dateOfBirth; UpdateDateOfBirthEvent({this.dateOfBirth}); @override - List get props => [dateOfBirth]; + List get props => [dateOfBirth!]; @override String toString() => 'Update DateOfBirth Event'; @@ -35,7 +35,7 @@ class UpdateDateOfBirthEvent extends SettingsEvent { @immutable class UpdateNotifySalesEvent extends SettingsEvent { - final bool notifySales; + final bool? notifySales; UpdateNotifySalesEvent({this.notifySales}); @@ -43,12 +43,12 @@ class UpdateNotifySalesEvent extends SettingsEvent { String toString() => 'Update NotifySales Event'; @override - List get props => [notifySales]; + List get props => [notifySales!]; } @immutable class UpdateNotifyArrivalsEvent extends SettingsEvent { - final bool notifyArrivals; + final bool? notifyArrivals; UpdateNotifyArrivalsEvent({this.notifyArrivals}); @@ -56,12 +56,12 @@ class UpdateNotifyArrivalsEvent extends SettingsEvent { String toString() => 'Update NotifyArrivals Event'; @override - List get props => [notifyArrivals]; + List get props => [notifyArrivals!]; } @immutable class UpdateNotifyDeliveryEvent extends SettingsEvent { - final bool notifyDelivery; + final bool? notifyDelivery; UpdateNotifyDeliveryEvent({this.notifyDelivery}); @@ -69,5 +69,5 @@ class UpdateNotifyDeliveryEvent extends SettingsEvent { String toString() => 'Update Delivery Event'; @override - List get props => [notifyDelivery]; + List get props => [notifyDelivery!]; } diff --git a/lib/presentation/features/profile/settings_state.dart b/lib/presentation/features/profile/settings_state.dart index 68d0d69a..9548ec48 100644 --- a/lib/presentation/features/profile/settings_state.dart +++ b/lib/presentation/features/profile/settings_state.dart @@ -4,50 +4,50 @@ import 'package:openflutterecommerce/domain/entities/user/settings.dart'; @immutable abstract class SettingsState extends Equatable { - final UserSettingsEntity settings; + final UserSettingsEntity? settings; SettingsState({this.settings}); @override - List get props => [settings]; + List get props => [settings!]; } @immutable class SettingsInitialState extends SettingsState { - SettingsInitialState({UserSettingsEntity settings}) : super(settings: settings); + SettingsInitialState({UserSettingsEntity? settings}) : super(settings: settings); } @immutable class FullNameUpdatedState extends SettingsState { - FullNameUpdatedState({UserSettingsEntity settings}) : super(settings: settings); + FullNameUpdatedState({UserSettingsEntity? settings}) : super(settings: settings); } @immutable class DateOfBirthUpdatedState extends SettingsState { - DateOfBirthUpdatedState({UserSettingsEntity settings}) : super(settings: settings); + DateOfBirthUpdatedState({UserSettingsEntity? settings}) : super(settings: settings); } @immutable class NotifySalesUpdatedState extends SettingsState { - NotifySalesUpdatedState({UserSettingsEntity settings}) : super(settings: settings); + NotifySalesUpdatedState({UserSettingsEntity? settings}) : super(settings: settings); } @immutable class NotifyArrivalsUpdatedSate extends SettingsState { - NotifyArrivalsUpdatedSate({UserSettingsEntity settings}) : super(settings: settings); + NotifyArrivalsUpdatedSate({UserSettingsEntity? settings}) : super(settings: settings); } @immutable class NotifyDeliveryUpdatedState extends SettingsState { - NotifyDeliveryUpdatedState({UserSettingsEntity settings}) : super(settings: settings); + NotifyDeliveryUpdatedState({UserSettingsEntity? settings}) : super(settings: settings); } @immutable class ChangeSettingsErrorState extends SettingsState { - final String errorMessage; + final String? errorMessage; - ChangeSettingsErrorState({UserSettingsEntity settings, this.errorMessage}) + ChangeSettingsErrorState({UserSettingsEntity? settings, this.errorMessage}) : super(settings: settings); @override - List get props => [settings, errorMessage]; + List get props => [settings!, errorMessage!]; } diff --git a/lib/presentation/features/profile/views/order_details.dart b/lib/presentation/features/profile/views/order_details.dart index d3b96b0b..026723b7 100644 --- a/lib/presentation/features/profile/views/order_details.dart +++ b/lib/presentation/features/profile/views/order_details.dart @@ -12,7 +12,7 @@ import '../profile_state.dart'; class MyOrderDetailsView extends StatefulWidget { final Function changeView; - const MyOrderDetailsView({Key key, @required this.changeView}) : super(key: key); + const MyOrderDetailsView({ required this.changeView}) ; @override _MyOrderDetailsViewState createState() => _MyOrderDetailsViewState(); @@ -43,12 +43,12 @@ class _MyOrderDetailsViewState extends State { style: _theme.textTheme.headline4, ), TextSpan( - text: '#' + state.orderData.orderNumber.toString(), - style: _theme.textTheme.headline4.copyWith(fontWeight: FontWeight.w700), + text: '#' + state.orderData!.orderNumber.toString(), + style: _theme.textTheme.headline4?.copyWith(fontWeight: FontWeight.w700), ), ])), - Text(DateFormat('yyyy-MM-dd').format(state.orderData.orderDate), - style: _theme.textTheme.headline3.copyWith(color: AppColors.lightGray)) + Text(DateFormat('yyyy-MM-dd').format(state.orderData!.orderDate), + style: _theme.textTheme.headline3?.copyWith(color: AppColors.lightGray)) ], ), SizedBox( @@ -59,14 +59,14 @@ class _MyOrderDetailsViewState extends State { text: TextSpan(children: [ TextSpan( text: 'Tacking Number: ', - style: _theme.textTheme.headline4.copyWith(color: _theme.primaryColorLight), + style: _theme.textTheme.headline4?.copyWith(color: _theme.primaryColorLight), ), TextSpan( - text: state.orderData.trackingNumber, + text: state.orderData!.trackingNumber, style: _theme.textTheme.headline4, ), ])), - Text('Delivered', style: _theme.textTheme.headline4.copyWith(color: AppColors.green)), + Text('Delivered', style: _theme.textTheme.headline4?.copyWith(color: AppColors.green)), ]), SizedBox( height: AppSizes.sidePadding, @@ -77,7 +77,7 @@ class _MyOrderDetailsViewState extends State { Row( children: [ Text( - state.orderData.totalQuantity.toString(), + state.orderData!.totalQuantity.toString(), style: _theme.textTheme.headline4, ), Padding( @@ -100,20 +100,20 @@ class _MyOrderDetailsViewState extends State { SizedBox( height: AppSizes.sidePadding, ), - buildSummaryLine('Shipping Address:', state.orderData.shippingAddress.toString(), _theme, width), + buildSummaryLine('Shipping Address:', state.orderData!.shippingAddress.toString(), _theme, width), SizedBox( height: AppSizes.sidePadding, ), - buildSummaryLine('Payment Methods:', state.orderData.paymentMethod, _theme, width), + buildSummaryLine('Payment Methods:', state.orderData!.paymentMethod, _theme, width), SizedBox( height: AppSizes.sidePadding, ), - buildSummaryLine('Discount:', state.orderData.promo.toString(), _theme, width), + buildSummaryLine('Discount:', state.orderData!.promo.toString(), _theme, width), SizedBox( height: AppSizes.sidePadding, ), buildSummaryLine( - 'Total Amount:', '\$' + state.orderData.totalPrice.toStringAsFixed(0), _theme, width), + 'Total Amount:', '\$' + state.orderData!.totalPrice.toStringAsFixed(0), _theme, width), SizedBox( height: AppSizes.sidePadding, ), @@ -151,7 +151,7 @@ class _MyOrderDetailsViewState extends State { List _buildCartProductItems(ProfileMyOrderDetailsState state) { return [ - for (CartItem item in state.orderData.products) + for (CartItem item in state.orderData!.products) OpenFlutterCartTile( item: item, onAddToFav: (() => {}), @@ -170,7 +170,7 @@ class _MyOrderDetailsViewState extends State { children: [ Text( label, - style: _theme.textTheme.headline4.copyWith(color: _theme.primaryColorLight), + style: _theme.textTheme.headline4?.copyWith(color: _theme.primaryColorLight), ), Container( width: width / 2, diff --git a/lib/presentation/features/profile/views/orders.dart b/lib/presentation/features/profile/views/orders.dart index 5f216049..e9d49d97 100644 --- a/lib/presentation/features/profile/views/orders.dart +++ b/lib/presentation/features/profile/views/orders.dart @@ -10,9 +10,9 @@ import '../../wrapper.dart'; import '../profile.dart'; class MyOrdersView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const MyOrdersView({Key key, this.changeView}) : super(key: key); + const MyOrdersView({ this.changeView}) ; @override _MyOrdersViewState createState() => _MyOrdersViewState(); @@ -76,7 +76,7 @@ class _MyOrdersViewState extends State { tabs: tabs, unselectedLabelStyle: _theme.textTheme.headline2, labelStyle: _theme.textTheme.headline2 - .copyWith(color: AppColors.white), + ?.copyWith(color: AppColors.white), ), ]), ), @@ -88,9 +88,9 @@ class _MyOrdersViewState extends State { horizontal: AppSizes.sidePadding), child: TabBarView( children: [ - buildOrderList(state.orderData, bloc), - buildOrderList(state.orderData, bloc), - buildOrderList(state.orderData, bloc), + buildOrderList(state.orderData!, bloc), + buildOrderList(state.orderData!, bloc), + buildOrderList(state.orderData!, bloc), ], ), ), @@ -113,7 +113,7 @@ class _MyOrdersViewState extends State { order: orders[index], onClick: ((int orderId) => { bloc..add(ProfileMyOrderDetailsEvent(orderId)), - widget.changeView(changeType: ViewChangeType.Exact, index: 7) + widget.changeView!(changeType: ViewChangeType.Exact, index: 7) }), ); }); diff --git a/lib/presentation/features/profile/views/payment_methods.dart b/lib/presentation/features/profile/views/payment_methods.dart index cafacf82..a09c742e 100644 --- a/lib/presentation/features/profile/views/payment_methods.dart +++ b/lib/presentation/features/profile/views/payment_methods.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; class PaymentMethodsView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const PaymentMethodsView({Key key, this.changeView}) : super(key: key); + const PaymentMethodsView({ this.changeView}) ; @override _PaymentMethodsViewState createState() => _PaymentMethodsViewState(); diff --git a/lib/presentation/features/profile/views/profile.dart b/lib/presentation/features/profile/views/profile.dart index 6af7f7b1..31434411 100644 --- a/lib/presentation/features/profile/views/profile.dart +++ b/lib/presentation/features/profile/views/profile.dart @@ -8,9 +8,9 @@ import 'package:openflutterecommerce/presentation/widgets/independent/menu_line. import '../profile.dart'; class ProfileView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const ProfileView({Key key, this.changeView}) : super(key: key); + const ProfileView({ this.changeView}) ; @override _ProfileViewState createState() => _ProfileViewState(); @@ -70,7 +70,7 @@ class _ProfileViewState extends State { subtitle: 'Already Have 12 orders', onTap: (() => { bloc..add(ProfileMyOrdersEvent()), - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Exact, index: 1) })), Divider(), @@ -79,7 +79,7 @@ class _ProfileViewState extends State { //TODO: make dynamic address count subtitle: '3 addresses', onTap: (() => { - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Exact, index: 2) })), Divider(), @@ -88,7 +88,7 @@ class _ProfileViewState extends State { //TODO: make short card info subtitle: 'visa **34', onTap: (() => { - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Exact, index: 3) })), Divider(), @@ -97,7 +97,7 @@ class _ProfileViewState extends State { //TODO: make dynamic later subtitle: 'You have special promocodes', onTap: (() => { - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Exact, index: 4) })), Divider(), @@ -106,7 +106,7 @@ class _ProfileViewState extends State { //TODO: make dynamic later subtitle: 'review for 4 items', onTap: (() => { - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Exact, index: 5) })), Divider(), @@ -114,7 +114,7 @@ class _ProfileViewState extends State { title: 'Settings', subtitle: 'Notification, Password', onTap: (() => { - widget.changeView( + widget.changeView!( changeType: ViewChangeType.Exact, index: 6) //Navigator.of(context).pushNamed(OpenFlutterEcommerceRoutes.settings) })), diff --git a/lib/presentation/features/profile/views/promos.dart b/lib/presentation/features/profile/views/promos.dart index cb642b26..74634c8a 100644 --- a/lib/presentation/features/profile/views/promos.dart +++ b/lib/presentation/features/profile/views/promos.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; class PromosView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const PromosView({Key key, this.changeView}) : super(key: key); + const PromosView({ this.changeView}) ; @override _PromosViewState createState() => _PromosViewState(); diff --git a/lib/presentation/features/profile/views/reviews.dart b/lib/presentation/features/profile/views/reviews.dart index 88a2bbb1..73e950ca 100644 --- a/lib/presentation/features/profile/views/reviews.dart +++ b/lib/presentation/features/profile/views/reviews.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; class MyReviewsView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const MyReviewsView({Key key, this.changeView}) : super(key: key); + const MyReviewsView({ this.changeView}) ; @override _MyReviewsViewState createState() => _MyReviewsViewState(); diff --git a/lib/presentation/features/profile/views/settings.dart b/lib/presentation/features/profile/views/settings.dart index 850255af..33907239 100644 --- a/lib/presentation/features/profile/views/settings.dart +++ b/lib/presentation/features/profile/views/settings.dart @@ -13,9 +13,9 @@ import 'package:openflutterecommerce/presentation/features/profile/settings_stat import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; class SettingsView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const SettingsView({Key key, this.changeView}) : super(key: key); + const SettingsView({ this.changeView}) ; @override _SettingsViewState createState() => _SettingsViewState(); @@ -24,11 +24,11 @@ class SettingsView extends StatefulWidget { class _SettingsViewState extends State { final GlobalKey scaffoldKey = GlobalKey(); - TextEditingController _currentPasswordController; - TextEditingController _newPasswordController; - TextEditingController _repeatPasswordController; - TextEditingController _fullNameController; - TextEditingController _dateOfBirthController; + late TextEditingController _currentPasswordController; + late TextEditingController _newPasswordController; + late TextEditingController _repeatPasswordController; + late TextEditingController _fullNameController; + late TextEditingController _dateOfBirthController; @override void initState() { @@ -59,8 +59,8 @@ class _SettingsViewState extends State { child: BlocBuilder( bloc: settingsBloc, builder: (context, state) { - _fullNameController.text = state.settings.fullName; - _dateOfBirthController.text = state.settings.dateOfBirth; + _fullNameController.text = state.settings!.fullName; + _dateOfBirthController.text = state.settings!.dateOfBirth; return SingleChildScrollView( child: Container( @@ -140,7 +140,7 @@ class _SettingsViewState extends State { ), CupertinoSwitch( //trackColor: AppColors.lightGray, - value: state.settings.notifySales, + value: state.settings!.notifySales, activeColor: AppColors.success, onChanged: (newValue) => settingsBloc.add(UpdateNotifySalesEvent(notifySales: newValue)), ), @@ -158,7 +158,7 @@ class _SettingsViewState extends State { ), CupertinoSwitch( //trackColor: AppColors.lightGray, - value: state.settings.notifyArrivals, + value: state.settings!.notifyArrivals, activeColor: AppColors.success, onChanged: (newValue) => settingsBloc..add(UpdateNotifyArrivalsEvent(notifyArrivals: newValue)), ), @@ -176,7 +176,7 @@ class _SettingsViewState extends State { ), CupertinoSwitch( //trackColor: AppColors.lightGray, - value: state.settings.notifyDelivery, + value: state.settings!.notifyDelivery, activeColor: AppColors.success, onChanged: (newValue) => settingsBloc..add(UpdateNotifyDeliveryEvent(notifyDelivery: newValue)), ), @@ -216,7 +216,7 @@ class _SettingsViewState extends State { }); } else if (state is ChangePasswordErrorState) { WidgetsBinding.instance.addPostFrameCallback((_) { - _showAlertDialog(context, 'Error', state.errorMessage); + _showAlertDialog(context, 'Error', state.errorMessage!); }); } @@ -326,7 +326,7 @@ class _SettingsViewState extends State { ), ), actions: [ - FlatButton( + TextButton( child: Text('Ok'), onPressed: () { Navigator.of(context).pop(); diff --git a/lib/presentation/features/profile/views/shipping_addresses.dart b/lib/presentation/features/profile/views/shipping_addresses.dart index d5d2a8b3..9c812146 100644 --- a/lib/presentation/features/profile/views/shipping_addresses.dart +++ b/lib/presentation/features/profile/views/shipping_addresses.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:openflutterecommerce/presentation/widgets/widgets.dart'; class MyShippingAddressesView extends StatefulWidget { - final Function changeView; + final Function? changeView; - const MyShippingAddressesView({Key key, this.changeView}) : super(key: key); + const MyShippingAddressesView({ this.changeView}) ; @override _MyShippingAddressesViewState createState() => _MyShippingAddressesViewState(); diff --git a/lib/presentation/features/sign_in/sign_in_bloc.dart b/lib/presentation/features/sign_in/sign_in_bloc.dart index 6f0f5c9b..2bc7026f 100644 --- a/lib/presentation/features/sign_in/sign_in_bloc.dart +++ b/lib/presentation/features/sign_in/sign_in_bloc.dart @@ -10,8 +10,8 @@ class SignInBloc extends Bloc { final AuthenticationBloc authenticationBloc; SignInBloc({ - @required this.userRepository, - @required this.authenticationBloc, + required this.userRepository, + required this.authenticationBloc, }) : assert(userRepository != null), assert(authenticationBloc != null), super(SignInInitialState()); @@ -30,7 +30,7 @@ class SignInBloc extends Bloc { authenticationBloc.add(LoggedIn(token)); yield SignInFinishedState(); } catch (error) { - yield SignInErrorState(error); + yield SignInErrorState(error.toString()); } } @@ -44,7 +44,7 @@ class SignInBloc extends Bloc { yield SignInFinishedState(); } catch (error) { - yield SignInErrorState(error); + yield SignInErrorState(error.toString()); } } @@ -58,7 +58,7 @@ class SignInBloc extends Bloc { yield SignInFinishedState(); } catch (error) { - yield SignInErrorState(error); + yield SignInErrorState(error.toString()); } } } diff --git a/lib/presentation/features/sign_in/sign_in_event.dart b/lib/presentation/features/sign_in/sign_in_event.dart index 924d8d0b..b74c2625 100644 --- a/lib/presentation/features/sign_in/sign_in_event.dart +++ b/lib/presentation/features/sign_in/sign_in_event.dart @@ -9,7 +9,7 @@ class SignInPressed extends SignInEvent { final String email; final String password; - SignInPressed({this.email, this.password}); + SignInPressed({required this.email, required this.password}); @override List get props => [email, password]; diff --git a/lib/presentation/features/sign_in/signin_screen.dart b/lib/presentation/features/sign_in/signin_screen.dart index 0c7b4e29..b88788c4 100644 --- a/lib/presentation/features/sign_in/signin_screen.dart +++ b/lib/presentation/features/sign_in/signin_screen.dart @@ -21,7 +21,7 @@ class _SignInScreenState extends State { final GlobalKey emailKey = GlobalKey(); final GlobalKey passwordKey = GlobalKey(); - double sizeBetween; + late double sizeBetween; @override Widget build(BuildContext context) { @@ -47,7 +47,7 @@ class _SignInScreenState extends State { } // on failure show a snackbar if (state is SignInErrorState) { - Scaffold.of(context).showSnackBar( + ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('${state.error}'), backgroundColor: Colors.red, @@ -141,10 +141,10 @@ class _SignInScreenState extends State { } void _validateAndSend() { - if (emailKey.currentState.validate() != null) { + if (emailKey.currentState?.validate() != null) { return; } - if (passwordKey.currentState.validate() != null) { + if (passwordKey.currentState?.validate() != null) { return; } BlocProvider.of(context).add( diff --git a/lib/presentation/features/sign_up/sign_up_bloc.dart b/lib/presentation/features/sign_up/sign_up_bloc.dart index 7d10119f..7ebee35b 100644 --- a/lib/presentation/features/sign_up/sign_up_bloc.dart +++ b/lib/presentation/features/sign_up/sign_up_bloc.dart @@ -10,8 +10,8 @@ class SignUpBloc extends Bloc { final AuthenticationBloc authenticationBloc; SignUpBloc({ - @required this.userRepository, - @required this.authenticationBloc, + required this.userRepository, + required this.authenticationBloc, }) : assert(userRepository != null), assert(authenticationBloc != null), super(SignUpInitialState()); @@ -32,7 +32,7 @@ class SignUpBloc extends Bloc { authenticationBloc.add(LoggedIn(token)); yield SignUpFinishedState(); } catch (error) { - yield SignUpErrorState(error); + yield SignUpErrorState(error.toString()); } } @@ -46,7 +46,7 @@ class SignUpBloc extends Bloc { yield SignUpFinishedState(); } catch (error) { - yield SignUpErrorState(error); + yield SignUpErrorState(error.toString()); } } @@ -60,7 +60,7 @@ class SignUpBloc extends Bloc { yield SignUpFinishedState(); } catch (error) { - yield SignUpErrorState(error); + yield SignUpErrorState(error.toString()); } } } diff --git a/lib/presentation/features/sign_up/sign_up_event.dart b/lib/presentation/features/sign_up/sign_up_event.dart index 22285f81..199744fc 100644 --- a/lib/presentation/features/sign_up/sign_up_event.dart +++ b/lib/presentation/features/sign_up/sign_up_event.dart @@ -10,7 +10,7 @@ class SignUpPressed extends SignUpEvent { final String password; final String name; - SignUpPressed({this.name, this.email, this.password}); + SignUpPressed({required this.name, required this.email, required this.password}); @override List get props => [email, password]; diff --git a/lib/presentation/features/sign_up/sign_up_state.dart b/lib/presentation/features/sign_up/sign_up_state.dart index 918aa925..4166fa46 100644 --- a/lib/presentation/features/sign_up/sign_up_state.dart +++ b/lib/presentation/features/sign_up/sign_up_state.dart @@ -10,12 +10,12 @@ class SignUpInitialState extends SignUpState {} class SignUpProcessingState extends SignUpState {} class SignUpErrorState extends SignUpState { - final String error; + final String? error; SignUpErrorState(this.error); @override - List get props => [error]; + List get props => [error!]; } class SignUpFinishedState extends SignUpState {} diff --git a/lib/presentation/features/sign_up/signup_screen.dart b/lib/presentation/features/sign_up/signup_screen.dart index e5a3be5a..395016b0 100644 --- a/lib/presentation/features/sign_up/signup_screen.dart +++ b/lib/presentation/features/sign_up/signup_screen.dart @@ -21,7 +21,7 @@ class _SignUpScreenState extends State { final GlobalKey passwordKey = GlobalKey(); final GlobalKey nameKey = GlobalKey(); - double sizeBetween; + late double sizeBetween; @override Widget build(BuildContext context) { @@ -47,7 +47,7 @@ class _SignUpScreenState extends State { } // on failure show a snackbar if (state is SignUpErrorState) { - Scaffold.of(context).showSnackBar( + ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('${state.error}'), backgroundColor: Colors.red, @@ -147,13 +147,13 @@ class _SignUpScreenState extends State { } void _validateAndSend() { - if (nameKey.currentState.validate() != null) { + if (nameKey.currentState?.validate() != null) { return; } - if (emailKey.currentState.validate() != null) { + if (emailKey.currentState?.validate() != null) { return; } - if (passwordKey.currentState.validate() != null) { + if (passwordKey.currentState?.validate() != null) { return; } BlocProvider.of(context).add( diff --git a/lib/presentation/features/wrapper.dart b/lib/presentation/features/wrapper.dart index 075a3964..5168229d 100644 --- a/lib/presentation/features/wrapper.dart +++ b/lib/presentation/features/wrapper.dart @@ -7,7 +7,7 @@ import 'package:flutter/material.dart'; enum ViewChangeType { Start, Forward, Backward, Exact } class OpenFlutterWrapperState extends State { - PageController _viewController; + late PageController _viewController; PageView getPageView(List widgets) { return PageView( @@ -16,7 +16,7 @@ class OpenFlutterWrapperState extends State { children: widgets); } - void changePage({@required ViewChangeType changeType, int index}) { + void changePage({required ViewChangeType changeType, required int index}) { switch (changeType) { case ViewChangeType.Forward: _viewController.nextPage( diff --git a/lib/presentation/widgets/data_driven/box_value_select.dart b/lib/presentation/widgets/data_driven/box_value_select.dart index 50b40f0e..4b43401f 100644 --- a/lib/presentation/widgets/data_driven/box_value_select.dart +++ b/lib/presentation/widgets/data_driven/box_value_select.dart @@ -12,20 +12,19 @@ class OpenFlutterSelectValuesBoxes extends StatefulWidget { final double boxWidth; const OpenFlutterSelectValuesBoxes( - {Key key, - @required this.availableValues, - @required this.selectedValues, - @required this.label, - @required this.onClick, - this.boxWidth}) - : super(key: key); + {required this.availableValues, + required this.selectedValues, + required this.label, + required this.onClick, + required this.boxWidth}) + ; @override _OpenFlutterSelectValuesBoxesState createState() => _OpenFlutterSelectValuesBoxesState(); } class _OpenFlutterSelectValuesBoxesState extends State> { - List selectedValues; + late List selectedValues; @override void initState() { @@ -85,7 +84,7 @@ class _OpenFlutterSelectValuesBoxesState extends State _OpenFlutterCartTileState(); @@ -60,7 +59,7 @@ class _OpenFlutterCartTileState extends State { width: width - 173, child: Text(widget.item.product.title, style: _theme.textTheme.headline4 - .copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor)), + ?.copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor)), ), !widget.orderComplete ? InkWell( @@ -140,7 +139,7 @@ class _OpenFlutterCartTileState extends State { child: Row(children: [ Text('Units: ', style: _theme.textTheme.bodyText1), Text(widget.item.productQuantity.quantity.toString(), - style: _theme.textTheme.bodyText1.copyWith(color: _theme.primaryColor)), + style: _theme.textTheme.bodyText1?.copyWith(color: _theme.primaryColor)), ])), Container( width: width - 280, diff --git a/lib/presentation/widgets/data_driven/category_list_element.dart b/lib/presentation/widgets/data_driven/category_list_element.dart index fd5b45a7..602556cf 100644 --- a/lib/presentation/widgets/data_driven/category_list_element.dart +++ b/lib/presentation/widgets/data_driven/category_list_element.dart @@ -9,7 +9,7 @@ import 'package:openflutterecommerce/data/model/category.dart'; class OpenFlutterCatregoryListElement extends StatelessWidget { final ProductCategory category; - const OpenFlutterCatregoryListElement({Key key, this.category}) : super(key: key); + const OpenFlutterCatregoryListElement({required this.category}); @override Widget build(BuildContext context) { @@ -26,6 +26,8 @@ class OpenFlutterCatregoryListElement extends StatelessWidget { bottom: BorderSide(color: _theme.primaryColorLight, width: 0.4), ), ), - child: Text(category.name, style: _theme.textTheme.headline4.copyWith(fontWeight: FontWeight.normal))); + child: Text(category.name, + style: _theme.textTheme.headline4 + ?.copyWith(fontWeight: FontWeight.normal))); } } diff --git a/lib/presentation/widgets/data_driven/category_tile.dart b/lib/presentation/widgets/data_driven/category_tile.dart index 1fea4b84..7bcac457 100644 --- a/lib/presentation/widgets/data_driven/category_tile.dart +++ b/lib/presentation/widgets/data_driven/category_tile.dart @@ -13,7 +13,7 @@ class OpenFlutterCategoryTile extends StatelessWidget { final double height; final double width; - const OpenFlutterCategoryTile({Key key, this.category, this.height, this.width}) : super(key: key); + const OpenFlutterCategoryTile({required this.category, required this.height, required this.width}); @override Widget build(BuildContext context) { @@ -32,7 +32,8 @@ class OpenFlutterCategoryTile extends StatelessWidget { Container( alignment: Alignment.centerLeft, width: width - 200.0, - child: Text(category.name, style: _theme.textTheme.headline4)), + child: + Text(category.name, style: _theme.textTheme.headline4)), Container( width: 200, alignment: Alignment.centerRight, diff --git a/lib/presentation/widgets/data_driven/hashtag_list.dart b/lib/presentation/widgets/data_driven/hashtag_list.dart index a03a2689..3a6a1c57 100644 --- a/lib/presentation/widgets/data_driven/hashtag_list.dart +++ b/lib/presentation/widgets/data_driven/hashtag_list.dart @@ -11,8 +11,7 @@ class OpenFlutterHashTagList extends StatelessWidget { final double height; final Function onTap; - const OpenFlutterHashTagList({Key key, this.tags, this.onTap, this.height}) - : super(key: key); + const OpenFlutterHashTagList({required this.tags, required this.onTap, required this.height}); @override Widget build(BuildContext context) { diff --git a/lib/presentation/widgets/data_driven/order_tile.dart b/lib/presentation/widgets/data_driven/order_tile.dart index c46f777b..583b39cb 100644 --- a/lib/presentation/widgets/data_driven/order_tile.dart +++ b/lib/presentation/widgets/data_driven/order_tile.dart @@ -7,7 +7,7 @@ class OpenFlutterOrderTile extends StatelessWidget { final UserOrder order; final Function(int) onClick; - const OpenFlutterOrderTile({Key key, @required this.order, @required this.onClick}) : super(key: key); + const OpenFlutterOrderTile({required this.order, required this.onClick}); @override Widget build(BuildContext context) { @@ -38,15 +38,15 @@ class OpenFlutterOrderTile extends StatelessWidget { TextSpan( text: 'Order: ', style: _theme.textTheme.headline4 - .copyWith(color: _theme.primaryColorLight, fontWeight: FontWeight.normal), + ?.copyWith(color: _theme.primaryColorLight, fontWeight: FontWeight.normal), ), TextSpan( text: '#' + order.orderNumber.toString(), - style: _theme.textTheme.headline4.copyWith(fontWeight: FontWeight.w700), + style: _theme.textTheme.headline4?.copyWith(fontWeight: FontWeight.w700), ), ])), Text(DateFormat('yyyy-MM-dd').format(order.orderDate), - style: _theme.textTheme.headline2.copyWith(color: AppColors.red)) + style: _theme.textTheme.headline2?.copyWith(color: AppColors.red)) ], ), SizedBox( @@ -60,7 +60,7 @@ class OpenFlutterOrderTile extends StatelessWidget { children: [ Text( 'Tacking Number: ', - style: _theme.textTheme.headline4.copyWith(color: _theme.primaryColorLight), + style: _theme.textTheme.headline4?.copyWith(color: _theme.primaryColorLight), ), Padding( padding: const EdgeInsets.only(left: AppSizes.sidePadding), @@ -81,7 +81,7 @@ class OpenFlutterOrderTile extends StatelessWidget { children: [ Text( 'Quantity: ', - style: _theme.textTheme.headline4.copyWith(color: _theme.primaryColorLight), + style: _theme.textTheme.headline4?.copyWith(color: _theme.primaryColorLight), ), Padding( padding: const EdgeInsets.only(left: AppSizes.linePadding), @@ -96,7 +96,7 @@ class OpenFlutterOrderTile extends StatelessWidget { children: [ Text( 'Totat Amount: ', - style: _theme.textTheme.headline4.copyWith(color: _theme.primaryColorLight), + style: _theme.textTheme.headline4?.copyWith(color: _theme.primaryColorLight), ), Padding( padding: const EdgeInsets.only(left: AppSizes.sidePadding), @@ -118,7 +118,7 @@ class OpenFlutterOrderTile extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - RaisedButton( + MaterialButton( padding: EdgeInsets.only(left: 24, right: 24, top: 10, bottom: 10), color: AppColors.white, onPressed: () { @@ -133,7 +133,7 @@ class OpenFlutterOrderTile extends StatelessWidget { ), ), Text(order.orderStatus.toString().split('.')[1], - style: _theme.textTheme.headline4.copyWith(color: AppColors.green)), + style: _theme.textTheme.headline4?.copyWith(color: AppColors.green)), ], ) ], diff --git a/lib/presentation/widgets/data_driven/product_list_view.dart b/lib/presentation/widgets/data_driven/product_list_view.dart index f77609af..1c48aa9b 100644 --- a/lib/presentation/widgets/data_driven/product_list_view.dart +++ b/lib/presentation/widgets/data_driven/product_list_view.dart @@ -17,11 +17,10 @@ class OpenFlutterProductListView extends StatelessWidget { final Function(Product product) onFavoritesTap; const OpenFlutterProductListView({ - Key key, - this.width, - this.products, - @required this.onFavoritesTap - }) : super(key: key); + required this.width, + required this.products, + required this.onFavoritesTap + }); @override Widget build(BuildContext context) { diff --git a/lib/presentation/widgets/data_driven/promo_tile.dart b/lib/presentation/widgets/data_driven/promo_tile.dart index 0955d845..c1b121bc 100644 --- a/lib/presentation/widgets/data_driven/promo_tile.dart +++ b/lib/presentation/widgets/data_driven/promo_tile.dart @@ -9,8 +9,7 @@ class OpenFlutterPromoTile extends StatelessWidget { final Function onClickApply; final Color textColor; - const OpenFlutterPromoTile({Key key, @required this.item, @required this.onClickApply, @required this.textColor}) - : super(key: key); + const OpenFlutterPromoTile({ required this.item, required this.onClickApply, required this.textColor}); @override Widget build(BuildContext context) { @@ -42,13 +41,13 @@ class OpenFlutterPromoTile extends StatelessWidget { padding: EdgeInsets.all(AppSizes.linePadding * 2), child: Row(children: [ Text(item.discount.toStringAsFixed(0), - style: _theme.textTheme.caption.copyWith(color: textColor, fontSize: 32)), + style: _theme.textTheme.caption?.copyWith(color: textColor, fontSize: 32)), Padding( padding: EdgeInsets.only(top: 16, left: 5), child: Column( children: [ - Text('%', style: _theme.textTheme.headline2.copyWith(color: textColor)), - Text('off', style: _theme.textTheme.headline2.copyWith(color: textColor)) + Text('%', style: _theme.textTheme.headline2?.copyWith(color: textColor)), + Text('off', style: _theme.textTheme.headline2?.copyWith(color: textColor)) ], )) ])), @@ -62,8 +61,8 @@ class OpenFlutterPromoTile extends StatelessWidget { children: [ Text(item.title, style: _theme.textTheme.headline4 - .copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor)), - Text(item.promoCode, style: _theme.textTheme.bodyText1.copyWith(color: _theme.primaryColor)) + ?.copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor)), + Text(item.promoCode, style: _theme.textTheme.bodyText1?.copyWith(color: _theme.primaryColor)) ])), Container( padding: EdgeInsets.only(left: AppSizes.sidePadding, top: AppSizes.linePadding * 2), @@ -71,7 +70,7 @@ class OpenFlutterPromoTile extends StatelessWidget { child: Column(children: [ Text(item.daysLeft.toString() + ' days remaining', style: - _theme.textTheme.headline2.copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor)), + _theme.textTheme.headline2?.copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor)), Padding(padding: EdgeInsets.only(bottom: AppSizes.linePadding)), OpenFlutterButton( width: 120, diff --git a/lib/presentation/widgets/data_driven/rating_summary.dart b/lib/presentation/widgets/data_driven/rating_summary.dart index a91ae897..ae9abb6c 100644 --- a/lib/presentation/widgets/data_driven/rating_summary.dart +++ b/lib/presentation/widgets/data_driven/rating_summary.dart @@ -8,7 +8,7 @@ import '../widgets.dart'; class OpenFlutterRatingSummary extends StatelessWidget { final double rating; - final List ratingDetail; + final List? ratingDetail; final int startCount; final int ratingQuantity; final bool showLabel; @@ -19,7 +19,6 @@ class OpenFlutterRatingSummary extends StatelessWidget { final double reviewCounterLabelFontSize; const OpenFlutterRatingSummary({ - Key key, this.startCount = 5, this.rating = 5, this.ratingQuantity = 0, @@ -30,7 +29,7 @@ class OpenFlutterRatingSummary extends StatelessWidget { this.starIconSize = 14.0, this.labelFontSize = 14.0, this.reviewCounterLabelFontSize = 14.0, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -51,7 +50,7 @@ class OpenFlutterRatingSummary extends StatelessWidget { children: [ Text( rating.toString(), - style: Theme.of(context).textTheme.headline3.copyWith( + style: Theme.of(context).textTheme.headline3?.copyWith( color: Colors.black, ), ), @@ -75,7 +74,7 @@ class OpenFlutterRatingSummary extends StatelessWidget { if (showLabel) { return Text( '${ratingQuantity.toString()} ratings', - style: Theme.of(context).textTheme.caption.copyWith( + style: Theme.of(context).textTheme.caption?.copyWith( color: Colors.grey, fontSize: labelFontSize, ), @@ -90,8 +89,8 @@ class OpenFlutterRatingSummary extends StatelessWidget { List _buildList(BuildContext context) { var list = []; - if (ratingDetail != null && ratingDetail.isNotEmpty) { - ratingDetail.forEach((starQuantity) { + if (ratingDetail != null && ratingDetail!.isNotEmpty) { + ratingDetail!.forEach((starQuantity) { list.add(_buildItem(context, starQuantity)); }); } @@ -172,7 +171,7 @@ class OpenFlutterRatingSummary extends StatelessWidget { return Center( child: Text( starQuantity.quantity.toInt().toString(), - style: Theme.of(context).textTheme.caption.copyWith( + style: Theme.of(context).textTheme.caption?.copyWith( fontSize: reviewCounterLabelFontSize, ), textAlign: TextAlign.center, @@ -201,7 +200,7 @@ class StarQuantity { final int quantity; StarQuantity({ - this.rating, - this.quantity, + required this.rating, + required this.quantity, }); } 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 b77304e0..0b88d349 100644 --- a/lib/presentation/widgets/data_driven/size_changing_app_bar.dart +++ b/lib/presentation/widgets/data_driven/size_changing_app_bar.dart @@ -17,15 +17,13 @@ class SizeChangingAppBar extends StatelessWidget { final VoidCallback onViewChanged; const SizeChangingAppBar( - {Key key, - this.title, - @required this.filterRules, - this.sortRules, + {required this.title, + required this.filterRules, + required this.sortRules, this.isListView = true, - this.onFilterRulesChanged, - this.onSortRulesChanged, - this.onViewChanged}) - : super(key: key); + required this.onFilterRulesChanged, + required this.onSortRulesChanged, + required this.onViewChanged}); @override Widget build(BuildContext context) { @@ -60,7 +58,7 @@ class SizeChangingAppBar extends StatelessWidget { Container( height: 30, child: VisualFilter( - filterRules?.hashTags, filterRules?.selectedHashTags, + filterRules!.hashTags, filterRules!.selectedHashTags, (updateValue, isSelected) { BlocProvider.of(context).add( ProductChangeHashTagEvent(updateValue, isSelected)); diff --git a/lib/presentation/widgets/extensions/product_view.dart b/lib/presentation/widgets/extensions/product_view.dart index 9941c46b..76ed60a4 100644 --- a/lib/presentation/widgets/extensions/product_view.dart +++ b/lib/presentation/widgets/extensions/product_view.dart @@ -15,14 +15,15 @@ import 'commerce_image_view.dart'; extension View on Product { Widget getListView( - {@required BuildContext context, - @required VoidCallback showProductInfo, - @required VoidCallback onFavoritesClick}) { + {required BuildContext context, + required VoidCallback showProductInfo, + required VoidCallback onFavoritesClick}) { return BaseProductListItem( onClick: showProductInfo, - inactiveMessage: amountAvailable == null || amountAvailable > 0 ? null : 'Sorry, this item is currently sold out', + inactiveMessage: + (amountAvailable > 0) ? '' : 'Sorry, this item is currently sold out', bottomRoundButton: _getFavoritesButton(onFavoritesClick), - image: mainImage?.getView(), + image: mainImage.getView(), specialMark: specialMark, mainContentBuilder: (context) { return Column( @@ -39,14 +40,14 @@ extension View on Product { } Widget getTileView( - {@required BuildContext context, - @required VoidCallback showProductInfo, - @required VoidCallback onFavoritesClick}) { + {required BuildContext context, + required VoidCallback showProductInfo, + required VoidCallback onFavoritesClick}) { return BaseProductTile( onClick: showProductInfo, bottomRoundButton: _getFavoritesButton(onFavoritesClick), inactiveMessage: - amountAvailable == null || amountAvailable > 0 ? null : 'Sorry, this item is currently sold out', + amountAvailable > 0 ? '' : 'Sorry, this item is currently sold out', image: mainImage.getView(), mainContentBuilder: (context) { return Column( @@ -55,7 +56,8 @@ extension View on Product { buildRating(context), Padding( padding: EdgeInsets.symmetric(vertical: 4.0), - child: Text(title, style: Theme.of(context).textTheme.headline4), + child: + Text(title, style: Theme.of(context).textTheme.headline4), ), Row( children: [ @@ -70,10 +72,8 @@ extension View on Product { Widget _getFavoritesButton(VoidCallback onFavoritesClick) { return FloatingActionButton( - 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 + 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, @@ -95,8 +95,10 @@ extension View on Product { return Row(children: [ Text( price != null ? '\$' + price.toStringAsFixed(0) : '', - style: _theme.textTheme.headline2.copyWith( - decoration: hasDiscountPrice ? TextDecoration.lineThrough : TextDecoration.none, + style: _theme.textTheme.headline2?.copyWith( + decoration: hasDiscountPrice + ? TextDecoration.lineThrough + : TextDecoration.none, ), ), SizedBox( @@ -108,7 +110,8 @@ extension View on Product { Widget buildRating(BuildContext context) { return Container( - padding: EdgeInsets.only(top: AppSizes.linePadding, bottom: AppSizes.linePadding), + padding: EdgeInsets.only( + top: AppSizes.linePadding, bottom: AppSizes.linePadding), child: OpenFlutterProductRating( rating: averageRating, ratingCount: ratingCount, @@ -120,21 +123,21 @@ extension View on Product { Widget buildDiscountPrice(ThemeData _theme) { return Text('\$' + discountPrice.toStringAsFixed(0), - style: _theme.textTheme.headline2.copyWith(color: _theme.errorColor)); + style: _theme.textTheme.headline2?.copyWith(color: _theme.errorColor)); } } extension FavoriteView on FavoriteProduct { Widget getListView( - {@required BuildContext context, - @required VoidCallback showProductInfo, - @required VoidCallback onAddToCart, - @required VoidCallback onRemoveFromFavorites, - @required HashMap selectedAttributes}) { + {required BuildContext context, + required VoidCallback showProductInfo, + required VoidCallback onAddToCart, + required VoidCallback onRemoveFromFavorites, + Map? selectedAttributes}) { return BaseProductListItem( onClick: showProductInfo, - inactiveMessage: product.amountAvailable == null || product.amountAvailable > 0 - ? null + inactiveMessage: product.amountAvailable > 0 + ? '' : 'Sorry, this item is currently sold out', bottomRoundButton: FloatingActionButton( heroTag: 'Remove from Cart' + Random().nextInt(1000000).toString(), @@ -178,15 +181,15 @@ extension FavoriteView on FavoriteProduct { } Widget getTileView( - {@required BuildContext context, - @required VoidCallback showProductInfo, - @required VoidCallback onAddToCart, - @required VoidCallback onRemoveFromFavorites, - @required HashMap selectedAttributes}) { + {required BuildContext context, + required VoidCallback showProductInfo, + required VoidCallback onAddToCart, + required VoidCallback onRemoveFromFavorites, + required Map selectedAttributes}) { return BaseProductTile( onClick: showProductInfo, - inactiveMessage: product.amountAvailable == null || product.amountAvailable > 0 - ? null + inactiveMessage: product.amountAvailable > 0 + ? '' : 'Sorry, this item is currently sold out', bottomRoundButton: FloatingActionButton( heroTag: 'Add to Cart' + Random().nextInt(1000000).toString(), @@ -228,7 +231,8 @@ extension FavoriteView on FavoriteProduct { }); } - Widget _buildColor(ThemeData _theme, HashMap selectedAttributes) { + Widget _buildColor( + ThemeData _theme, Map? selectedAttributes) { String colorValue = ''; selectedAttributes?.forEach((attribute, value) { if (attribute.name == 'Color') colorValue = value; @@ -236,17 +240,20 @@ extension FavoriteView on FavoriteProduct { return colorValue.isNotEmpty ? Row( children: [ - Text('Color:', style: _theme.textTheme.bodyText1.copyWith()), + Text('Color:', style: _theme.textTheme.bodyText1?.copyWith()), Padding( padding: EdgeInsets.only(left: AppSizes.linePadding), ), - Text(colorValue, style: _theme.textTheme.bodyText1.copyWith(color: AppColors.black)) + Text(colorValue, + style: _theme.textTheme.bodyText1 + ?.copyWith(color: AppColors.black)) ], ) : Row(); } - Row _buildSize(ThemeData _theme, HashMap selectedAttributes) { + Row _buildSize( + ThemeData _theme, Map? selectedAttributes) { String sizeValue = ''; selectedAttributes?.forEach((attribute, value) { if (attribute.name == 'Size') sizeValue = value; @@ -254,11 +261,13 @@ extension FavoriteView on FavoriteProduct { return sizeValue.isNotEmpty ? Row( children: [ - Text('Size:', style: _theme.textTheme.bodyText1.copyWith()), + Text('Size:', style: _theme.textTheme.bodyText1?.copyWith()), Padding( padding: EdgeInsets.only(left: AppSizes.linePadding), ), - Text(sizeValue, style: _theme.textTheme.bodyText1.copyWith(color: AppColors.black)) + Text(sizeValue, + style: _theme.textTheme.bodyText1 + ?.copyWith(color: AppColors.black)) ], ) : Row(); diff --git a/lib/presentation/widgets/independent/action_card.dart b/lib/presentation/widgets/independent/action_card.dart index a2beaaf5..c3a09e82 100644 --- a/lib/presentation/widgets/independent/action_card.dart +++ b/lib/presentation/widgets/independent/action_card.dart @@ -7,8 +7,7 @@ class OpenFlutterActionCard extends StatelessWidget { final Function onLinkTap; final Widget child; - const OpenFlutterActionCard({Key key, @required this.title, this.linkText, this.child, this.onLinkTap}) - : super(key: key); + const OpenFlutterActionCard({required this.title, required this.linkText, required this.child, required this.onLinkTap}); @override Widget build(BuildContext context) { @@ -33,7 +32,7 @@ class OpenFlutterActionCard extends StatelessWidget { children: [ Container( width: width / 3 * 2, - child: Text(title, style: _theme.textTheme.headline2.copyWith(color: _theme.primaryColor))), + child: Text(title, style: _theme.textTheme.headline2?.copyWith(color: _theme.primaryColor))), linkText != null ? Container( alignment: Alignment.centerRight, @@ -41,7 +40,7 @@ class OpenFlutterActionCard extends StatelessWidget { child: InkWell( onTap: (() => {onLinkTap()}), child: - Text(linkText, style: _theme.textTheme.headline2.copyWith(color: _theme.accentColor)), + Text(linkText, style: _theme.textTheme.headline2?.copyWith(color: _theme.accentColor)), )) : Container() ], diff --git a/lib/presentation/widgets/independent/base_product_list_item.dart b/lib/presentation/widgets/independent/base_product_list_item.dart index ffefaaf2..f35effba 100644 --- a/lib/presentation/widgets/independent/base_product_list_item.dart +++ b/lib/presentation/widgets/independent/base_product_list_item.dart @@ -2,28 +2,21 @@ import 'package:flutter/material.dart'; import 'package:openflutterecommerce/config/theme.dart'; class BaseProductListItem extends StatelessWidget { - final VoidCallback onClick; + final VoidCallback? onClick; final String inactiveMessage; final Widget bottomRoundButton; - final ImageProvider image; + final ImageProvider? image; final WidgetBuilder mainContentBuilder; - final String specialMark; - final VoidCallback onRemove; + final String? specialMark; + final VoidCallback? onRemove; final double imageHeight; final double imageWidth; const BaseProductListItem( - {Key key, - this.onClick, - this.inactiveMessage, - this.bottomRoundButton, - this.image, - this.mainContentBuilder, - this.imageHeight = 125, - this.imageWidth = 125, - this.specialMark, - this.onRemove}) - : super(key: key); + { this.onClick, + required this.inactiveMessage, + required this.bottomRoundButton, this.image, + required this.mainContentBuilder, this.imageHeight = 125, this.imageWidth = 125, this.specialMark, this.onRemove}); @override Widget build(BuildContext context) { @@ -49,7 +42,10 @@ class BaseProductListItem extends StatelessWidget { width: imageWidth, height: imageHeight, decoration: BoxDecoration( - image: image == null ? null : DecorationImage(image: image, fit: BoxFit.cover), + image: image == null + ? null + : DecorationImage( + image: image!, fit: BoxFit.cover), color: AppColors.background, borderRadius: BorderRadius.only( topLeft: Radius.circular(AppSizes.imageRadius), @@ -90,14 +86,19 @@ class BaseProductListItem extends StatelessWidget { child: Container( padding: EdgeInsets.all(AppSizes.linePadding * 1.5), decoration: BoxDecoration( - borderRadius: BorderRadius.circular(AppSizes.imageRadius), - color: specialMark == 'New' ? AppColors.red : AppColors.black, + borderRadius: + BorderRadius.circular(AppSizes.imageRadius), + color: specialMark == 'New' + ? AppColors.red + : AppColors.black, ), - child: Text(specialMark, + child: Text(specialMark!, style: Theme.of(context) .textTheme .bodyText1 - .copyWith(color: AppColors.white, fontWeight: FontWeight.bold))), + ?.copyWith( + color: AppColors.white, + fontWeight: FontWeight.bold))), ), onRemove == null ? Container() diff --git a/lib/presentation/widgets/independent/base_product_tile.dart b/lib/presentation/widgets/independent/base_product_tile.dart index 5cd028fc..bbf02d0a 100644 --- a/lib/presentation/widgets/independent/base_product_tile.dart +++ b/lib/presentation/widgets/independent/base_product_tile.dart @@ -8,24 +8,23 @@ class BaseProductTile extends StatelessWidget { final ImageProvider image; final WidgetBuilder mainContentBuilder; final String specialMark; - final VoidCallback onRemove; + final VoidCallback? onRemove; final double imageHeight; final double imageWidth; final double tileHeight; const BaseProductTile( - {Key key, - this.onClick, - this.inactiveMessage, - this.bottomRoundButton, - this.image, - this.mainContentBuilder, + { + required this.onClick, + required this.inactiveMessage, + required this.bottomRoundButton, + required this.image, + required this.mainContentBuilder, this.imageHeight = 184, this.imageWidth = AppSizes.tile_width, this.tileHeight = AppSizes.tile_height, - this.specialMark, - this.onRemove}) - : super(key: key); + required this.specialMark, this.onRemove}) + ; @override Widget build(BuildContext context) { @@ -85,7 +84,7 @@ class BaseProductTile extends StatelessWidget { style: Theme.of(context) .textTheme .bodyText1 - .copyWith(color: AppColors.white, fontWeight: FontWeight.bold))), + ?.copyWith(color: AppColors.white, fontWeight: FontWeight.bold))), ), onRemove == null ? Container() diff --git a/lib/presentation/widgets/independent/block_header.dart b/lib/presentation/widgets/independent/block_header.dart index 0a475e3f..ea289e53 100644 --- a/lib/presentation/widgets/independent/block_header.dart +++ b/lib/presentation/widgets/independent/block_header.dart @@ -8,13 +8,11 @@ import 'package:openflutterecommerce/config/theme.dart'; class OpenFlutterBlockHeader extends StatelessWidget { final double width; final String title; - final String linkText; - final VoidCallback onLinkTap; - final String description; + final String? linkText; + final VoidCallback? onLinkTap; + final String? description; - const OpenFlutterBlockHeader( - {Key key, @required this.width, @required this.title, this.linkText, this.onLinkTap, this.description}) - : super(key: key); + const OpenFlutterBlockHeader({required this.width, required this.title, this.linkText, this.onLinkTap, this.description}); @override Widget build(BuildContext context) { @@ -23,7 +21,8 @@ class OpenFlutterBlockHeader extends StatelessWidget { return InkWell( onTap: onLinkTap, child: Container( - padding: EdgeInsets.only(top: AppSizes.sidePadding, left: AppSizes.sidePadding), + padding: EdgeInsets.only( + top: AppSizes.sidePadding, left: AppSizes.sidePadding), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -38,7 +37,8 @@ class OpenFlutterBlockHeader extends StatelessWidget { width: rightLinkWidth, child: Align( alignment: Alignment.centerRight, - child: Text(linkText, style: _theme.textTheme.bodyText2), + child: + Text(linkText!, style: _theme.textTheme.bodyText2), ), ) : Container(), @@ -46,7 +46,7 @@ class OpenFlutterBlockHeader extends StatelessWidget { ), description != null ? Text( - description, + description!, style: _theme.textTheme.bodyText2, ) : Container() diff --git a/lib/presentation/widgets/independent/block_subtitle.dart b/lib/presentation/widgets/independent/block_subtitle.dart index 90a6e8e5..7ffa8bf7 100644 --- a/lib/presentation/widgets/independent/block_subtitle.dart +++ b/lib/presentation/widgets/independent/block_subtitle.dart @@ -6,25 +6,25 @@ import 'package:flutter/material.dart'; import 'package:openflutterecommerce/config/theme.dart'; class OpenFlutterBlockSubtitle extends StatelessWidget { - final double width; + final double? width; final String title; - final String linkText; - final Function onLinkTap; + final String? linkText; + final Function? onLinkTap; const OpenFlutterBlockSubtitle({ - Key key, this.width, - @required this.title, + required this.title, this.linkText, this.onLinkTap, - }) : super(key: key); + }); @override Widget build(BuildContext context) { var _theme = Theme.of(context); const rightLinkWidth = 100.0; return Container( - padding: EdgeInsets.only(top: AppSizes.sidePadding, left: AppSizes.sidePadding), + padding: EdgeInsets.only( + top: AppSizes.sidePadding, left: AppSizes.sidePadding), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -33,18 +33,20 @@ class OpenFlutterBlockSubtitle extends StatelessWidget { children: [ Container( child: Text(title, - style: _theme.textTheme.headline4 - .copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor))), + style: _theme.textTheme.headline4?.copyWith( + fontWeight: FontWeight.bold, + color: _theme.primaryColor))), linkText != null ? InkWell( - onTap: (() => {onLinkTap()}), + onTap: (() => {onLinkTap!()}), child: Container( width: rightLinkWidth, child: Align( alignment: Alignment.centerRight, child: Text( - linkText, - style: _theme.textTheme.headline4.copyWith(color: _theme.accentColor), + linkText!, + style: _theme.textTheme.headline4 + ?.copyWith(color: _theme.accentColor), ), ), ), diff --git a/lib/presentation/widgets/independent/bottom_menu.dart b/lib/presentation/widgets/independent/bottom_menu.dart index fc2cd5ab..70f95730 100644 --- a/lib/presentation/widgets/independent/bottom_menu.dart +++ b/lib/presentation/widgets/independent/bottom_menu.dart @@ -24,14 +24,7 @@ class OpenFlutterBottomMenu extends StatelessWidget { height: 24.0, width: 24.0, color: colorByIndex(theme, index), - ), - title: Text( - title, - style: TextStyle( - fontSize: 10.0, - color: colorByIndex(theme, index), - ), - ), + ) ); } diff --git a/lib/presentation/widgets/independent/bottom_popup.dart b/lib/presentation/widgets/independent/bottom_popup.dart index 8a52bcce..8c3a77e2 100644 --- a/lib/presentation/widgets/independent/bottom_popup.dart +++ b/lib/presentation/widgets/independent/bottom_popup.dart @@ -5,7 +5,7 @@ class OpenFlutterBottomPopup extends StatelessWidget { final Widget child; final String title; - const OpenFlutterBottomPopup({Key key, @required this.child, @required this.title}) : super(key: key); + const OpenFlutterBottomPopup({ required this.child, required this.title}) ; @override Widget build(BuildContext context) { diff --git a/lib/presentation/widgets/independent/clickable_line.dart b/lib/presentation/widgets/independent/clickable_line.dart index 1086296f..96ca93f9 100644 --- a/lib/presentation/widgets/independent/clickable_line.dart +++ b/lib/presentation/widgets/independent/clickable_line.dart @@ -12,15 +12,15 @@ class OpenFlutterClickableLine extends StatelessWidget { final Function(SortRules) onTap; const OpenFlutterClickableLine( - {Key key, - @required this.width, - @required this.height, - @required this.title, - @required this.onTap, - @required this.sortRules, - this.backgroundColor, - this.textColor}) - : super(key: key); + { + required this.width, + required this.height, + required this.title, + required this.onTap, + required this.sortRules, + required this.backgroundColor, + required this.textColor}) + ; @override Widget build(BuildContext context) { @@ -34,6 +34,6 @@ class OpenFlutterClickableLine extends StatelessWidget { width: width, color: backgroundColor, child: Text(title, - style: _theme.textTheme.headline4.copyWith(fontWeight: FontWeight.normal, color: textColor)))); + style: _theme.textTheme.headline4?.copyWith(fontWeight: FontWeight.normal, color: textColor)))); } } diff --git a/lib/presentation/widgets/independent/color_select.dart b/lib/presentation/widgets/independent/color_select.dart index e2a0d91f..b700940c 100644 --- a/lib/presentation/widgets/independent/color_select.dart +++ b/lib/presentation/widgets/independent/color_select.dart @@ -10,19 +10,19 @@ class OpenFlutterColorSelect extends StatefulWidget { final Function(List) onClick; const OpenFlutterColorSelect( - {Key key, - @required this.availableColors, - @required this.selectedColors, - @required this.label, - @required this.onClick}) - : super(key: key); + { + required this.availableColors, + required this.selectedColors, + required this.label, + required this.onClick}) + ; @override _OpenFlutterColorSelectState createState() => _OpenFlutterColorSelectState(); } class _OpenFlutterColorSelectState extends State { - List selectedColors; + late List selectedColors; @override void initState() { @@ -34,7 +34,7 @@ class _OpenFlutterColorSelectState extends State { Widget build(BuildContext context) { var width = MediaQuery.of(context).size.width; return Column(children: [ - OpenFlutterBlockSubtitle(title: widget.label, width: width), + OpenFlutterBlockSubtitle(title: widget.label, width: width, linkText: '', onLinkTap: (){},), Padding( padding: EdgeInsets.only(bottom: AppSizes.sidePadding), ), diff --git a/lib/presentation/widgets/independent/custom_button.dart b/lib/presentation/widgets/independent/custom_button.dart index 92592460..6661cbca 100644 --- a/lib/presentation/widgets/independent/custom_button.dart +++ b/lib/presentation/widgets/independent/custom_button.dart @@ -6,28 +6,27 @@ import 'package:flutter/material.dart'; import 'package:openflutterecommerce/config/theme.dart'; class OpenFlutterButton extends StatelessWidget { - final double width; - final double height; - final Function onPressed; + final double? width; + final double? height; + final Function() onPressed; final String title; - final IconData icon; + IconData? icon; final double iconSize; final Color backgroundColor; final Color textColor; final Color borderColor; OpenFlutterButton({ - Key key, this.width, this.height, - @required this.title, - @required this.onPressed, + required this.title, + required this.onPressed, this.icon, this.backgroundColor = AppColors.red, this.textColor = AppColors.white, this.borderColor = AppColors.red, this.iconSize = 18.0, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -67,7 +66,7 @@ class OpenFlutterButton extends StatelessWidget { ), ), ); - /*RaisedButton( + /*MaterialButton( onPressed: onPressed, shape: new RoundedRectangleBorder( borderRadius: new BorderRadius.circular( @@ -79,7 +78,7 @@ class OpenFlutterButton extends StatelessWidget { width: width, height: height, child: Text(title, - style: _theme.textTheme.button.copyWith( + style: _theme.textTheme.button?.copyWith( backgroundColor: _theme.textTheme.button.backgroundColor, color: _theme.textTheme.button.color ) @@ -91,8 +90,8 @@ class OpenFlutterButton extends StatelessWidget { Widget _buildTitle(ThemeData _theme) { return Text( title, - style: _theme.textTheme.button.copyWith( - backgroundColor: _theme.textTheme.button.backgroundColor, + style: _theme.textTheme.button?.copyWith( + backgroundColor: _theme.textTheme.button?.backgroundColor, color: textColor, ), ); @@ -107,7 +106,7 @@ class OpenFlutterButton extends StatelessWidget { child: Icon( icon, size: iconSize, - color: theme.textTheme.button.color, + color: theme.textTheme.button?.color, ), ); } diff --git a/lib/presentation/widgets/independent/custom_checkbox.dart b/lib/presentation/widgets/independent/custom_checkbox.dart index cb050e3c..59425879 100644 --- a/lib/presentation/widgets/independent/custom_checkbox.dart +++ b/lib/presentation/widgets/independent/custom_checkbox.dart @@ -14,13 +14,12 @@ class OpenFlutterCheckbox extends StatelessWidget { final mainAxisAlignment; const OpenFlutterCheckbox({ - Key key, - this.width, - @required this.title, - this.checked, - this.onTap, + required this.width, + required this.title, + required this.checked, + required this.onTap, this.mainAxisAlignment = MainAxisAlignment.start, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -36,12 +35,12 @@ class OpenFlutterCheckbox extends StatelessWidget { activeColor: _theme.primaryColor, checkColor: _theme.backgroundColor, value: checked, - onChanged: ((bool newValue) => {onTap(newValue)})), + onChanged: ((bool? newValue) => {onTap(newValue!)})), Container( width: width - rightLinkWidth, child: Text( title, - style: _theme.textTheme.headline4.copyWith( + style: _theme.textTheme.headline4?.copyWith( fontWeight: FontWeight.bold, color: _theme.primaryColor), ), diff --git a/lib/presentation/widgets/independent/delivery_method.dart b/lib/presentation/widgets/independent/delivery_method.dart index 8b456b39..ccbde6c8 100644 --- a/lib/presentation/widgets/independent/delivery_method.dart +++ b/lib/presentation/widgets/independent/delivery_method.dart @@ -48,7 +48,7 @@ class OpenFlutterDeliveryMethod extends StatelessWidget { width: 61, ), ), - Text(title, style: _theme.textTheme.bodyText2.copyWith(color: _theme.primaryColorLight)) + Text(title, style: _theme.textTheme.bodyText2?.copyWith(color: _theme.primaryColorLight)) ], ), )); diff --git a/lib/presentation/widgets/independent/error_dialog.dart b/lib/presentation/widgets/independent/error_dialog.dart index 7a5bd02b..7ee40a46 100644 --- a/lib/presentation/widgets/independent/error_dialog.dart +++ b/lib/presentation/widgets/independent/error_dialog.dart @@ -5,7 +5,7 @@ import 'package:openflutterecommerce/config/theme.dart'; class ErrorDialog extends StatelessWidget { final String mainText; - const ErrorDialog({Key key, this.mainText}) : super(key: key); + const ErrorDialog({ required this.mainText}) ; @override Widget build(BuildContext context) { @@ -28,7 +28,7 @@ class ErrorDialog extends StatelessWidget { Padding( padding: EdgeInsets.symmetric(horizontal: 16.0), child: Text(mainText, - style: Theme.of(context).textTheme.headline4.copyWith(color: Theme.of(context).errorColor)), + style: Theme.of(context).textTheme.headline4?.copyWith(color: Theme.of(context).errorColor)), ), SizedBox( height: 12.0, diff --git a/lib/presentation/widgets/independent/expansion_tile.dart b/lib/presentation/widgets/independent/expansion_tile.dart index 56d0c068..2c2b5fd2 100644 --- a/lib/presentation/widgets/independent/expansion_tile.dart +++ b/lib/presentation/widgets/independent/expansion_tile.dart @@ -4,10 +4,10 @@ class OpenFlutterExpansionTile extends StatelessWidget { final String title, description; OpenFlutterExpansionTile({ - Key key, - @required this.title, - @required this.description, - }) : super(key: key); + + required this.title, + required this.description, + }) ; @override Widget build(BuildContext context) { diff --git a/lib/presentation/widgets/independent/favourite_button.dart b/lib/presentation/widgets/independent/favourite_button.dart index f577fb56..0b4cc93d 100644 --- a/lib/presentation/widgets/independent/favourite_button.dart +++ b/lib/presentation/widgets/independent/favourite_button.dart @@ -2,18 +2,13 @@ import 'package:flutter/material.dart'; import 'package:openflutterecommerce/config/theme.dart'; class OpenFlutterFavouriteButton extends StatelessWidget { - final bool favourite; - final VoidCallback setFavourite; - final double size; - final double iconSize; + final bool? favourite; + final VoidCallback? setFavourite; + final double? size; + final double? iconSize; OpenFlutterFavouriteButton( - {Key key, - this.size, - this.iconSize, - @required this.favourite, - @required this.setFavourite}) - : super(key: key); + {this.size, this.iconSize, this.favourite, this.setFavourite}); @override Widget build(BuildContext context) { @@ -30,7 +25,7 @@ class OpenFlutterFavouriteButton extends StatelessWidget { ), height: size ?? 50, width: size ?? 50, - child: favourite + child: favourite! ? Icon(Icons.favorite, size: iconSize ?? 20, color: _theme.accentColor) : Icon(Icons.favorite_border, diff --git a/lib/presentation/widgets/independent/input_button.dart b/lib/presentation/widgets/independent/input_button.dart index 425e8be5..14aeff22 100644 --- a/lib/presentation/widgets/independent/input_button.dart +++ b/lib/presentation/widgets/independent/input_button.dart @@ -8,8 +8,8 @@ class OpenFlutterInputButton extends StatelessWidget { final TextEditingController controller; const OpenFlutterInputButton( - {Key key, @required this.placeHolder, @required this.onClick, @required this.width, @required this.controller}) - : super(key: key); + { required this.placeHolder, required this.onClick, required this.width, required this.controller}) + ; @override Widget build(BuildContext context) { @@ -35,7 +35,7 @@ class OpenFlutterInputButton extends StatelessWidget { width: width - 40, child: TextField( controller: controller, - style: _theme.textTheme.headline2.copyWith(color: _theme.primaryColorLight), + style: _theme.textTheme.headline2?.copyWith(color: _theme.primaryColorLight), decoration: InputDecoration( border: InputBorder.none, hintText: placeHolder, diff --git a/lib/presentation/widgets/independent/input_field.dart b/lib/presentation/widgets/independent/input_field.dart index 36b4bfaf..82701d00 100644 --- a/lib/presentation/widgets/independent/input_field.dart +++ b/lib/presentation/widgets/independent/input_field.dart @@ -4,19 +4,19 @@ import 'package:openflutterecommerce/config/theme.dart'; class OpenFlutterInputField extends StatefulWidget { final TextEditingController controller; final String hint; - final FormFieldValidator validator; + final FormFieldValidator? validator; final TextInputType keyboard; - final FocusNode focusNode; - final VoidCallback onFinished; + final FocusNode? focusNode; + final VoidCallback? onFinished; final bool isPassword; final double horizontalPadding; - final Function onValueChanged; - final String error; + final Function? onValueChanged; + final String? error; const OpenFlutterInputField( - {Key key, - @required this.controller, - this.hint, + {Key? key, + required this.controller, + required this.hint, this.validator, this.keyboard = TextInputType.text, this.focusNode, @@ -34,12 +34,12 @@ class OpenFlutterInputField extends StatefulWidget { } class OpenFlutterInputFieldState extends State { - String error; + late String error; bool isChecked = false; @override Widget build(BuildContext context) { - error = widget.error; + error = widget.error!; return Padding( padding: EdgeInsets.symmetric(horizontal: widget.horizontalPadding), @@ -62,7 +62,7 @@ class OpenFlutterInputFieldState extends State { child: Padding( padding: EdgeInsets.only(left: 16.0), child: TextField( - onChanged: (value) => widget.onValueChanged(value), + onChanged: (value) => widget.onValueChanged!(value), style: TextStyle( color: AppColors.black, fontWeight: FontWeight.normal, @@ -80,7 +80,9 @@ class OpenFlutterInputFieldState extends State { Icons.close, color: AppColors.red, ) - : isChecked ? Icon(Icons.done) : null, + : isChecked + ? Icon(Icons.done) + : null, hintStyle: TextStyle( color: AppColors.lightGray, fontSize: 16, @@ -101,7 +103,7 @@ class OpenFlutterInputFieldState extends State { String validate() { setState(() { - error = widget.validator(widget.controller.text); + error = widget.validator!(widget.controller.text)!; }); return error; } diff --git a/lib/presentation/widgets/independent/label_right_checkbox.dart b/lib/presentation/widgets/independent/label_right_checkbox.dart index b617cd2a..ba1302f2 100644 --- a/lib/presentation/widgets/independent/label_right_checkbox.dart +++ b/lib/presentation/widgets/independent/label_right_checkbox.dart @@ -7,15 +7,15 @@ class OpenFlutterLabelRightCheckbox extends StatefulWidget { final Function(bool) onChanged; final double width; - const OpenFlutterLabelRightCheckbox({Key key, this.checked, this.title, this.onChanged, this.width}) - : super(key: key); + const OpenFlutterLabelRightCheckbox({ required this.checked, required this.title, required this.onChanged, required this.width}) + ; @override _OpenFlutterLabelRightCheckboxState createState() => _OpenFlutterLabelRightCheckboxState(); } class _OpenFlutterLabelRightCheckboxState extends State { - bool _checked; + late bool _checked; @override void initState() { @@ -35,14 +35,14 @@ class _OpenFlutterLabelRightCheckboxState extends State photos; + final List? photos; final double photoSize; final double rating; final int starCount; - final Function onHelpfulTapped; + final Function()? onHelpfulTapped; final bool isHelpfulMarked; final double helpfulIconSize; final double helpfulFontSize; const OpenFlutterProductReviewItem({ - Key key, + this.avatarUrl = '', this.avatarSize = 40.0, this.writerName = '', @@ -40,7 +40,7 @@ class OpenFlutterProductReviewItem extends StatelessWidget { this.isHelpfulMarked = false, this.helpfulIconSize = 14.0, this.helpfulFontSize = 12.0, - }) : super(key: key); + }) ; @override Widget build(BuildContext context) { @@ -49,7 +49,6 @@ class OpenFlutterProductReviewItem extends StatelessWidget { width: double.infinity, child: Stack( fit: StackFit.loose, - overflow: Overflow.visible, children: [ Padding( padding: EdgeInsets.only( @@ -127,7 +126,7 @@ class OpenFlutterProductReviewItem extends StatelessWidget { Expanded( child: Text( reviewDateTime, - style: Theme.of(context).textTheme.caption.copyWith( + style: Theme.of(context).textTheme.caption?.copyWith( fontSize: 12, ), textAlign: TextAlign.end, @@ -142,7 +141,7 @@ class OpenFlutterProductReviewItem extends StatelessWidget { width: double.infinity, child: Text( comment, - style: Theme.of(context).textTheme.bodyText2.copyWith( + style: Theme.of(context).textTheme.bodyText2?.copyWith( fontSize: 14.0, ), textAlign: TextAlign.start, @@ -151,7 +150,7 @@ class OpenFlutterProductReviewItem extends StatelessWidget { } Widget _buildPhotos(BuildContext context) { - if (withPhotos && photos != null && photos.isNotEmpty) { + if (withPhotos && photos != null && photos?.isNotEmpty == true) { return Padding( padding: const EdgeInsets.only( top: 8.0, @@ -170,7 +169,7 @@ class OpenFlutterProductReviewItem extends StatelessWidget { } List _buildPhotosItems() { - var list = List.generate(photos.length, (index) => _buildPhotoItem(photos[index])); + var list = List.generate(photos!.length, (index) => _buildPhotoItem(photos![index])); return list; } @@ -185,12 +184,12 @@ class OpenFlutterProductReviewItem extends StatelessWidget { child: Image.network( photoUrl, fit: BoxFit.fill, - loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent loadingProgress) { + loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) { if (loadingProgress == null) return child; return Center( child: CircularProgressIndicator( value: loadingProgress.expectedTotalBytes != null - ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes + ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!.toInt() : null, ), ); @@ -202,7 +201,7 @@ class OpenFlutterProductReviewItem extends StatelessWidget { Widget _buildIsHelpful(BuildContext context) { return GestureDetector( - onTap: onHelpfulTapped, + onTap: onHelpfulTapped!, child: ConstrainedBox( constraints: BoxConstraints( minHeight: 32.0, @@ -215,7 +214,7 @@ class OpenFlutterProductReviewItem extends StatelessWidget { child: Text( 'Helpful', textAlign: TextAlign.end, - style: Theme.of(context).textTheme.caption.copyWith( + style: Theme.of(context).textTheme.caption?.copyWith( color: _getHelpfulColor(context), fontSize: helpfulFontSize, ), diff --git a/lib/presentation/widgets/independent/right_arrow_action.dart b/lib/presentation/widgets/independent/right_arrow_action.dart index cbb7ca27..66347ddb 100644 --- a/lib/presentation/widgets/independent/right_arrow_action.dart +++ b/lib/presentation/widgets/independent/right_arrow_action.dart @@ -5,8 +5,7 @@ class OpenFlutterRightArrow extends StatelessWidget { final String text; final VoidCallback onClick; - const OpenFlutterRightArrow(this.text, {Key key, this.onClick}) - : super(key: key); + const OpenFlutterRightArrow(this.text, {required this.onClick}); @override Widget build(BuildContext context) { diff --git a/lib/presentation/widgets/independent/scaffold.dart b/lib/presentation/widgets/independent/scaffold.dart index ac4dc255..61a0221a 100644 --- a/lib/presentation/widgets/independent/scaffold.dart +++ b/lib/presentation/widgets/independent/scaffold.dart @@ -7,33 +7,31 @@ import 'package:flutter/material.dart'; import '../widgets.dart'; class OpenFlutterScaffold extends StatelessWidget { - final Color background; + final Color? background; final String title; final Widget body; final int bottomMenuIndex; - final List tabBarList; - final TabController tabController; + final List? tabBarList; + final TabController? tabController; const OpenFlutterScaffold( - {Key key, - this.background, - @required this.title, - @required this.body, - @required this.bottomMenuIndex, + {this.background, + required this.title, + required this.body, + required this.bottomMenuIndex, this.tabBarList, - this.tabController}) - : super(key: key); + this.tabController}); @override Widget build(BuildContext context) { var tabBars = []; var _theme = Theme.of(context); if (tabBarList != null) { - for (var i = 0; i < tabBarList.length; i++) { - tabBars.add(Tab(key: UniqueKey(), text: tabBarList[i])); + for (var i = 0; i < tabBarList!.length; i++) { + tabBars.add(Tab(key: UniqueKey(), text: tabBarList![i])); } } - Widget tabWidget = tabBars.isNotEmpty + PreferredSizeWidget tabWidget = tabBars.isNotEmpty == true ? TabBar( unselectedLabelColor: _theme.primaryColor, unselectedLabelStyle: TextStyle(fontWeight: FontWeight.normal), @@ -43,7 +41,9 @@ class OpenFlutterScaffold extends StatelessWidget { controller: tabController, indicatorColor: _theme.accentColor, indicatorSize: TabBarIndicatorSize.tab) - : null; + : TabBar( + tabs: [], + ); return Scaffold( backgroundColor: background, appBar: title != null diff --git a/lib/presentation/widgets/independent/scaffold_collapsing.dart b/lib/presentation/widgets/independent/scaffold_collapsing.dart index 6c7aa32a..737711e2 100644 --- a/lib/presentation/widgets/independent/scaffold_collapsing.dart +++ b/lib/presentation/widgets/independent/scaffold_collapsing.dart @@ -8,7 +8,7 @@ import 'package:openflutterecommerce/config/theme.dart'; import 'bottom_menu.dart'; class OpenFlutterCollapsingScaffold extends StatelessWidget { - final Color background; + final Color? background; final String title; final Widget body; final int bottomMenuIndex; @@ -16,8 +16,8 @@ class OpenFlutterCollapsingScaffold extends StatelessWidget { final TabController tabController; const OpenFlutterCollapsingScaffold( - {Key key, this.background, this.title, this.body, this.bottomMenuIndex, this.tabBarList, this.tabController}) - : super(key: key); + { this.background, required this.title, required this.body, required this.bottomMenuIndex, required this.tabBarList, required this.tabController}) + ; @override Widget build(BuildContext context) { @@ -29,7 +29,7 @@ class OpenFlutterCollapsingScaffold extends StatelessWidget { ? (BuildContext context, bool innerBoxIsScrolled) { return _buildSilverAppBar(context); } - : null, + : null!, body: body, ), backgroundColor: background, @@ -46,7 +46,7 @@ class OpenFlutterCollapsingScaffold extends StatelessWidget { } } - Widget tabWidget = tabBars.isNotEmpty + PreferredSizeWidget tabWidget = tabBars.isNotEmpty ? TabBar( unselectedLabelColor: _theme.primaryColor, unselectedLabelStyle: TextStyle(fontWeight: FontWeight.normal), @@ -56,7 +56,7 @@ class OpenFlutterCollapsingScaffold extends StatelessWidget { controller: tabController, indicatorColor: _theme.accentColor, indicatorSize: TabBarIndicatorSize.tab) - : null; + : TabBar(tabs: [],); return [ SliverAppBar( diff --git a/lib/presentation/widgets/independent/search_bar.dart b/lib/presentation/widgets/independent/search_bar.dart index 0a196794..04568ae9 100644 --- a/lib/presentation/widgets/independent/search_bar.dart +++ b/lib/presentation/widgets/independent/search_bar.dart @@ -5,14 +5,14 @@ class OpenFlutterSearchBar extends StatefulWidget { final String searchKey; final Function(String) onChange; - const OpenFlutterSearchBar({Key key, this.searchKey, this.onChange}) : super(key: key); + const OpenFlutterSearchBar({ required this.searchKey, required this.onChange}) ; @override _OpenFlutterSearchBarState createState() => _OpenFlutterSearchBarState(); } class _OpenFlutterSearchBarState extends State { - TextEditingController _searchKeyController; + late TextEditingController _searchKeyController; @override Widget build(BuildContext context) { @@ -36,7 +36,7 @@ class _OpenFlutterSearchBarState extends State { width: width - 90, child: TextField( controller: _searchKeyController, - style: _theme.textTheme.headline2.copyWith(color: _theme.primaryColorLight), + style: _theme.textTheme.headline2?.copyWith(color: _theme.primaryColorLight), decoration: InputDecoration( border: InputBorder.none, ))) diff --git a/lib/presentation/widgets/independent/service_button.dart b/lib/presentation/widgets/independent/service_button.dart index 880f37bc..e82bb00c 100644 --- a/lib/presentation/widgets/independent/service_button.dart +++ b/lib/presentation/widgets/independent/service_button.dart @@ -6,8 +6,8 @@ class OpenFlutterServiceButton extends StatelessWidget { final VoidCallback onPressed; const OpenFlutterServiceButton( - {Key key, this.serviceType = ServiceType.Google, this.onPressed}) - : super(key: key); + { this.serviceType = ServiceType.Google, required this.onPressed}) + ; @override Widget build(BuildContext context) { diff --git a/lib/presentation/widgets/independent/sortby.dart b/lib/presentation/widgets/independent/sortby.dart index bf3a38f4..872c2a76 100644 --- a/lib/presentation/widgets/independent/sortby.dart +++ b/lib/presentation/widgets/independent/sortby.dart @@ -8,8 +8,8 @@ class OpenFlutterSortBy extends StatelessWidget { final Function(SortRules) onSelect; final SortRules currentSortBy; - const OpenFlutterSortBy({Key key, this.onSelect, this.currentSortBy}) - : super(key: key); + const OpenFlutterSortBy( + {required this.onSelect, required this.currentSortBy}); @override Widget build(BuildContext context) { @@ -30,8 +30,8 @@ class OpenFlutterSortBy extends StatelessWidget { title: rule.getSortTitle(), sortRules: rule, backgroundColor: - rule == currentSortBy ? _theme.accentColor : null, - textColor: rule == currentSortBy ? AppColors.white : null, + rule == currentSortBy ? _theme.accentColor : _theme.accentColor, + textColor: rule == currentSortBy ? AppColors.white : AppColors.white, onTap: ((rule) => {onSelect(rule)}), )) .toList(growable: false); diff --git a/lib/presentation/widgets/independent/summary_line.dart b/lib/presentation/widgets/independent/summary_line.dart index eb476e74..8208e70a 100644 --- a/lib/presentation/widgets/independent/summary_line.dart +++ b/lib/presentation/widgets/independent/summary_line.dart @@ -5,7 +5,7 @@ class OpenFlutterSummaryLine extends StatelessWidget { final String title; final String summary; - const OpenFlutterSummaryLine({Key key, this.title, this.summary}) : super(key: key); + const OpenFlutterSummaryLine({ required this.title, required this.summary}) ; @override Widget build(BuildContext context) { @@ -21,7 +21,7 @@ class OpenFlutterSummaryLine extends StatelessWidget { width: width / 2, child: Text(summary, style: - _theme.textTheme.headline2.copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor))), + _theme.textTheme.headline2?.copyWith(fontWeight: FontWeight.bold, color: _theme.primaryColor))), ], )); } diff --git a/lib/presentation/widgets/independent/text_tile.dart b/lib/presentation/widgets/independent/text_tile.dart index b07b160a..6ea9d90c 100644 --- a/lib/presentation/widgets/independent/text_tile.dart +++ b/lib/presentation/widgets/independent/text_tile.dart @@ -6,7 +6,7 @@ class OpenFlutterTextTile extends StatelessWidget { final String subtitle; final Function onClick; - const OpenFlutterTextTile({Key key, this.title, this.subtitle, this.onClick}) : super(key: key); + const OpenFlutterTextTile({ required this.title, required this.subtitle, required this.onClick}) ; @override Widget build(BuildContext context) { diff --git a/lib/presentation/widgets/independent/view_options.dart b/lib/presentation/widgets/independent/view_options.dart index fee9d212..c6c0730b 100644 --- a/lib/presentation/widgets/independent/view_options.dart +++ b/lib/presentation/widgets/independent/view_options.dart @@ -15,17 +15,16 @@ class OpenFlutterViewOptions extends StatelessWidget { final bool isListView; final Function(FilterRules) onFilterChanged; final Function(SortRules) onSortChanged; - final Function onChangeViewClicked; + final Function()? onChangeViewClicked; const OpenFlutterViewOptions( - {Key key, - @required this.onFilterChanged, - @required this.onSortChanged, - @required this.onChangeViewClicked, - @required this.sortRules, - @required this.filterRules, - this.isListView = true}) - : super(key: key); + { + required this.onFilterChanged, + required this.onSortChanged, + required this.onChangeViewClicked, + required this.sortRules, + required this.filterRules, + this.isListView = true}); @override Widget build(BuildContext context) { @@ -113,7 +112,7 @@ class OpenFlutterViewOptions extends StatelessWidget { Expanded( child: InkWell( child: Text(value, - style: Theme.of(context).textTheme.headline4.copyWith( + style: Theme.of(context).textTheme.headline4?.copyWith( fontWeight: FontWeight.normal, color: sortRules.sortType == key ? AppColors.white : AppColors.black)), onTap: () { diff --git a/pubspec.yaml b/pubspec.yaml index c601cc3b..a867ecbf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ description: A Flutter E-commerce App. version: 0.0.2+2 environment: - sdk: ">=2.6.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: