Browse Source

fix search location

master
daivph 5 years ago
parent
commit
703c79246c
7 changed files with 38 additions and 42 deletions
  1. +3
    -3
      ios/Runner.xcodeproj/project.pbxproj
  2. +5
    -5
      lib/data/api/dio_provider.dart
  3. +8
    -4
      lib/data/api/rest_client.dart
  4. +8
    -8
      lib/data/api/rest_client.g.dart
  5. +9
    -8
      lib/data/repository/repository.dart
  6. +4
    -8
      lib/presentation/screens/location_unit/bloc/location_bloc.dart
  7. +1
    -6
      lib/presentation/screens/location_unit/sc_location.dart

+ 3
- 3
ios/Runner.xcodeproj/project.pbxproj View File

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 = (

+ 5
- 5
lib/data/api/dio_provider.dart View File

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;
} }



+ 8
- 4
lib/data/api/rest_client.dart View File

@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

+ 8
- 8
lib/data/api/rest_client.g.dart View File

} }


@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);

+ 9
- 8
lib/data/repository/repository.dart View File

{@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;
} }

+ 4
- 8
lib/presentation/screens/location_unit/bloc/location_bloc.dart View File

} 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;
} }

+ 1
- 6
lib/presentation/screens/location_unit/sc_location.dart View File

@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,

Loading…
Cancel
Save