baligh_dashboard/lib/screens/report_details_screen.dart
Abdullah Salah cf9784f468 First Commit
2024-12-26 09:10:35 +03:00

245 lines
7.7 KiB
Dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:baligh_dashboard/utils/file_classification.dart';
import 'package:baligh_dashboard/widgets/app_toast.dart';
import 'package:baligh_dashboard/widgets/dashboard_tile.dart';
import 'package:baligh_dashboard/widgets/file_card.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class ReportDetailsScreen extends StatefulWidget {
const ReportDetailsScreen({
super.key,
required this.id,
required this.name,
required this.address,
required this.school,
required this.type,
required this.status,
required this.age,
required this.attachments,
required this.createdAt,
required this.description,
required this.nationalIdNumber,
required this.phone,
});
final String id;
final String name;
final String address;
final String school;
final String type;
final String status;
final Timestamp createdAt;
final int age;
final String phone;
final int nationalIdNumber;
final String description;
final List attachments;
@override
State<ReportDetailsScreen> createState() => _ReportDetailsScreenState();
}
class _ReportDetailsScreenState extends State<ReportDetailsScreen> {
String selectedStatus = "قيد الانتظار";
List<String> availableStatus = [
"قيد الانتظار",
"قيد المعالجة",
"مكتمل",
];
@override
void initState() {
setState(() {
selectedStatus = widget.status;
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
body: SafeArea(
child: ListView(
padding: const EdgeInsets.symmetric(horizontal: 15),
children: [
const SizedBox(
height: 50,
),
AutoSizeText(
"تفاصيل البلاغ",
style: Theme.of(context).textTheme.titleLarge,
minFontSize: 12,
),
const SizedBox(
height: 30,
),
Wrap(
children: [
Text(
"حالة البلاغ:",
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(
width: 5,
),
DropdownMenu<String>(
initialSelection: "قيد الانتظار",
label: const Text("الحالة"),
onSelected: (String? value) async {
var old = selectedStatus;
setState(() {
selectedStatus = value ?? "قيد الانتظار";
});
try {
await FirebaseFirestore.instance
.collection("reports")
.doc(widget.id)
.update({
'status': selectedStatus,
});
} catch (e) {
setState(() {
selectedStatus = old;
});
BotToast.showCustomText(toastBuilder: (_) {
return const AppToast(text: "حدث خطأ ما");
});
}
},
dropdownMenuEntries:
availableStatus.map<DropdownMenuEntry<String>>((value) {
return DropdownMenuEntry<String>(
value: value,
label: value,
);
}).toList(),
),
],
),
const SizedBox(
height: 15,
),
Row(
children: [
Expanded(
child: AutoSizeText(
"اسم صاحب البلاغ",
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 3,
minFontSize: 8,
),
),
const SizedBox(
width: 5,
),
Expanded(
child: AutoSizeText(
"عنوان صاحب البلاغ",
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 3,
minFontSize: 8,
),
),
const SizedBox(
width: 5,
),
Expanded(
child: AutoSizeText(
"المدرسة",
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 3,
minFontSize: 8,
),
),
const SizedBox(
width: 5,
),
Expanded(
child: AutoSizeText(
"نوع البلاغ",
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 3,
minFontSize: 8,
),
),
const SizedBox(
width: 5,
),
Expanded(
child: AutoSizeText(
"الحالة",
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 3,
minFontSize: 8,
),
),
],
),
const SizedBox(
height: 10,
),
DashboardTile(
id: widget.id,
name: widget.name,
age: widget.age,
phone: widget.phone,
address: widget.address,
school: widget.school,
nationalIdNumber: widget.nationalIdNumber,
description: widget.description,
attachments: widget.attachments,
type: widget.type,
createdAt: widget.createdAt,
status: widget.status,
),
const SizedBox(
height: 20,
),
AutoSizeText(
"وصف البلاغ",
style: Theme.of(context).textTheme.bodyLarge,
minFontSize: 12,
),
const SizedBox(
height: 10,
),
Text(
widget.description,
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(
height: 20,
),
AutoSizeText(
"الملفات المرفقة",
style: Theme.of(context).textTheme.bodyLarge,
minFontSize: 12,
),
const SizedBox(
height: 10,
),
Wrap(
children: widget.attachments
.map(
(el) => FileCard(
type: FileClassification.getFileClass(el),
filename: FileClassification.getFileName(el) ?? "",
fileUrl: el,),
)
.toList(),
),
const SizedBox(
height: 30,
),
],
),
),
),
);
}
}