import 'dart:async'; import 'dart:developer'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:injector/injector.dart'; import 'package:prosappco/constansts.dart'; import 'package:prosappco/screens/lists/professional_list_screen.dart'; import 'package:setting_repository/setting_repository.dart'; class UserMapScreen extends StatefulWidget { const UserMapScreen({super.key}); @override State createState() => _UserMapScreenState(); } class _UserMapScreenState extends State { final Completer _mapController = Completer(); LatLng? _currentP; final settingRepository = Injector.appInstance.get(); SettingEntity? settings; @override void initState() { super.initState(); _loadSettings(); } void _loadSettings() { settingRepository.getSettings().then( (value) => setState(() { settings = value; }), ); } @override Widget build(BuildContext context) { return Column( children: [ Expanded( child: Stack( children: [ GoogleMap( myLocationEnabled: true, onMapCreated: (GoogleMapController controller) { _mapController.complete(controller); }, initialCameraPosition: const CameraPosition( target: LatLng(7.078511421411328, -73.08832615613937 // currentPosition.latitude, currentPosition.longitude ), zoom: 16, ), myLocationButtonEnabled: false, ), Positioned( top: 10, left: 0, child: Builder( builder: (context) { return ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.white, shape: const CircleBorder(), elevation: 3, minimumSize: const Size(50, 50), ), child: const Icon( Icons.menu, color: Colors.black, size: 35, ), onPressed: () { Scaffold.of(context).openDrawer(); }, ); }, ), ), const Positioned( bottom: 30, right: 0, left: 0, top: 0, child: Icon( Icons.location_on, size: 40, color: Color(0xFFFF0000), ), ), Positioned( top: 10, right: 10, child: FloatingActionButton( onPressed: () async { try { Position position = await _determinePosition(); if (mounted) { setState(() { _currentP = LatLng( position.latitude, position.longitude, ); }); _animateCameraToPosition(_currentP!); } } catch (e) { ScaffoldMessenger.of(context).clearSnackBars(); ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Por favor activa la ubicacion'), ), ); } }, elevation: 0, child: const Icon( Icons.gps_fixed, size: 30, ), ), ), ], ), ), buildBottom(context) ], ); } Container buildBottom(BuildContext context) { return Container( padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 10), color: Colors.white, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ TextField( readOnly: true, onTap: () async { var datos = await Navigator.push(context, CupertinoPageRoute(builder: (context) { return const ProfessionalListScreen(); })); log('xd -- $datos'); }, decoration: const InputDecoration( prefixIcon: Icon(Icons.assignment_ind_rounded), suffixIcon: Icon(Icons.arrow_drop_down), hintText: 'Selecciona un profesional', ), ), const SizedBox(height: 15), const TextField( readOnly: true, decoration: InputDecoration( prefixIcon: Icon(Icons.location_on), hintText: 'Dirección', ), ), const SizedBox(height: 15), const Row( children: [ Expanded( child: TextField( readOnly: true, decoration: InputDecoration( prefixIcon: Icon(Icons.calendar_month), hintText: 'Fecha', ), ), ), Expanded( child: TextField( readOnly: true, decoration: InputDecoration( prefixIcon: Icon(Icons.watch_later_outlined), hintText: 'Hora', ), ), ), ], ), const SizedBox(height: 15), const TextField( // controller: _observacionController, decoration: InputDecoration( prefixIcon: Icon(Icons.message_outlined), hintText: 'Observaciones', ), ), const SizedBox(height: 15), Row( children: [ Expanded( child: FilledButton( onPressed: () {}, style: FilledButton.styleFrom( backgroundColor: Theme.of(context).colorScheme.primary, padding: const EdgeInsets.symmetric(vertical: 15), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), // style: ElevatedButton.styleFrom( // backgroundColor: Theme.of(context).colorScheme.primary, // padding: const EdgeInsets.symmetric(vertical: 15), // shape: RoundedRectangleBorder( // borderRadius: BorderRadius.circular(10), // ), // ), child: const Text( 'Pedir cita', style: TextStyle(color: Colors.white, fontSize: 18), ), ), ), const SizedBox(width: 10), FilledButton( onPressed: () {}, style: FilledButton.styleFrom( backgroundColor: Colors.red, padding: const EdgeInsets.symmetric(vertical: 15), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), //x child: const Icon( CupertinoIcons.xmark, color: Colors.white, size: 30, ), ), ], ) ], ), ); } Future _animateCameraToPosition(LatLng position) async { final GoogleMapController controller = await _mapController.future; controller.animateCamera( CameraUpdate.newCameraPosition( CameraPosition( target: position, zoom: 17.5, ), ), ); } Future _determinePosition() async { bool serviceEnabled; LocationPermission permission; serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { return Future.error('Location services are disabled'); } permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.denied) { return Future.error('Location permission denied'); } } if (permission == LocationPermission.deniedForever) { return Future.error('Location permissions are permanently denied'); } Position position = await Geolocator.getCurrentPosition(); return position; } }