225 lines
7.6 KiB
Dart
225 lines
7.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../services/firestore_service.dart';
|
|
|
|
class ContactScreen extends StatefulWidget {
|
|
const ContactScreen({super.key});
|
|
|
|
@override
|
|
State<ContactScreen> createState() => _ContactScreenState();
|
|
}
|
|
|
|
class _ContactScreenState extends State<ContactScreen> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
final _firstNameController = TextEditingController();
|
|
final _lastNameController = TextEditingController();
|
|
final _emailController = TextEditingController();
|
|
final _phoneController = TextEditingController();
|
|
final _messageController = TextEditingController();
|
|
|
|
final FirestoreService _firestoreService = FirestoreService();
|
|
bool _isSubmitting = false;
|
|
|
|
@override
|
|
void dispose() {
|
|
_firstNameController.dispose();
|
|
_lastNameController.dispose();
|
|
_emailController.dispose();
|
|
_phoneController.dispose();
|
|
_messageController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
bool _isValidEmail(String email) {
|
|
return RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(email);
|
|
}
|
|
|
|
Future<void> _submitForm() async {
|
|
if (!_formKey.currentState!.validate() || _isSubmitting) return;
|
|
|
|
setState(() {
|
|
_isSubmitting = true;
|
|
});
|
|
|
|
try {
|
|
await _firestoreService.submitContactMessage(
|
|
firstName: _firstNameController.text.trim(),
|
|
lastName: _lastNameController.text.trim(),
|
|
email: _emailController.text.trim(),
|
|
phone: _phoneController.text.trim(),
|
|
message: _messageController.text.trim(),
|
|
);
|
|
|
|
if (!mounted) return;
|
|
|
|
_firstNameController.clear();
|
|
_lastNameController.clear();
|
|
_emailController.clear();
|
|
_phoneController.clear();
|
|
_messageController.clear();
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Ihre Nachricht wurde erfolgreich übermittelt!'),
|
|
backgroundColor: Colors.green,
|
|
),
|
|
);
|
|
} catch (e) {
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Fehler beim Senden: $e'),
|
|
backgroundColor: Colors.red,
|
|
),
|
|
);
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() {
|
|
_isSubmitting = false;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Kontakt Bürgerforum'),
|
|
centerTitle: true,
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Card(
|
|
color: Colors.blue.shade50,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
child: const Padding(
|
|
padding: EdgeInsets.all(14.0),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.mail_outline, color: Colors.blue, size: 28),
|
|
SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
'Hier kannst du direkt mit dem Bürgerforum Oggau in Kontakt treten. Wir freuen uns über deine Anregungen und Fragen!',
|
|
style: TextStyle(fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: TextFormField(
|
|
controller: _firstNameController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Vorname *',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
validator: (value) =>
|
|
(value == null || value.trim().isEmpty)
|
|
? 'Bitte Vorname eingeben'
|
|
: null,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: TextFormField(
|
|
controller: _lastNameController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Nachname *',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
validator: (value) =>
|
|
(value == null || value.trim().isEmpty)
|
|
? 'Bitte Nachname eingeben'
|
|
: null,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextFormField(
|
|
controller: _emailController,
|
|
keyboardType: TextInputType.emailAddress,
|
|
decoration: const InputDecoration(
|
|
labelText: 'E-Mail-Adresse *',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
validator: (value) {
|
|
if (value == null || value.trim().isEmpty) {
|
|
return 'Bitte E-Mail-Adresse eingeben';
|
|
}
|
|
if (!_isValidEmail(value.trim())) {
|
|
return 'Bitte eine gültige E-Mail eingeben';
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextFormField(
|
|
controller: _phoneController,
|
|
keyboardType: TextInputType.phone,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Rückrufnummer (optional)',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextFormField(
|
|
controller: _messageController,
|
|
maxLines: 5,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Ihr Anliegen / Ihre Nachricht *',
|
|
alignLabelWithHint: true,
|
|
border: OutlineInputBorder(),
|
|
),
|
|
validator: (value) =>
|
|
(value == null || value.trim().isEmpty)
|
|
? 'Bitte Ihre Nachricht eingeben'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
'Hinweis: Strafrechtlich relevante Kommentare und Verleumdungen werden polizeilich verfolgt.',
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
color: Colors.red.shade700,
|
|
fontStyle: FontStyle.italic,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 48,
|
|
child: ElevatedButton.icon(
|
|
onPressed: _isSubmitting ? null : _submitForm,
|
|
icon: _isSubmitting
|
|
? const SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: const Icon(Icons.send),
|
|
label: Text(
|
|
_isSubmitting ? 'Wird gesendet...' : 'Nachricht absenden',
|
|
style: const TextStyle(fontSize: 16),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|