actualiza todos los campos excepto schedule

This commit is contained in:
Felipe
2024-03-19 15:40:07 -05:00
parent bb840260ba
commit 10536be873
13 changed files with 868 additions and 33 deletions
@@ -0,0 +1,283 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:prosappco/components/general_primary_button.dart';
class ProfessionalMapScreen extends StatefulWidget {
const ProfessionalMapScreen({super.key});
@override
State<ProfessionalMapScreen> createState() => _ProfessionalMapScreenState();
}
class _ProfessionalMapScreenState extends State<ProfessionalMapScreen> {
final TextEditingController _addressController = TextEditingController();
bool _locationPermissionGranted = false;
late GoogleMapController googleMapController;
late Position currentPosition;
var coords;
@override
void initState() {
super.initState();
_getLocation();
}
Future<void> _getLocation() async {
try {
final position = await _determinePosition();
setState(() {
currentPosition = position;
_locationPermissionGranted = true;
});
} catch (e) {
log('Error getting location: $e');
}
}
Future<Position> _determinePosition() async {
bool serviceEnabled;
LocationPermission permission;
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
throw 'Location services are disabled';
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
throw 'Location permission denied';
}
}
if (permission == LocationPermission.deniedForever) {
throw 'Location permissions are permanently denied';
}
return await Geolocator.getCurrentPosition();
}
Future<String> getLocationName(double latitude, double longitude) async {
String address;
List<Placemark> placemarks =
await placemarkFromCoordinates(latitude, longitude);
Placemark place = placemarks[0];
if (place.thoroughfare != '' || place.subThoroughfare != '') {
address =
"${place.thoroughfare} ${place.subThoroughfare} ${place.subLocality}, ${place.locality}, ${place.administrativeArea}";
} else {
address = '';
}
return address;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Ubicación'),
// leading: BackButton(
// onPressed: () {
// Navigator.pop(
// context, {"address": '', 'longitude': 0, 'latitude': 0});
// },
// ),
actions: [
IconButton(
icon: const Icon(Icons.my_location),
onPressed: () async {
try {
final position = await _determinePosition();
if (googleMapController != null) {
googleMapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(position.latitude, position.longitude),
zoom: 18,
),
),
);
} else {
log('Google Map Controller is not initialized.');
}
setState(() {
currentPosition = position;
_locationPermissionGranted = true;
});
} catch (e) {
log('Error getting location: $e');
setState(() {
_locationPermissionGranted = false;
});
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text(
'Los servicios de ubicación están desactivados'),
action: SnackBarAction(
label: 'Configuración',
onPressed: () {
Geolocator.openLocationSettings();
},
),
),
);
}
},
),
],
),
backgroundColor: const Color(0xFFD6F4FF),
body: Stack(
children: [
_locationPermissionGranted
? GoogleMap(
mapType: MapType.normal,
initialCameraPosition: CameraPosition(
target: LatLng(
currentPosition.latitude, currentPosition.longitude),
zoom: 16,
),
zoomControlsEnabled: false,
myLocationEnabled: true,
onMapCreated: (GoogleMapController controller) {
googleMapController = controller;
},
onCameraMove: (position) {
setState(() {
coords = position.target;
});
},
onCameraIdle: () async {
final isLocationEnabled =
await Geolocator.isLocationServiceEnabled();
if (!isLocationEnabled) {
setState(() {
_locationPermissionGranted = false;
});
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text(
'Los servicios de ubicación están desactivados'),
action: SnackBarAction(
label: 'Configuración',
onPressed: () {
Geolocator.openLocationSettings();
},
),
),
);
}
if (coords != null) {
getLocationName(coords.latitude, coords.longitude)
.then((locationName) {
setState(() {
_addressController.text = locationName;
});
});
}
},
)
: Container(
color: Colors.white,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircularProgressIndicator()
.animate()
.fadeOut(duration: const Duration(seconds: 2)),
const SizedBox(height: 8),
const Text('Cargando...')
.animate()
.fadeOut(duration: const Duration(seconds: 2)),
const Text('Permita los permisos de ubicación')
.animate()
.fadeIn(delay: const Duration(seconds: 2))
.scale(),
],
),
),
),
_locationPermissionGranted
? Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 1,
blurRadius: 5,
offset: const Offset(0, 2),
),
],
),
child: Padding(
padding: const EdgeInsets.only(
left: 18,
right: 18,
bottom: 15,
),
child: TextFormField(
readOnly: true,
controller: _addressController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.near_me),
hintText: 'Dirección',
),
),
),
)
: const SizedBox(),
_locationPermissionGranted
? const Positioned(
bottom: 30,
right: 0,
left: 0,
top: 0,
child: Icon(
Icons.location_on,
size: 40,
color: Colors.red,
),
)
: const SizedBox(),
_locationPermissionGranted
? Positioned(
bottom: 30,
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Center(
child: GeneralPrimaryButton(
label: 'Guardar',
isEnabled: _locationPermissionGranted,
onPressed: () {
Navigator.pop(context, {
"address": _addressController.text,
'latitude': coords.latitude,
'longitude': coords.longitude,
});
},
),
),
),
)
: const SizedBox(),
],
),
);
}
}
@@ -1,7 +1,21 @@
import 'dart:developer';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:image_picker/image_picker.dart';
import 'package:injector/injector.dart';
import 'package:professional_repository/professional_repository.dart';
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
import 'package:prosappco/blocs/professional_bloc/professional_bloc.dart';
import 'package:prosappco/blocs/professional_profile_bloc/professional_profile_bloc.dart';
import 'package:prosappco/components/general_primary_button.dart';
import 'package:prosappco/screens/professional/professional_map_screen.dart';
import 'package:prosappco/screens/professional/professional_schedule_screen.dart';
import 'package:setting_repository/setting_repository.dart';
class ProfessionalProfileScreen extends StatefulWidget {
const ProfessionalProfileScreen({super.key});
@@ -12,6 +26,52 @@ class ProfessionalProfileScreen extends StatefulWidget {
}
class _ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
final settingRepository = Injector.appInstance.get<SettingRepository>();
SettingEntity? settings;
XFile? _imageFile;
bool loadFinish = false;
bool officeValue = false;
bool deliveryValue = false;
bool rateValue = false;
final TextEditingController _addressController = TextEditingController();
final TextEditingController _aditionalAddressController =
TextEditingController();
final TextEditingController _rateController = TextEditingController();
double _longitudeController = 0;
double _latitudeController = 0;
bool isNequiActive = false;
bool isDatafonoActive = false;
bool isTransferActive = false;
@override
void initState() {
super.initState();
_loadSettings();
}
@override
void dispose() {
_addressController.dispose();
_aditionalAddressController.dispose();
_rateController.dispose();
super.dispose();
}
void _loadSettings() {
settingRepository.getSettings().then(
(value) => setState(() {
settings = value;
}),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -21,7 +81,7 @@ class _ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
body: BlocBuilder<ProfessionalBloc, ProfessionalState>(
builder: (context, state) {
return Scaffold(
body: Center(
body: SingleChildScrollView(
child: content(context, state),
),
);
@@ -44,6 +104,353 @@ class _ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
}
body(ProfessionalEntity proInfo) {
return Text('Bienvenido Profesional ${proInfo.address}');
if (!loadFinish) {
_addressController.text = proInfo.address;
_aditionalAddressController.text = proInfo.aditionalAddress;
isNequiActive = proInfo.paymentMethods.nequi;
isDatafonoActive = proInfo.paymentMethods.datafono;
isTransferActive = proInfo.paymentMethods.transferencia;
// proInfo.bannerPicture != ''
// ? _imageFile = XFile(proInfo.bannerPicture)
// : _imageFile = null;
if (proInfo.locationPreferences == LocationPreferences.both) {
officeValue = true;
deliveryValue = true;
} else if (proInfo.locationPreferences == LocationPreferences.office) {
officeValue = true;
deliveryValue = false;
} else if (proInfo.locationPreferences == LocationPreferences.delivery) {
officeValue = false;
deliveryValue = true;
}
_rateController.text = proInfo.rate;
loadFinish = true;
}
return Column(
children: [
pictureWidget(proInfo.bannerPicture, context),
const Divider(height: 0),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 15),
child: Column(
children: [
Row(
children: [
const Expanded(
child: Text(
'Servicio a domicilio',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
),
Switch(
value: deliveryValue,
onChanged: (value) {
setState(() {
deliveryValue = value;
if (settings?.domicilios == true) {
deliveryValue = value;
if (!deliveryValue) {
officeValue = true;
}
} else {
deliveryValue = false;
}
});
},
),
],
),
Row(
children: [
const Expanded(
child: Text(
'Servicio en sitio',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
),
Switch(
value: officeValue,
onChanged: (value) {
setState(() {
if (settings?.domicilios == true) {
officeValue = value;
if (!officeValue) {
deliveryValue = true;
}
} else {
officeValue = true;
deliveryValue = false;
}
});
},
),
],
),
officeValue
? Column(
children: [
TextField(
decoration: const InputDecoration(
prefixIcon: Icon(Icons.location_on_outlined),
hintText: 'Dirección',
),
controller: _addressController,
readOnly: true,
onTap: () async {
final Map<String, dynamic>? mapInfo =
await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
const ProfessionalMapScreen()),
);
if (mapInfo != null) {
setState(() {
_addressController.text =
mapInfo['address'] ?? '';
_latitudeController =
mapInfo['latitude'] ?? 0;
_longitudeController =
mapInfo['longitude'] ?? 0;
});
}
}),
TextField(
controller: _aditionalAddressController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.house_outlined),
hintText: 'Piso / Conjunto / Apartamento',
),
),
],
)
.animate()
.moveY(duration: const Duration(milliseconds: 100))
: const SizedBox(),
],
),
),
const Divider(height: 0),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 15),
child: Column(
children: [
Row(
children: [
const Expanded(
child: Text(
'Tarifa',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
),
Switch(
value: rateValue,
onChanged: (value) {
setState(() {
if (settings?.tarifas == true) {
rateValue = value;
} else {
rateValue = false;
}
});
},
),
],
),
rateValue
? TextField(
controller: _rateController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.attach_money),
hintText: 'COP',
),
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
)
.animate()
.moveY(duration: const Duration(milliseconds: 100))
: const SizedBox(),
],
),
),
const Divider(height: 0),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 15),
child: Column(
children: [
const Padding(
padding: EdgeInsets.only(bottom: 10),
child: Text(
'Metodos de pago',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
),
CheckboxListTile(
value: isDatafonoActive,
onChanged: (value) {
setState(() {
isDatafonoActive = value!;
});
},
title: const Text('Datafono'),
),
CheckboxListTile(
value: isNequiActive,
onChanged: (value) {
setState(() {
isNequiActive = value!;
});
},
title: const Text('Nequi'),
),
CheckboxListTile(
value: isTransferActive,
onChanged: (value) {
setState(() {
isTransferActive = value!;
});
},
title: const Text('Transferencia bancaria'),
),
],
),
),
const Divider(height: 0),
GestureDetector(
onTap: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => const ProfessionalScheduleScreen(),
),
);
},
child: Text(proInfo.schedules.toString()),
),
const Divider(height: 0),
const SizedBox(height: 20),
GeneralPrimaryButton(
onPressed: () {
context.read<ProfessionalProfileBloc>().add(
UpdateProfessionalProfileInfo(
address: _addressController.text,
aditionalAddress: _aditionalAddressController.text,
latitude: _latitudeController,
longitude: _longitudeController,
locationPreferences: officeValue && deliveryValue
? LocationPreferences.both
: officeValue && !deliveryValue
? LocationPreferences.office
: deliveryValue && !officeValue
? LocationPreferences.delivery
: LocationPreferences.office,
paymentMethods: PaymentMethodEntity(
datafono: isDatafonoActive,
nequi: isNequiActive,
transferencia: isTransferActive,
),
rate: _rateController.text,
// schedules: Schedules(
// monday: monday,
// tuesday: tuesday,
// wednesday: wednesday,
// thursday: thursday,
// friday: friday,
// saturday: saturday,
// sunday: sunday,
// ),
),
);
context.read<ProfessionalProfileBloc>().add(
UpdateProfessionalBannerInfo(fileBanner: _imageFile?.path),
);
},
label: 'Guardar',
),
const SizedBox(height: 20),
],
);
}
Widget pictureWidget(String? bannerPicture, BuildContext context) {
final pictureUrl = bannerPicture;
final pathImageFile = _imageFile?.path;
ImageProvider<Object>? imageProvider;
if (pathImageFile != null && pathImageFile.isNotEmpty) {
imageProvider = FileImage(File(pathImageFile));
} else if (pictureUrl != null && pictureUrl.isNotEmpty) {
imageProvider = NetworkImage(pictureUrl);
}
return GestureDetector(
onTap: () async {
final ImagePicker picker = ImagePicker();
final XFile? image = await picker.pickImage(
source: ImageSource.gallery,
maxHeight: 1000,
maxWidth: 2000,
imageQuality: 40,
);
if (image != null) {
setState(() {
_imageFile = image;
});
}
},
child: pictureContainerWidget(imageProvider),
);
}
Widget pictureContainerWidget(ImageProvider<Object>? imageProvider) {
final image = imageProvider == null
? null
: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
);
final widget = image == null
? Icon(
Icons.image_outlined,
color: Colors.grey.shade400,
size: 40,
)
: null;
return Container(
width: double.infinity,
height: 200,
decoration: BoxDecoration(
color: Colors.grey.shade300,
image: image,
),
child: widget,
);
}
}
@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
class ProfessionalScheduleScreen extends StatefulWidget {
const ProfessionalScheduleScreen({super.key});
@override
State<ProfessionalScheduleScreen> createState() =>
_ProfessionalScheduleScreenState();
}
class _ProfessionalScheduleScreenState
extends State<ProfessionalScheduleScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Horario'),
),
body: SingleChildScrollView(
child: Column(
children: [
Row(
children: [
Expanded(
child: Text(
'Lunes',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
),
Switch(
value: false,
onChanged: (value) {
setState(() {});
},
),
],
),
],
),
),
);
}
}