Skip to content

Commit

Permalink
Fix search place
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushik committed Jul 1, 2024
1 parent 72efb47 commit fa524b9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 35 deletions.
67 changes: 36 additions & 31 deletions app/lib/ui/flow/geofence/add/addnew/add_new_place_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,39 +146,44 @@ class _AddNewPlaceViewState extends ConsumerState<AddNewPlaceView> {
Widget _placesItemView(ApiNearbyPlace place, bool isLast) {
return Column(
children: [
Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.only(top: 2),
child: Icon(
Icons.location_on_outlined,
size: 24,
color: context.colorScheme.textPrimary,
),
),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
place.name,
maxLines: 1,
style: AppTextStyle.subtitle2.copyWith(
color: context.colorScheme.textPrimary,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.only(top: 2),
child: SvgPicture.asset(
Assets.images.icLocation,
colorFilter: ColorFilter.mode(
context.colorScheme.textPrimary,
BlendMode.srcATop,
),
const SizedBox(height: 4),
Text(
place.formatted_address,
style: AppTextStyle.caption
.copyWith(color: context.colorScheme.textSecondary),
maxLines: 2,
overflow: TextOverflow.ellipsis,
)
],
),
),
)
]),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
place.name,
maxLines: 1,
style: AppTextStyle.subtitle2.copyWith(
color: context.colorScheme.textPrimary,
),
),
const SizedBox(height: 4),
Text(
place.formatted_address,
style: AppTextStyle.caption
.copyWith(color: context.colorScheme.textSecondary),
maxLines: 2,
overflow: TextOverflow.ellipsis,
)
],
),
)
]),
),
Visibility(
visible: !isLast,
child: Padding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class AddNewPlaceViewNotifier extends StateNotifier<AddNewPlaceState> {
value,
'', // put user latitude coordinates here.
'', // put user longitude coordinates here.
'AIzaSyDbaJSVGU4Jkhd_V_e9esorzh_8yykh160',
);

state = state.copyWith(places: places, loading: false);
Expand Down
2 changes: 2 additions & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ migrate_working_dir/
#.vscode/

# Flutter/Dart/Pub related
**/config.dart

# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
Expand Down
4 changes: 4 additions & 0 deletions data/lib/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class AppConfig {
static const String placeBaseUrl = 'https://maps.googleapis.com/maps/api/place/textsearch/json';
static const String mapApiKey = 'AIzaSyDbaJSVGU4Jkhd_V_e9esorzh_8yykh160';
}
5 changes: 2 additions & 3 deletions data/lib/service/place_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart' as http;

import '../api/network/client.dart';
import '../config.dart';

const baseUrl = 'https://maps.googleapis.com/maps/api/place/textsearch/json';
const defaultRadius = 1500;

final placeServiceProvider = Provider(
Expand Down Expand Up @@ -86,11 +86,10 @@ class PlaceService {
String query,
String? lat,
String? lng,
String apiKey,
) async {
final placeRadius = (lat != null && lng != null) ? defaultRadius : '';
final String url =
'$baseUrl?query=$query&location=$lat,$lng&radius=$placeRadius&key=$apiKey';
'${AppConfig.placeBaseUrl}?query=$query&location=$lat,$lng&radius=$placeRadius&key=${AppConfig.mapApiKey}';

final response = await http.get(Uri.parse(url));

Expand Down

0 comments on commit fa524b9

Please sign in to comment.