Skip to content

Commit 8fca0f5

Browse files
author
himanshu goyal
committed
maps screen finish
1 parent 842798d commit 8fca0f5

File tree

16 files changed

+192
-132
lines changed

16 files changed

+192
-132
lines changed

lib/core/queries/auth.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class AuthQueries {
1313
''';
1414
}
1515

16-
String gAuth(String? name, String email) {
16+
String gAuth(String? name, String email, String? imageUrl) {
1717
return '''
1818
mutation{
19-
oAuth(userInput: {email: "$email", name: "$name"})
19+
oAuth(userInput: {email: "$email", name: "$name", imageUrl: "$imageUrl"})
2020
}
2121
''';
2222
}

lib/core/queries/beacon.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ deleteBeacon(id: "$id")
254254
landmarks{
255255
_id
256256
title
257+
icon
257258
location{
258259
lat
259260
lon

lib/data/datasource/remote/remote_auth_api.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class RemoteAuthApi {
8686
}
8787
}
8888

89-
Future<DataState<UserEntity>> gAuth(String name, String email) async {
89+
Future<DataState<UserEntity>> gAuth(String name, String email, String? imageUrl) async {
9090
log('name: $name');
9191
log('email: $email');
9292

@@ -97,7 +97,7 @@ class RemoteAuthApi {
9797
}
9898

9999
final QueryResult result = await clientNonAuth.mutate(
100-
MutationOptions(document: gql(_authQueries.gAuth(name, email))));
100+
MutationOptions(document: gql(_authQueries.gAuth(name, email, imageUrl))));
101101

102102
log(result.toString());
103103

lib/data/datasource/remote/remote_hike_api.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ class RemoteHikeApi {
174174
final result = await _authClient
175175
.mutate(MutationOptions(document: gql(beaconQueries.sos(id))));
176176

177+
print("result sos: ${result.data}");
178+
177179
if (result.isConcrete &&
178180
result.data != null &&
179181
result.data!['sos'] != null) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class LocationSuggestion {
2+
final String name;
3+
final double latitude;
4+
final double longitude;
5+
final String fullAddress;
6+
7+
LocationSuggestion({
8+
required this.name,
9+
required this.latitude,
10+
required this.longitude,
11+
required this.fullAddress,
12+
});
13+
14+
factory LocationSuggestion.fromJson(Map<String, dynamic> json) {
15+
return LocationSuggestion(
16+
name: json['formatted'] ?? json['address_line1'] ?? 'Unknown Location',
17+
latitude: (json['lat'] ?? 0.0).toDouble(),
18+
longitude: (json['lon'] ?? 0.0).toDouble(),
19+
fullAddress: json['formatted'] ?? 'Unknown Address',
20+
);
21+
}
22+
23+
@override
24+
String toString() {
25+
return 'LocationSuggestion(name: $name, lat: $latitude, lon: $longitude)';
26+
}
27+
}

lib/data/repositories/auth_repository_implementation.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class AuthRepositoryImplementation implements AuthRepository {
2020
}
2121

2222
@override
23-
Future<DataState<UserEntity>> oAuth(String name, String email) {
24-
return remoteAuthApi.gAuth(name, email);
23+
Future<DataState<UserEntity>> oAuth(String name, String email, String? imageUrl) {
24+
return remoteAuthApi.gAuth(name, email, imageUrl);
2525
}
2626

2727
@override

lib/domain/repositories/auth_repository.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class AuthRepository {
1212
// Login function
1313
Future<DataState<UserEntity>> login(String email, String password);
1414

15-
Future<DataState<UserEntity>> oAuth(String name, String email);
15+
Future<DataState<UserEntity>> oAuth(String name, String email, String? imageUrl);
1616

1717
Future<DataState<String>> sendVerificationCode();
1818

lib/domain/usecase/auth_usecase.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class AuthUseCase {
1717
return authRepository.login(email, password);
1818
}
1919

20-
Future<DataState<UserEntity>> oAuthUseCase(String name, String email) async {
21-
return authRepository.oAuth(name, email);
20+
Future<DataState<UserEntity>> oAuthUseCase(String name, String email, String? imageUrl) async {
21+
return authRepository.oAuth(name, email, imageUrl);
2222
}
2323

2424
Future<DataState<UserEntity>> getUserInfoUseCase() async {

lib/presentation/auth/auth_cubit/auth_cubit.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ class AuthCubit extends Cubit<AuthState> {
7979
);
8080

8181
final gAuth = await _googleSignIn.signIn();
82+
print("Google Auth: ${gAuth}");
8283

8384
if (gAuth != null && gAuth.displayName != null) {
85+
// pass imageurl
8486
var dataState =
85-
await authUseCase.oAuthUseCase(gAuth.displayName!, gAuth.email);
87+
await authUseCase.oAuthUseCase(gAuth.displayName!, gAuth.email, gAuth.photoUrl);
8688

8789
if (dataState is DataSuccess && dataState.data != null) {
8890
emit(SuccessState());

lib/presentation/hike/cubit/location_cubit/location_cubit.dart

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class LocationCubit extends Cubit<LocationState> {
247247

248248
emit(LoadedLocationState(
249249
geofence: _geofence,
250-
locationMarkers: _hikeMarkers,
250+
locationMarkers: Set<Marker>.from(_hikeMarkers),
251251
polyline: _polyline,
252252
version: DateTime.now().millisecondsSinceEpoch,
253253
mapType: _mapType,
@@ -260,7 +260,7 @@ class LocationCubit extends Cubit<LocationState> {
260260
PolylinePoints polylinePoints = PolylinePoints();
261261
try {
262262
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
263-
'AIzaSyBdIpiEfBE5DohHgBvwPTljZQAcNWcKwCs',
263+
'AIzaSyC72TkXzQTsnbGdZy5ldeX64y0mofn_iUs',
264264
PointLatLng(_points.first.latitude, _points.first.longitude),
265265
PointLatLng(_points.last.longitude, _points.last.longitude));
266266

@@ -363,18 +363,29 @@ class LocationCubit extends Cubit<LocationState> {
363363
if (dataState is DataSuccess && dataState.data != null) {
364364
BeaconLocationsEntity beaconLocationsEntity = dataState.data!;
365365

366+
print(
367+
'Location update subscription: ${beaconLocationsEntity.toString()}');
368+
369+
// when new landmark is created
366370
// when new landmark is created
367371
if (beaconLocationsEntity.landmark != null) {
368372
LandMarkEntity newLandMark = beaconLocationsEntity.landmark!;
369373

370-
// await _createLandMarkMarker(newLandMark);
374+
print('Creating landmark marker for: ${newLandMark.title}');
375+
print('Markers before: ${_hikeMarkers.length}');
376+
377+
await _createLandMarkMarker(newLandMark);
378+
379+
print('Markers after: ${_hikeMarkers.length}');
371380

372381
emit(LoadedLocationState(
373382
polyline: _polyline,
374-
locationMarkers: _hikeMarkers,
383+
locationMarkers:
384+
Set<Marker>.from(_hikeMarkers), // Create new Set instance
375385
mapType: _mapType,
376386
geofence: _geofence,
377-
version: DateTime.now().millisecond,
387+
version: DateTime.now()
388+
.millisecondsSinceEpoch, // Use millisecondsSinceEpoch
378389
message:
379390
'A landmark is created by ${beaconLocationsEntity.landmark!.createdBy!.name ?? 'Anonymous'}'));
380391
}
@@ -388,9 +399,9 @@ class LocationCubit extends Cubit<LocationState> {
388399
emit(LoadedLocationState(
389400
polyline: _polyline,
390401
geofence: _geofence,
391-
locationMarkers: _hikeMarkers,
402+
locationMarkers: Set<Marker>.from(_hikeMarkers),
392403
mapType: _mapType,
393-
version: DateTime.now().microsecond));
404+
version: DateTime.now().millisecondsSinceEpoch));
394405
// add marker for user
395406
}
396407

@@ -460,10 +471,10 @@ class LocationCubit extends Cubit<LocationState> {
460471
calculateMapBoundsFromListOfLatLng(_points), 50));
461472

462473
emit(LoadedLocationState(
474+
polyline: _polyline,
463475
geofence: _geofence,
464-
locationMarkers: _hikeMarkers,
476+
locationMarkers: Set<Marker>.from(_hikeMarkers),
465477
mapType: _mapType,
466-
polyline: _polyline,
467478
version: DateTime.now().millisecondsSinceEpoch));
468479
} else if (beaconLocationsEntity.userSOS != null) {
469480
var user = beaconLocationsEntity.userSOS!;
@@ -669,21 +680,25 @@ class LocationCubit extends Cubit<LocationState> {
669680
return _address.isNotEmpty ? _address : null;
670681
}
671682

672-
// update here
673683
Future<void> createLandmark(
674684
String beaconId, String title, LatLng latlng, String icon) async {
675-
print("Creating landmark with title: $title at $latlng");
676685
var dataState = await _hikeUseCase.createLandMark(beaconId, title,
677686
latlng.latitude.toString(), latlng.longitude.toString(), icon);
678-
print("Data state: $dataState");
687+
679688
if (dataState is DataSuccess && dataState.data != null) {
680-
print('result Creating marker for landmark: 1: ${dataState.data?.icon}');
689+
print('Local landmark created: ${dataState.data!.title}');
681690
await _createLandMarkMarker(dataState.data!);
691+
692+
await locationUpdateSubscription(beaconId);
693+
682694
emit(LoadedLocationState(
683695
polyline: _polyline,
684696
geofence: _geofence,
685697
mapType: _mapType,
686-
locationMarkers: Set<Marker>.from(_hikeMarkers),
698+
locationMarkers:
699+
Set<Marker>.from(_hikeMarkers), // Create new Set instance
700+
version:
701+
DateTime.now().millisecondsSinceEpoch, // Consistent versioning
687702
message: 'New marker created by ${dataState.data!.createdBy!.name}'));
688703
}
689704
}
@@ -733,7 +748,7 @@ class LocationCubit extends Cubit<LocationState> {
733748
_hikeMarkers.where((element) => element.markerId == markerId);
734749

735750
if (existingMarkers.isEmpty) {
736-
var newMarker = await createMarkerWithCircularNetworkImage(
751+
var newMarker = await createMarkerWithLocalAsset(
737752
landMark,
738753
);
739754
_hikeMarkers.add(newMarker);
@@ -785,11 +800,44 @@ class LocationCubit extends Cubit<LocationState> {
785800
}
786801
}
787802

803+
Future<Marker> createMarkerWithLocalAsset(LandMarkEntity landmark) async {
804+
Future<BitmapDescriptor> getResizedMarkerIcon(
805+
String assetPath, int width) async {
806+
final ByteData data = await rootBundle.load(assetPath);
807+
final codec = await ui.instantiateImageCodec(
808+
data.buffer.asUint8List(),
809+
targetWidth: width,
810+
);
811+
final frame = await codec.getNextFrame();
812+
final ui.Image image = frame.image;
813+
814+
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
815+
final Uint8List resizedBytes = byteData!.buffer.asUint8List();
816+
817+
return BitmapDescriptor.fromBytes(resizedBytes);
818+
}
819+
820+
BitmapDescriptor customIcon = await getResizedMarkerIcon(
821+
landmark.icon ?? 'images/icons/location-marker.png',
822+
80, // desired width in pixels
823+
);
824+
825+
return Marker(
826+
markerId: MarkerId(landmark.id!.toString()),
827+
position: locationToLatLng(landmark.location!),
828+
icon: customIcon,
829+
infoWindow: InfoWindow(
830+
title:
831+
'${landmark.title} by ${landmark.createdBy?.name ?? 'Anonymous'}',
832+
),
833+
);
834+
}
835+
788836
Future<Marker> createMarkerWithCircularNetworkImage(
789837
LandMarkEntity landmark) async {
790838
print("Creating marker for landmark: ${landmark.createdBy?.imageUrl}");
791839
final Uint8List markerIcon = await getCircularImageWithBorderAndPointer(
792-
landmark.icon ?? 'assets/icons/location-marker.png',
840+
landmark.icon ?? 'images/icons/location-marker.png',
793841
size: 80,
794842
borderColor: Colors.teal,
795843
borderWidth: 4,

0 commit comments

Comments
 (0)