Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
282 lines
9.9 KiB
Dart
282 lines
9.9 KiB
Dart
import 'package:prosapp_web_app/models/setting.dart';
|
|
import 'package:prosapp_web_app/providers/settings_provider.dart';
|
|
import 'package:prosapp_web_app/services/api_service.dart';
|
|
import 'package:prosapp_web_app/ui/cards/white_card.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:prosapp_web_app/ui/labels/custom_labels.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class SupportView extends StatelessWidget {
|
|
const SupportView({super.key});
|
|
|
|
Future<void> _launchURL(String url) async {
|
|
final Uri _url = Uri.parse(url);
|
|
|
|
if (await canLaunchUrl(_url)) {
|
|
await launchUrl(
|
|
_url,
|
|
mode: LaunchMode.externalApplication,
|
|
webOnlyWindowName: '_blank', // Para abrir en una nueva pestaña en web
|
|
);
|
|
} else {
|
|
throw 'No se pudo abrir la URL $url';
|
|
}
|
|
}
|
|
|
|
Future<void> _goWhatssApp(String number) async {
|
|
final url = 'https://api.whatsapp.com/send?phone=$number&text=Hola%21+soy+usuario+de+Prosapp+y+quisiera+conocer+mas+sobre+esta+app+%F0%9F%98%81';
|
|
await _launchURL(url);
|
|
}
|
|
|
|
Future<void> _goEmail(String email) async {
|
|
final url = 'mailto:$email?subject=${Uri.encodeComponent(email)}';
|
|
|
|
await _launchURL(url);
|
|
}
|
|
|
|
Future<void> _goSugerencias(BuildContext context) async {
|
|
final controller = TextEditingController();
|
|
final api = ApiService.instance;
|
|
bool sending = false;
|
|
|
|
await showDialog(
|
|
context: context,
|
|
builder: (ctx) => StatefulBuilder(
|
|
builder: (ctx, setState) => AlertDialog(
|
|
title: const Text('Enviar sugerencia'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Text(
|
|
'Cuéntanos cómo podemos mejorar ProsApp',
|
|
style: TextStyle(fontSize: 14),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: controller,
|
|
maxLines: 4,
|
|
decoration: const InputDecoration(
|
|
hintText: 'Escribe tu sugerencia aquí...',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: sending ? null : () => Navigator.pop(ctx),
|
|
child: const Text('Cancelar'),
|
|
),
|
|
FilledButton(
|
|
onPressed: sending
|
|
? null
|
|
: () async {
|
|
final msg = controller.text.trim();
|
|
if (msg.isEmpty) return;
|
|
setState(() => sending = true);
|
|
try {
|
|
await api.post('/suggestions', {'message': msg});
|
|
if (ctx.mounted) {
|
|
Navigator.pop(ctx);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('¡Gracias por tu sugerencia!'),
|
|
backgroundColor: Colors.green,
|
|
),
|
|
);
|
|
}
|
|
} catch (_) {
|
|
setState(() => sending = false);
|
|
if (ctx.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Error al enviar. Intenta de nuevo.'),
|
|
backgroundColor: Colors.red,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
},
|
|
child: sending
|
|
? const SizedBox(
|
|
width: 16,
|
|
height: 16,
|
|
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
|
)
|
|
: const Text('Enviar'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _goPoliticas(String urlText) async {
|
|
final url = urlText;
|
|
await _launchURL(url);
|
|
}
|
|
|
|
Future<void> _goTerminos(String urlText) async {
|
|
final url = urlText;
|
|
await _launchURL(url);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
return Consumer<SettingsProvider>(
|
|
builder: (context, settingsProvider, child) {
|
|
final settings = settingsProvider.settings ?? Setting.fromDocument({});
|
|
|
|
return ListView(
|
|
physics: const ClampingScrollPhysics(),
|
|
children: [
|
|
const SizedBox(height: 10),
|
|
Center(
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 800),
|
|
child: WhiteCard(
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 10, bottom: 30),
|
|
child: Center(
|
|
child: Text(
|
|
settings.tituloSoporte,
|
|
style: TextStyle(
|
|
fontSize: size.width > 500 ? 30 : 20,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
left: size.width > 500 ? 30 : 0,
|
|
right: size.width > 500 ? 30 : 0,
|
|
bottom: 30,
|
|
),
|
|
child: Text(
|
|
settings.parrafoSoporte,
|
|
style: CustomLabels.h3,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
Center(
|
|
child: Column(
|
|
children: [
|
|
const Text(
|
|
'Horario de atención:',
|
|
style: TextStyle(
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Text(settings.diasSoporte, style: CustomLabels.h3),
|
|
Text(settings.horasSoporte, style: CustomLabels.h3),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 30),
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
left: size.width > 500 ? 30 : 0,
|
|
right: size.width > 500 ? 30 : 0,
|
|
bottom: 30,
|
|
),
|
|
child: Wrap(
|
|
alignment: WrapAlignment.center,
|
|
spacing: 15,
|
|
runSpacing: 15,
|
|
children: [
|
|
_buildGridButton(
|
|
context,
|
|
icon: Icons.phone,
|
|
text: 'WhatsApp',
|
|
onPressed: () =>
|
|
_goWhatssApp(settings.numeroSoporte),
|
|
),
|
|
_buildGridButton(
|
|
context,
|
|
icon: Icons.email,
|
|
text: 'Email',
|
|
onPressed: () => _goEmail(settings.emailSoporte),
|
|
),
|
|
_buildGridButton(
|
|
context,
|
|
icon: Icons.feedback,
|
|
text: 'Sugerencias',
|
|
onPressed: () => _goSugerencias(context),
|
|
),
|
|
_buildGridButton(
|
|
context,
|
|
icon: Icons.privacy_tip,
|
|
text: 'Políticas de Privacidad',
|
|
onPressed: () =>
|
|
_goPoliticas(settings.politicasPrivacidad),
|
|
),
|
|
_buildGridButton(
|
|
context,
|
|
icon: Icons.article,
|
|
text: 'Términos y Condiciones',
|
|
onPressed: () =>
|
|
_goTerminos(settings.terminosCondiciones),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildGridButton(
|
|
BuildContext context, {
|
|
required IconData icon,
|
|
required String text,
|
|
required VoidCallback onPressed,
|
|
}) {
|
|
return MouseRegion(
|
|
cursor: SystemMouseCursors.click,
|
|
child: GestureDetector(
|
|
onTap: onPressed,
|
|
child: Container(
|
|
height: 110,
|
|
width: 180,
|
|
decoration: BoxDecoration(
|
|
color: Colors.blue[600],
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(icon, size: 40, color: Colors.white),
|
|
const SizedBox(height: 10),
|
|
Center(
|
|
child: Text(
|
|
textAlign: TextAlign.center,
|
|
text,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 18,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|