actualiza todos los campos excepto schedule
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user