CommunityAPP/lib/emergency.dart

160 lines
5.1 KiB
Dart

import 'package:flutter/material.dart';
class EmergencyPage extends StatefulWidget {
const EmergencyPage({super.key});
@override
State<EmergencyPage> createState() => _EmergencyPageState();
}
class _EmergencyPageState extends State<EmergencyPage> {
final TextEditingController _descriptionController = TextEditingController();
String? _selectedType;
final List<Map<String, String>> disasterTypes = [
{"label": "🔥 火災", "value": "火災"},
{"label": "🌏 地震", "value": "地震"},
{"label": "💧 水災", "value": "水災"},
{"label": "🕵️‍♂️ 可疑人物", "value": "可疑人物"},
{"label": "⚠️ 公共設施故障", "value": "公共設施故障"},
{"label": "❓ 其他", "value": "其他"},
];
void _sendAlert() {
final type = _selectedType;
final desc = _descriptionController.text.trim();
if (type == null || type.isEmpty) {
_showDialog("⚠️ 請先選擇災害類型!");
return;
}
if (desc.isEmpty) {
_showDialog("⚠️ 請輸入簡易說明!");
return;
}
_showDialog("✅ 已通報「$type\n說明:「$desc");
}
void _showDialog(String message) {
showDialog(
context: context,
builder:
(_) => AlertDialog(
content: Text(message),
actions: [
TextButton(
child: const Text('確定'),
onPressed: () {
Navigator.pop(context); // 關閉 dialog
Navigator.pop(context); // 關閉 bottomSheet
},
),
],
),
);
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 40,
height: 5,
margin: const EdgeInsets.only(bottom: 15),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(10),
),
),
Image.network(
'https://cdn-icons-png.flaticon.com/512/564/564619.png',
width: 100,
),
const SizedBox(height: 15),
const Text('若遇緊急情況,請選擇災害類型後立即通報。'),
const SizedBox(height: 20),
Align(
alignment: Alignment.centerLeft,
child: Text(
'災害類型',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 8),
DropdownButtonFormField<String>(
decoration: const InputDecoration(border: OutlineInputBorder()),
value: _selectedType,
hint: const Text("請選擇..."),
items:
disasterTypes
.map(
(item) => DropdownMenuItem(
value: item['value'],
child: Text(item['label']!),
),
)
.toList(),
onChanged: (value) {
setState(() {
_selectedType = value;
});
},
),
const SizedBox(height: 20),
Align(
alignment: Alignment.centerLeft,
child: Text(
'簡易說明',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 8),
TextField(
controller: _descriptionController,
maxLines: 3,
decoration: const InputDecoration(
hintText: '請輸入簡要說明,例如地點或狀況...',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 25),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: _sendAlert,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
),
icon: const Icon(Icons.warning),
label: const Text('立即通報'),
),
),
],
),
),
),
);
}
}