refactor: split registration page into focused parts
This commit is contained in:
161
lib/pages/registration/registration_calculations.dart
Normal file
161
lib/pages/registration/registration_calculations.dart
Normal file
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pad_scanner/services/api_service.dart';
|
||||
|
||||
class RegistrationOverviewStats {
|
||||
final int totalCount;
|
||||
final int shelvedCount;
|
||||
final int transferredCount;
|
||||
|
||||
const RegistrationOverviewStats({
|
||||
required this.totalCount,
|
||||
required this.shelvedCount,
|
||||
required this.transferredCount,
|
||||
});
|
||||
}
|
||||
|
||||
class RegistrationOverviewSections {
|
||||
final List<PaichaOverviewItem> scanned;
|
||||
final List<PaichaOverviewItem> unscanned;
|
||||
|
||||
const RegistrationOverviewSections({
|
||||
required this.scanned,
|
||||
required this.unscanned,
|
||||
});
|
||||
|
||||
bool get hasDivider => scanned.isNotEmpty && unscanned.isNotEmpty;
|
||||
}
|
||||
|
||||
RegistrationOverviewStats overviewStats(PaichaOverviewResult? overview) {
|
||||
if (overview?.success != true) {
|
||||
return const RegistrationOverviewStats(
|
||||
totalCount: 0,
|
||||
shelvedCount: 0,
|
||||
transferredCount: 0,
|
||||
);
|
||||
}
|
||||
|
||||
var shelvedCount = 0;
|
||||
var transferredCount = 0;
|
||||
for (final item in overview!.items) {
|
||||
switch (item.status) {
|
||||
case 'on_shelf':
|
||||
shelvedCount++;
|
||||
case 'transferred':
|
||||
transferredCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return RegistrationOverviewStats(
|
||||
totalCount: overview.totalCount,
|
||||
shelvedCount: shelvedCount,
|
||||
transferredCount: transferredCount,
|
||||
);
|
||||
}
|
||||
|
||||
RegistrationOverviewSections splitOverviewItems({
|
||||
required PaichaOverviewResult overview,
|
||||
required Iterable<String> zongpaiNos,
|
||||
}) {
|
||||
final scannedSet = zongpaiNos.toSet();
|
||||
final scanned = <PaichaOverviewItem>[];
|
||||
final unscanned = <PaichaOverviewItem>[];
|
||||
for (final item in overview.items) {
|
||||
if (scannedSet.contains(item.zongpaiNo)) {
|
||||
scanned.add(item);
|
||||
} else {
|
||||
unscanned.add(item);
|
||||
}
|
||||
}
|
||||
return RegistrationOverviewSections(scanned: scanned, unscanned: unscanned);
|
||||
}
|
||||
|
||||
List<PaichaOverviewItem> findOnShelfItemsInScanned({
|
||||
required PaichaOverviewResult? overview,
|
||||
required Iterable<String> zongpaiNos,
|
||||
}) {
|
||||
return _findScannedItemsByStatus(
|
||||
overview: overview,
|
||||
zongpaiNos: zongpaiNos,
|
||||
status: 'on_shelf',
|
||||
);
|
||||
}
|
||||
|
||||
List<PaichaOverviewItem> findTransferredItemsInScanned({
|
||||
required PaichaOverviewResult? overview,
|
||||
required Iterable<String> zongpaiNos,
|
||||
}) {
|
||||
return _findScannedItemsByStatus(
|
||||
overview: overview,
|
||||
zongpaiNos: zongpaiNos,
|
||||
status: 'transferred',
|
||||
);
|
||||
}
|
||||
|
||||
bool hasAnyLocatedInScanned({
|
||||
required PaichaOverviewResult? overview,
|
||||
required Iterable<String> zongpaiNos,
|
||||
}) {
|
||||
if (overview?.success != true) return false;
|
||||
final scannedSet = zongpaiNos.toSet();
|
||||
return overview!.items.any(
|
||||
(item) =>
|
||||
scannedSet.contains(item.zongpaiNo) &&
|
||||
(item.status == 'on_shelf' || item.status == 'transferred'),
|
||||
);
|
||||
}
|
||||
|
||||
Color registrationBarColor({
|
||||
required String status,
|
||||
required bool isScanned,
|
||||
required bool isTransitTarget,
|
||||
}) {
|
||||
if (isScanned) {
|
||||
return status == 'on_shelf' && !isTransitTarget
|
||||
? Colors.red
|
||||
: const Color(0xFF43A047);
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case 'on_shelf':
|
||||
return const Color(0xFF2196F3);
|
||||
case 'transferred':
|
||||
return const Color(0xFFFF9800);
|
||||
default:
|
||||
return Colors.grey.shade400;
|
||||
}
|
||||
}
|
||||
|
||||
Color registrationRowBgColor({
|
||||
required String status,
|
||||
required bool isScanned,
|
||||
required bool isTransitTarget,
|
||||
}) {
|
||||
if (isScanned) {
|
||||
return status == 'on_shelf' && !isTransitTarget
|
||||
? Colors.red.shade50
|
||||
: const Color(0xFFF1F8E9);
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case 'on_shelf':
|
||||
return const Color(0xFFE3F2FD);
|
||||
case 'transferred':
|
||||
return const Color(0xFFFFF3E0);
|
||||
default:
|
||||
return const Color(0xFFF5F5F5);
|
||||
}
|
||||
}
|
||||
|
||||
List<PaichaOverviewItem> _findScannedItemsByStatus({
|
||||
required PaichaOverviewResult? overview,
|
||||
required Iterable<String> zongpaiNos,
|
||||
required String status,
|
||||
}) {
|
||||
if (overview?.success != true) return [];
|
||||
final scannedSet = zongpaiNos.toSet();
|
||||
return overview!.items
|
||||
.where(
|
||||
(item) => scannedSet.contains(item.zongpaiNo) && item.status == status,
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
Reference in New Issue
Block a user