Skip to content

Commit

Permalink
Merge pull request #76 from SWM-M3PRO/feature/M3-292-myPlaceModify
Browse files Browse the repository at this point in the history
M3-292 내 장소 등록 수정
  • Loading branch information
tkdals802 authored Aug 17, 2024
2 parents 71a1c8d + 8692dba commit 61ab1e5
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 81 deletions.
Binary file added assets/images/green_map_pin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 19 additions & 15 deletions lib/controllers/my_place_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class MyPlaceController extends GetxController {

RxList<Marker> markers = <Marker>[].obs;
RxBool isLoading = true.obs;
final RxDouble selectedLatitude = 37.503640.obs;
final RxDouble selectedLongitude = 127.044829.obs;
final RxDouble selectedLatitude = 37.566422.obs;
final RxDouble selectedLongitude = 126.977948.obs;
RxBool isCameraTrackingUser = true.obs;
final RxString myPlaceName = "HOME".obs;
final RxInt selectedPlace = 0.obs;

Expand All @@ -49,25 +50,13 @@ class MyPlaceController extends GetxController {
bottomSheetController.minimize();
}

void updateMarker(LatLng latLng) {
markers.clear();
markers.add(
Marker(
markerId: MarkerId('clicked_position'),
position: latLng,
infoWindow: InfoWindow(
title: 'Clicked Position',
snippet: 'Lat: ${latLng.latitude}, Lng: ${latLng.longitude}',
),
),
);
void updateCoordinate(LatLng latLng) {
selectedLatitude.value = latLng.latitude;
selectedLongitude.value = latLng.longitude;
}

Future<void> initCurrentLocation() async {
try {
await LocationService().initCurrentLocation();
currentCameraPosition = CameraPosition(
target: LatLng(
_locationService.currentLocation!.latitude!,
Expand Down Expand Up @@ -123,4 +112,19 @@ class MyPlaceController extends GetxController {
getSelectedPlace() {
return selectedPlace.value;
}

setCameraOnCurrentLocation() {
isCameraTrackingUser = true.obs;

currentCameraPosition = CameraPosition(
target: LatLng(
_locationService.currentLocation!.latitude!,
_locationService.currentLocation!.longitude!,
),
zoom: 16.0,
);
googleMapController?.animateCamera(
CameraUpdate.newCameraPosition(currentCameraPosition),
);
}
}
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ Future<void> main() async {
]);
await dotenv.load(fileName: ".env");
await GetStorage.init();
final MainController mainController = MainController();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);

mainController.checkVersion();
KakaoSdk.init(nativeAppKey: dotenv.env['NATIVE_APP_KEY']!);
LocationService().initBackgroundLocation();
String initialRoute = await AuthService().isLogin() ? '/main' : '/permission';
final MainController mainController = Get.put(MainController(), permanent: true);
mainController.checkVersion();
runApp(
MyApp(
initialRoute: initialRoute,
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MapScreen extends StatelessWidget {
mapController.googleMapController = ctrl;
},
myLocationEnabled: true,
myLocationButtonEnabled: false,
style: mapController.mapStyle,
polygons: Set<Polygon>.of(mapController.pixels),
),
Expand Down Expand Up @@ -98,7 +99,7 @@ class MapScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
PixelCountInfo(count: 128),
CurrentLocationButton(),
CurrentLocationButton(checkController: "map",),
],
),
),
Expand Down
128 changes: 92 additions & 36 deletions lib/screens/my_place_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,45 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../constants/app_colors.dart';
import '../controllers/my_place_controller.dart';
import '../service/location_service.dart';
import '../widgets/map/current_location_button.dart';

class MyPlaceScreen extends StatelessWidget {
MyPlaceScreen({super.key});

@override
Widget build(BuildContext context) {
final MyPlaceController myPlaceController = Get.put(MyPlaceController());
const double mapPinHeight = 60;
const double mapPinWidth = mapPinHeight * 0.85;

return Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {
Get.back();
},
icon: Icon(
Icons.arrow_back_ios,
color: AppColors.buttonColor,
),
final PreferredSizeWidget appBar = AppBar(
leading: IconButton(
onPressed: () {
Get.back();
},
icon: Icon(
Icons.arrow_back_ios,
color: AppColors.buttonColor,
),
backgroundColor: AppColors.background,
title: Text(
'내 장소 등록',
style: TextStyle(
color: AppColors.textPrimary,
),
),
backgroundColor: AppColors.background,
title: Text(
'내 장소 등록',
style: TextStyle(
color: AppColors.textPrimary,
),
),
);
final Widget mapPinImage = Image.asset(
'assets/images/green_map_pin.png',
height: mapPinHeight,
width: mapPinWidth,
);

final double appBarHeight = appBar.preferredSize.height;

return Scaffold(
appBar: appBar,
body: Obx(() {
if (myPlaceController.isLoading.value) {
return const Center(
Expand All @@ -58,36 +70,80 @@ class MyPlaceScreen extends StatelessWidget {
myPlaceController.googleMapController = ctrl;
},
myLocationEnabled: false,
zoomControlsEnabled: false,
style: myPlaceController.mapStyle,
markers: Set<Marker>.of(myPlaceController.markers),
onTap: (LatLng latLng) {
myPlaceController.updateMarker(latLng);
onCameraIdle: () async {
final GoogleMapController? controller =
myPlaceController.googleMapController;
LatLng center = LatLng(
LocationService().currentLocation!.latitude!,
LocationService().currentLocation!.longitude!,
);
if (controller != null) {
LatLngBounds visibleRegion =
await controller.getVisibleRegion();
center = LatLng(
(visibleRegion.northeast.latitude +
visibleRegion.southwest.latitude) /
2,
(visibleRegion.northeast.longitude +
visibleRegion.southwest.longitude) /
2,
);
}
myPlaceController.updateCoordinate(center);
},
);
},
),
Positioned(
top: 20,
right: 10,
child: GestureDetector(
onTap: () {
myPlaceController.openMyPlaceBottomSheet();
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 7, horizontal: 20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: AppColors.primary,
top: (MediaQuery.of(context).size.height - appBarHeight) / 2 -
(mapPinHeight - 2),
left:
(MediaQuery.of(context).size.width / 2) - (mapPinWidth / 2),
child: mapPinImage,
),
Positioned(
bottom: 15,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: CurrentLocationButton(
checkController: "myPlace",
),
),
child: Text(
'등록',
style: TextStyle(
color: AppColors.textPrimary,
fontSize: 15,
fontWeight: FontWeight.w700,
Padding(
padding: const EdgeInsets.all(10),
child: GestureDetector(
onTap: () {
myPlaceController.openMyPlaceBottomSheet();
},
child: Container(
width: MediaQuery.of(context).size.width - 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: AppColors.primary,
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
child: Text(
'등록',
style: TextStyle(
color: AppColors.textBlack,
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
),
),
),
),
),
),
],
),
),
],
Expand Down
44 changes: 22 additions & 22 deletions lib/utils/dio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ class DioService {
return handler.next(response);
},
onError: (
DioException dioException,
ErrorInterceptorHandler errorInterceptorHandler,
) async {
DioException dioException,
ErrorInterceptorHandler errorInterceptorHandler,
) async {
if (dioException.response?.statusCode == HttpStatus.unauthorized) {
try {
ReissueResponse reissueResponse = await reissueToken();
userManager.setAccessToken(reissueResponse.accessToken!);
userManager.setRefreshToken(reissueResponse.refreshToken!);

Response<dynamic> resendResponse =
await resendRequest(dioException, reissueResponse);
await resendRequest(dioException, reissueResponse);
errorInterceptorHandler.resolve(resendResponse);
debugPrint('-------------refresh---------------');
} catch (err) {
Expand All @@ -69,9 +69,9 @@ class DioService {
}

Future<Response<dynamic>> resendRequest(
DioException dioException,
ReissueResponse reissueResponse,
) async {
DioException dioException,
ReissueResponse reissueResponse,
) async {
final options = dioException.requestOptions;
final dio = Dio();
options.headers.addAll({
Expand All @@ -87,7 +87,7 @@ class DioService {
var response = await dio
.post("$baseUrl/auth/reissue", data: {"refreshToken": refreshToken});
ReissueResponse reissueResponse =
ReissueResponse.fromJson(response.data["data"]);
ReissueResponse.fromJson(response.data["data"]);
UserManager().setTokenReissued();
return reissueResponse;
}
Expand All @@ -102,11 +102,11 @@ class DioService {
options.extra['requestTimestamp'] = requestTimestamp;
debugPrint(
'---------------[Request - $requestTimestamp]---------------\n'
'[Method] : ${options.method}\n'
'[Path] : ${options.path}\n'
'[Headers] : ${options.headers}\n'
'[Query Parameters] : ${options.queryParameters}\n'
'[Body] : ${options.data}',
'[Method] : ${options.method}\n'
'[Path] : ${options.path}\n'
'[Headers] : ${options.headers}\n'
'[Query Parameters] : ${options.queryParameters}\n'
'[Body] : ${options.data}',
);
}
}
Expand All @@ -118,21 +118,21 @@ class DioService {
var requestDuration = requestEndTime.difference(requestTimestamp);
debugPrint(
'\n---------------[Response - $requestTimestamp]---------------\n'
'[Status Code] : ${response.statusCode}\n'
'[Data] : ${response.data}\n'
'[Duration] : ${requestDuration.inMilliseconds} ms\n'
'----------------------------------------------\n',
'[Status Code] : ${response.statusCode}\n'
'[Data] : ${response.data}\n'
'[Duration] : ${requestDuration.inMilliseconds} ms\n'
'----------------------------------------------\n',
);
}
}

void logError(DioException dioException) {
debugPrint(
'\n---------------[Response - ERROR]---------------\n'
'[Status Code] : ${dioException.response?.statusCode}\n'
'[Message]: ${dioException.message}'
'[Data] : ${dioException.response?.data}\n'
'----------------------------------------------\n',
'[Status Code] : ${dioException.response?.statusCode}\n'
'[Message]: ${dioException.message}'
'[Data] : ${dioException.response?.data}\n'
'----------------------------------------------\n',
);
}
}
}
24 changes: 20 additions & 4 deletions lib/widgets/map/current_location_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@ import 'package:get/get.dart';

import '../../constants/app_colors.dart';
import '../../controllers/map_controller.dart';
import '../../controllers/my_place_controller.dart';

class CurrentLocationButton extends StatefulWidget {
const CurrentLocationButton({super.key});
final String checkController;
const CurrentLocationButton({super.key, required this.checkController});

@override
createState() => _CurrentLocationButtonState();
}

class _CurrentLocationButtonState extends State<CurrentLocationButton> {
final MapController mapController = Get.find<MapController>();
late final dynamic _controller;
Color _buttonColor = AppColors.backgroundSecondary; // 기본 배경 색상
final Color _pressedColor = Colors.grey; // 눌렀을 때의 배경 색상

@override
void initState(){
super.initState();
_initializeController();
}

void _initializeController(){
if(widget.checkController=="map"){
_controller = Get.find<MapController>();
}else{
_controller = Get.find<MyPlaceController>();
}
}

void _onPointerDown(DragDownDetails event) {
setState(() {
_buttonColor = _pressedColor;
Expand All @@ -32,8 +48,8 @@ class _CurrentLocationButtonState extends State<CurrentLocationButton> {
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
mapController.setCameraOnCurrentLocation();
mapController.isCameraTrackingUser = true.obs;
_controller.setCameraOnCurrentLocation();
_controller.isCameraTrackingUser = true.obs;
},
onPanDown: _onPointerDown,
onPanEnd: (details) => _onPointerUp(),
Expand Down
Loading

0 comments on commit 61ab1e5

Please sign in to comment.