feat(statistics): update district handling and improve dropdown components in statistics view

This commit is contained in:
vergiLgood1 2025-05-27 15:43:28 +07:00
parent 860481a093
commit b62c64d36d
4 changed files with 24 additions and 85 deletions

View File

@ -145,6 +145,7 @@ class StatisticsViewController extends GetxController {
);
currentDistrictId.value = district.id;
currentDistrict.value = district;
} catch (e) {
_logger.e('Error loading district data: $e');
}

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:sigap/src/features/panic/presentation/controllers/statistics_view_controller.dart';
import 'package:sigap/src/shared/widgets/dropdown/custom_dropdown.dart';
class CrimeStatsHeader extends StatelessWidget {
final String district;
@ -68,16 +67,14 @@ class CrimeStatsHeader extends StatelessWidget {
const SizedBox(height: 5),
// Date picker row with custom dropdowns
// Date picker row
Row(
children: [
const Icon(Icons.calendar_month, size: 16, color: Colors.blue),
const SizedBox(width: 10),
Expanded(child: _buildMonthDropdownCustom()),
const SizedBox(width: 10),
Expanded(
child: _buildYearDropdownCustom(statsController.availableYears),
),
const SizedBox(width: 5),
_buildMonthDropdown(),
const SizedBox(width: 5),
_buildYearDropdown(statsController.availableYears),
],
),
],
@ -85,13 +82,15 @@ class CrimeStatsHeader extends StatelessWidget {
);
}
// Custom month dropdown using the shared custom dropdown widget
Widget _buildMonthDropdownCustom() {
Widget _buildMonthDropdown() {
final int currentMonth = int.parse(month);
final monthName = DateFormat(
'MMMM',
).format(DateTime(int.parse(year), currentMonth));
return CustomDropdown<int>(
label: '',
return DropdownButton<int>(
value: currentMonth,
underline: Container(), // Remove underline
onChanged: (value) {
if (value != null) onMonthChanged(value);
},
@ -101,7 +100,7 @@ class CrimeStatsHeader extends StatelessWidget {
'MMMM',
).format(DateTime(int.parse(year), monthNum));
return DropdownMenuItem<int>(
return DropdownMenuItem(
value: monthNum,
child: Text(monthName, style: const TextStyle(fontSize: 14)),
);
@ -109,23 +108,21 @@ class CrimeStatsHeader extends StatelessWidget {
);
}
// Custom year dropdown using the shared custom dropdown widget
Widget _buildYearDropdownCustom(List<int> availableYears) {
Widget _buildYearDropdown(List<int> availableYears) {
final int currentYear = int.parse(year);
final selectedYear =
return DropdownButton<int>(
value:
availableYears.contains(currentYear)
? currentYear
: availableYears.last;
return CustomDropdown<int>(
label: '',
value: selectedYear,
: availableYears.last,
underline: Container(), // Remove underline
onChanged: (value) {
if (value != null) onYearChanged(value);
},
items:
availableYears.map((year) {
return DropdownMenuItem<int>(
return DropdownMenuItem(
value: year,
child: Text(
year.toString(),

View File

@ -2,8 +2,6 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sigap/src/features/panic/presentation/controllers/recovery_indicator_controller.dart';
import '../widgets/progress_arc_painter.dart';
class RecoveryIndicator extends StatelessWidget {
const RecoveryIndicator({super.key});
@ -48,63 +46,6 @@ class RecoveryIndicator extends StatelessWidget {
),
],
),
const SizedBox(height: 10),
Row(
children: [
Text(
controller.duration.value,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
const SizedBox(width: 8),
Text(
controller.timeLabel.value,
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
),
const Spacer(),
Stack(
alignment: Alignment.center,
children: [
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.grey.shade100,
),
),
SizedBox(
width: 45,
height: 45,
child: CustomPaint(
painter: ProgressArcPainter(
progress: controller.progress.value,
color: Colors.purple,
backgroundColor: Colors.grey.shade200,
strokeWidth: 4,
),
),
),
Container(
width: 25,
height: 25,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: const Icon(
Icons.security,
color: Colors.teal,
size: 16,
),
),
],
),
],
),
const SizedBox(height: 16),

View File

@ -147,8 +147,8 @@ class StatisticsView extends StatelessWidget {
// Helper to get color based on safety level
Color _getSafetyColor(double safety) {
if (safety >= 0.8) return Colors.green;
if (safety >= 0.6) return Colors.blue;
if (safety >= 0.3) return Colors.orange;
return Colors.red;
if (safety >= 0.6) return Colors.orange;
if (safety >= 0.3) return Colors.red;
return Colors.purple;
}
}