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

@@ -374,7 +374,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = C3DTD2JH94;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
@@ -516,7 +516,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = C3DTD2JH94;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
@@ -550,7 +550,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = C3DTD2JH94;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (

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

@@ -26,11 +26,11 @@ class HttpLogInterceptor extends InterceptorsWrapper {
var token = await pref.getString(DATA_CONST.TOKEN_KEY);
options.headers["Authorization"] = "Bearer $token";
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;
}


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

@@ -74,31 +74,35 @@ abstract class RestClient {
@PUT("/api/notifications/update")
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(
{@Path() int page = 0,
@Path() int size = 400,
@Path() String query = '',
@DioOptions() Options options});

@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,
{@Path() int page = 0,
@Path() int size = 20,
@Path() String query = '',
@DioOptions() Options options});

@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,
{@Path() int page = 0,
@Path() int size = 20,
@Path() String query = '',
@DioOptions() Options options});

@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,
{@Path() int page = 0,
@Path() int size = 20,
@Path() String query = '',
@DioOptions() Options options});

//Crop

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

@@ -319,7 +319,7 @@ class _RestClient implements RestClient {
}

@override
getCountries({page = 0, size = 400, options}) async {
getCountries({page = 0, size = 400, query = '', options}) async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
queryParameters.removeWhere((k, v) => v == null);
@@ -328,7 +328,7 @@ class _RestClient implements RestClient {
newOptions.extra.addAll(_extra);
newOptions.headers.addAll(<String, dynamic>{});
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,
options: newOptions.merge(method: 'GET', baseUrl: baseUrl),
data: _data);
@@ -339,7 +339,7 @@ class _RestClient implements RestClient {
}

@override
getProvinces(countryId, {page = 0, size = 20, options}) async {
getProvinces(countryId, {page = 0, size = 20, query = '', options}) async {
ArgumentError.checkNotNull(countryId, 'countryId');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
@@ -349,7 +349,7 @@ class _RestClient implements RestClient {
newOptions.extra.addAll(_extra);
newOptions.headers.addAll(<String, dynamic>{});
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,
options: newOptions.merge(method: 'GET', baseUrl: baseUrl),
data: _data);
@@ -360,7 +360,7 @@ class _RestClient implements RestClient {
}

@override
getDistricts(provinceId, {page = 0, size = 20, options}) async {
getDistricts(provinceId, {page = 0, size = 20, query = '', options}) async {
ArgumentError.checkNotNull(provinceId, 'provinceId');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
@@ -370,7 +370,7 @@ class _RestClient implements RestClient {
newOptions.extra.addAll(_extra);
newOptions.headers.addAll(<String, dynamic>{});
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,
options: newOptions.merge(method: 'GET', baseUrl: baseUrl),
data: _data);
@@ -381,7 +381,7 @@ class _RestClient implements RestClient {
}

@override
getWards(districtId, {page = 0, size = 20, options}) async {
getWards(districtId, {page = 0, size = 20, query = '', options}) async {
ArgumentError.checkNotNull(districtId, 'districtId');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
@@ -391,7 +391,7 @@ class _RestClient implements RestClient {
newOptions.extra.addAll(_extra);
newOptions.headers.addAll(<String, dynamic>{});
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,
options: newOptions.merge(method: 'GET', baseUrl: baseUrl),
data: _data);

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

@@ -116,26 +116,27 @@ class Repository {
{@required LocationType locationType,
int filterId,
int page = 0,
int size = 500}) {
int size = 500,
String query = ''}) {
final client = RestClient(dio);
var op = buildConfigurableCacheOptions(
forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache));
var response;
switch (locationType) {
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;
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;
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;
default:
response = client.getCountries();
response = client.getCountries(query: query);
}
return response;
}

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

@@ -49,14 +49,10 @@ class LocationBloc extends Bloc<LocationEvent, LocationState> {
} else if (event is OnSearch) {
try {
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) {
location.isSelected = true;
}

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

@@ -29,12 +29,7 @@ class _LocationScreenState extends State<LocationScreen> {
@override
Widget build(BuildContext context) {
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(
type: widget.type,
selectedId: widget.selectedId,

Loading…
Cancel
Save