| ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ||||
| CLANG_ENABLE_MODULES = YES; | CLANG_ENABLE_MODULES = YES; | ||||
| CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; | CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; | ||||
| CURRENT_PROJECT_VERSION = 1; | |||||
| CURRENT_PROJECT_VERSION = 2; | |||||
| DEVELOPMENT_TEAM = C3DTD2JH94; | DEVELOPMENT_TEAM = C3DTD2JH94; | ||||
| ENABLE_BITCODE = NO; | ENABLE_BITCODE = NO; | ||||
| FRAMEWORK_SEARCH_PATHS = ( | FRAMEWORK_SEARCH_PATHS = ( | ||||
| ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ||||
| CLANG_ENABLE_MODULES = YES; | CLANG_ENABLE_MODULES = YES; | ||||
| CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; | CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; | ||||
| CURRENT_PROJECT_VERSION = 1; | |||||
| CURRENT_PROJECT_VERSION = 2; | |||||
| DEVELOPMENT_TEAM = C3DTD2JH94; | DEVELOPMENT_TEAM = C3DTD2JH94; | ||||
| ENABLE_BITCODE = NO; | ENABLE_BITCODE = NO; | ||||
| FRAMEWORK_SEARCH_PATHS = ( | FRAMEWORK_SEARCH_PATHS = ( | ||||
| ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ||||
| CLANG_ENABLE_MODULES = YES; | CLANG_ENABLE_MODULES = YES; | ||||
| CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; | CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; | ||||
| CURRENT_PROJECT_VERSION = 1; | |||||
| CURRENT_PROJECT_VERSION = 2; | |||||
| DEVELOPMENT_TEAM = C3DTD2JH94; | DEVELOPMENT_TEAM = C3DTD2JH94; | ||||
| ENABLE_BITCODE = NO; | ENABLE_BITCODE = NO; | ||||
| FRAMEWORK_SEARCH_PATHS = ( | FRAMEWORK_SEARCH_PATHS = ( |
| var token = await pref.getString(DATA_CONST.TOKEN_KEY); | var token = await pref.getString(DATA_CONST.TOKEN_KEY); | ||||
| options.headers["Authorization"] = "Bearer $token"; | options.headers["Authorization"] = "Bearer $token"; | ||||
| options.receiveTimeout = 20000; | options.receiveTimeout = 20000; | ||||
| // log("onRequest: ${options.uri}\n" | |||||
| // "data=${options.data}\n" | |||||
| // "method=${options.method}\n" | |||||
| // "headers=${options.headers}\n" | |||||
| // "queryParameters=${options.queryParameters}"); | |||||
| log("onRequest: ${options.uri}\n" | |||||
| "data=${options.data}\n" | |||||
| "method=${options.method}\n" | |||||
| "headers=${options.headers}\n" | |||||
| "queryParameters=${options.queryParameters}"); | |||||
| return options; | return options; | ||||
| } | } | ||||
| @PUT("/api/notifications/update") | @PUT("/api/notifications/update") | ||||
| Future<void> updateNoti(@Body() UpdateNoti updateNoti); | Future<void> updateNoti(@Body() UpdateNoti updateNoti); | ||||
| @GET("/api/tb-countries?page={page}&size={size}&&sort=name,ASC") | |||||
| @GET("/api/tb-countries?page={page}&size={size}&query={query}&&sort=name,ASC") | |||||
| Future<List<LocationUnit>> getCountries( | Future<List<LocationUnit>> getCountries( | ||||
| {@Path() int page = 0, | {@Path() int page = 0, | ||||
| @Path() int size = 400, | @Path() int size = 400, | ||||
| @Path() String query = '', | |||||
| @DioOptions() Options options}); | @DioOptions() Options options}); | ||||
| @GET( | @GET( | ||||
| "/api/tb-cities-by-country/{countryId}?page={page}&size={size}&&sort=name,ASC") | |||||
| "/api/tb-cities-by-country/{countryId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||||
| Future<List<LocationUnit>> getProvinces(@Path() int countryId, | Future<List<LocationUnit>> getProvinces(@Path() int countryId, | ||||
| {@Path() int page = 0, | {@Path() int page = 0, | ||||
| @Path() int size = 20, | @Path() int size = 20, | ||||
| @Path() String query = '', | |||||
| @DioOptions() Options options}); | @DioOptions() Options options}); | ||||
| @GET( | @GET( | ||||
| "/api/tb-districts-by-city/{provinceId}?page={page}&size={size}&&sort=name,ASC") | |||||
| "/api/tb-districts-by-city/{provinceId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||||
| Future<List<LocationUnit>> getDistricts(@Path() int provinceId, | Future<List<LocationUnit>> getDistricts(@Path() int provinceId, | ||||
| {@Path() int page = 0, | {@Path() int page = 0, | ||||
| @Path() int size = 20, | @Path() int size = 20, | ||||
| @Path() String query = '', | |||||
| @DioOptions() Options options}); | @DioOptions() Options options}); | ||||
| @GET( | @GET( | ||||
| "/api/tb-wards-by-district/{districtId}?page={page}&size={size}&&sort=name,ASC") | |||||
| "/api/tb-wards-by-district/{districtId}?page={page}&size={size}&query={query}&&sort=name,ASC") | |||||
| Future<List<LocationUnit>> getWards(@Path() int districtId, | Future<List<LocationUnit>> getWards(@Path() int districtId, | ||||
| {@Path() int page = 0, | {@Path() int page = 0, | ||||
| @Path() int size = 20, | @Path() int size = 20, | ||||
| @Path() String query = '', | |||||
| @DioOptions() Options options}); | @DioOptions() Options options}); | ||||
| //Crop | //Crop |
| } | } | ||||
| @override | @override | ||||
| getCountries({page = 0, size = 400, options}) async { | |||||
| getCountries({page = 0, size = 400, query = '', options}) async { | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| '/api/tb-countries?page=$page&size=$size&&sort=name,ASC', | |||||
| '/api/tb-countries?page=$page&size=$size&query=$query&&sort=name,ASC', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | ||||
| data: _data); | data: _data); | ||||
| } | } | ||||
| @override | @override | ||||
| getProvinces(countryId, {page = 0, size = 20, options}) async { | |||||
| getProvinces(countryId, {page = 0, size = 20, query = '', options}) async { | |||||
| ArgumentError.checkNotNull(countryId, 'countryId'); | ArgumentError.checkNotNull(countryId, 'countryId'); | ||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| '/api/tb-cities-by-country/$countryId?page=$page&size=$size&&sort=name,ASC', | |||||
| '/api/tb-cities-by-country/$countryId?page=$page&size=$size&query=$query&&sort=name,ASC', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | ||||
| data: _data); | data: _data); | ||||
| } | } | ||||
| @override | @override | ||||
| getDistricts(provinceId, {page = 0, size = 20, options}) async { | |||||
| getDistricts(provinceId, {page = 0, size = 20, query = '', options}) async { | |||||
| ArgumentError.checkNotNull(provinceId, 'provinceId'); | ArgumentError.checkNotNull(provinceId, 'provinceId'); | ||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| '/api/tb-districts-by-city/$provinceId?page=$page&size=$size&&sort=name,ASC', | |||||
| '/api/tb-districts-by-city/$provinceId?page=$page&size=$size&query=$query&&sort=name,ASC', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | ||||
| data: _data); | data: _data); | ||||
| } | } | ||||
| @override | @override | ||||
| getWards(districtId, {page = 0, size = 20, options}) async { | |||||
| getWards(districtId, {page = 0, size = 20, query = '', options}) async { | |||||
| ArgumentError.checkNotNull(districtId, 'districtId'); | ArgumentError.checkNotNull(districtId, 'districtId'); | ||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| '/api/tb-wards-by-district/$districtId?page=$page&size=$size&&sort=name,ASC', | |||||
| '/api/tb-wards-by-district/$districtId?page=$page&size=$size&query=$query&&sort=name,ASC', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | ||||
| data: _data); | data: _data); |
| {@required LocationType locationType, | {@required LocationType locationType, | ||||
| int filterId, | int filterId, | ||||
| int page = 0, | int page = 0, | ||||
| int size = 500}) { | |||||
| int size = 500, | |||||
| String query = ''}) { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var op = buildConfigurableCacheOptions( | var op = buildConfigurableCacheOptions( | ||||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | ||||
| var response; | var response; | ||||
| switch (locationType) { | switch (locationType) { | ||||
| case LocationType.province: | case LocationType.province: | ||||
| response = | |||||
| client.getProvinces(filterId, options: op, page: page, size: size); | |||||
| response = client.getProvinces(filterId, | |||||
| options: op, page: page, size: size, query: query); | |||||
| break; | break; | ||||
| case LocationType.district: | case LocationType.district: | ||||
| response = | |||||
| client.getDistricts(filterId, options: op, page: page, size: size); | |||||
| response = client.getDistricts(filterId, | |||||
| options: op, page: page, size: size, query: query); | |||||
| break; | break; | ||||
| case LocationType.ward: | case LocationType.ward: | ||||
| response = | |||||
| client.getWards(filterId, options: op, page: page, size: size); | |||||
| response = client.getWards(filterId, | |||||
| options: op, page: page, size: size, query: query); | |||||
| break; | break; | ||||
| default: | default: | ||||
| response = client.getCountries(); | |||||
| response = client.getCountries(query: query); | |||||
| } | } | ||||
| return response; | return response; | ||||
| } | } |
| } else if (event is OnSearch) { | } else if (event is OnSearch) { | ||||
| try { | try { | ||||
| final response = await repository.getLocationUnits( | final response = await repository.getLocationUnits( | ||||
| locationType: event.locationType, filterId: event.filterId); | |||||
| bool query(LocationUnit locationUnit) => | |||||
| event.searchString.isEmpty || | |||||
| locationUnit.name | |||||
| .toLowerCase() | |||||
| .contains(event.searchString.toLowerCase()); | |||||
| final result = response.where(query).toList(); | |||||
| List<LocationUnit> locations = result.map((location) { | |||||
| locationType: event.locationType, | |||||
| filterId: event.filterId, | |||||
| query: event.searchString); | |||||
| List<LocationUnit> locations = response.map((location) { | |||||
| if (location.id == event.selectedId) { | if (location.id == event.selectedId) { | ||||
| location.isSelected = true; | location.isSelected = true; | ||||
| } | } |
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return BlocProvider( | return BlocProvider( | ||||
| create: (context) => LocationBloc(repository: Repository()) | |||||
| ..add(DataFetched( | |||||
| locationType: widget.type, | |||||
| selectedId: widget.selectedId, | |||||
| filterId: widget.filterId, | |||||
| )), | |||||
| create: (context) => LocationBloc(repository: Repository()), | |||||
| child: HoldInfinityWidget( | child: HoldInfinityWidget( | ||||
| type: widget.type, | type: widget.type, | ||||
| selectedId: widget.selectedId, | selectedId: widget.selectedId, |