TKK_E32222567_Gps/lib/app/modules/maps/views/maps_view.dart

181 lines
5.6 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../controllers/maps_controller.dart';
class MapsView extends StatelessWidget {
const MapsView({super.key});
@override
Widget build(BuildContext context) {
final MapsController controller = Get.put(MapsController());
final Completer<GoogleMapController> mapController = Completer();
return Scaffold(
backgroundColor: Colors.white,
// === APPBAR SEPERTI HALAMAN NOTIFIKASI ===
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF7EFAB7),
Color(0xFF4FB9E4),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(30),
),
),
child: SafeArea(
child: Stack(
alignment: Alignment.center,
children: [
Align(
alignment: Alignment.centerLeft,
child: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Get.back(),
),
),
Text(
'Maps Lokasi',
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
),
// === ISI BODY ===
body: Obx(() {
final lat = controller.lat.value;
final lng = controller.lng.value;
final LatLng target = LatLng(lat, lng);
return Stack(
children: [
// === GOOGLE MAP FULL DI BAWAH APPBAR ===
Positioned.fill(
child: GoogleMap(
initialCameraPosition: CameraPosition(
target: target,
zoom: 16,
),
markers: {
Marker(
markerId: const MarkerId('current_location'),
position: target,
)
},
onMapCreated: (GoogleMapController googleMapController) {
mapController.complete(googleMapController);
controller.mapController.value = googleMapController;
},
myLocationEnabled: true,
myLocationButtonEnabled: false,
),
),
// === CARD INFO KOORDINAT MENGAMBANG DI ATAS MAP ===
Positioned(
bottom: 16,
left: 16,
right: 16,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 2,
blurRadius: 8,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShaderMask(
shaderCallback: (Rect bounds) {
return const LinearGradient(
colors: [
Color(0xFF7EFAB7),
Color(0xFF4FB9E4),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
).createShader(bounds);
},
child: const Icon(
Icons.location_on,
color: Colors.white,
size: 40,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Latitude : ${lat.toStringAsFixed(5)}',
style: GoogleFonts.poppins(
fontSize: 14,
color: const Color(0xFF35003F),
),
),
Text(
'Longitude : ${lng.toStringAsFixed(5)}',
style: GoogleFonts.poppins(
fontSize: 14,
color: const Color(0xFF35003F),
),
),
const SizedBox(height: 6),
Text(
'Last update : ${controller.lastUpdate.value}',
style: GoogleFonts.poppins(
fontSize: 12,
color: Colors.grey,
),
),
const SizedBox(height: 5),
GestureDetector(
onTap: () => controller.openGoogleMaps(lat, lng),
child: const Text(
'Tap untuk membuka di Google Maps',
style: TextStyle(
color: Color.fromARGB(255, 67, 225, 249),
fontSize: 12,
fontStyle: FontStyle.italic,
),
),
),
],
),
),
],
),
),
),
],
);
}),
);
}
}