velmart-picker/lib/features/slots/slots_screen.dart
Fibe Agent 5ba2691eac feat: initial Velmart Picker Flutter app
- All 5 batch steps: Picking, Sorting, Clarification, Slots, Handoff
- go_router navigation with step indicator
- graphql_flutter client wired up (endpoint via env var)
- Mock data layer swappable with real GraphQL service
- Item types: normal, cold, frozen, alcohol, clarify
- Storage slot assignment (cell/freezer/fridge)
2026-04-23 21:43:07 +00:00

197 lines
6.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../core/theme/app_theme.dart';
import '../../core/widgets/step_indicator.dart';
import '../../data/models/models.dart';
import '../../data/services/order_service.dart';
class SlotsScreen extends StatefulWidget {
final int orderId;
const SlotsScreen({super.key, required this.orderId});
@override
State<SlotsScreen> createState() => _SlotsScreenState();
}
class _SlotsScreenState extends State<SlotsScreen> {
final _service = MockOrderService();
Order? _order;
List<StorageSlot> _slots = [];
final Set<int> _selectedSlotIds = {};
bool _loading = true;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
final results = await Future.wait([
_service.getOrderDetail(widget.orderId),
_service.getAvailableSlots(),
]);
if (mounted) {
setState(() {
_order = results[0] as Order;
_slots = results[1] as List<StorageSlot>;
_loading = false;
});
}
}
bool get _needsFreezer => _order?.segments
.expand((s) => s.items)
.any((i) => i.type == ItemType.frozen && i.isCompleted) ??
false;
bool get _needsFridge => _order?.segments
.expand((s) => s.items)
.any((i) => i.type == ItemType.cold && i.isCompleted) ??
false;
List<StorageSlot> get _relevantSlots {
return _slots.where((s) {
if (s.type == StorageSlotType.cell) return true;
if (s.type == StorageSlotType.freezer && _needsFreezer) return true;
if (s.type == StorageSlotType.fridge && _needsFridge) return true;
return false;
}).toList();
}
Future<void> _confirmSlots() async {
if (_selectedSlotIds.isEmpty) return;
await _service.assignSlots(widget.orderId, _selectedSlotIds.toList());
if (mounted) context.push('/orders/${widget.orderId}/handoff');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(_order?.orderNumber ?? ''),
leading: IconButton(icon: const Icon(Icons.arrow_back), onPressed: () => context.pop()),
),
body: _loading
? const Center(child: CircularProgressIndicator())
: Column(
children: [
const StepIndicator(currentStep: BatchStep.slots),
Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Оберіть ячейки для зберігання',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
const SizedBox(height: 4),
Text(
'Обрано: ${_selectedSlotIds.length}',
style: const TextStyle(color: AppColors.textSecondary),
),
],
),
),
Expanded(
child: ListView(
padding: const EdgeInsets.symmetric(horizontal: 16),
children: [
_buildSlotGroup('Ячейки', StorageSlotType.cell),
if (_needsFreezer) _buildSlotGroup('Морозилка', StorageSlotType.freezer),
if (_needsFridge) _buildSlotGroup('Холодильник', StorageSlotType.fridge),
],
),
),
SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: ElevatedButton(
onPressed: _selectedSlotIds.isEmpty ? null : _confirmSlots,
child: const Text('Далі: Видача'),
),
),
),
],
),
);
}
Widget _buildSlotGroup(String title, StorageSlotType type) {
final slots = _relevantSlots.where((s) => s.type == type).toList();
if (slots.isEmpty) return const SizedBox.shrink();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text(title, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: AppColors.textSecondary)),
),
GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
childAspectRatio: 1.5,
),
itemCount: slots.length,
itemBuilder: (context, i) {
final slot = slots[i];
final selected = _selectedSlotIds.contains(slot.id);
return InkWell(
borderRadius: BorderRadius.circular(10),
onTap: () => setState(() {
if (selected) {
_selectedSlotIds.remove(slot.id);
} else {
_selectedSlotIds.add(slot.id);
}
}),
child: AnimatedContainer(
duration: const Duration(milliseconds: 150),
decoration: BoxDecoration(
color: selected ? AppColors.primary : Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: selected ? AppColors.primary : AppColors.divider,
width: 2,
),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
type == StorageSlotType.cell
? Icons.inbox
: type == StorageSlotType.freezer
? Icons.ac_unit
: Icons.kitchen,
color: selected ? Colors.white : AppColors.primary,
size: 20,
),
const SizedBox(height: 2),
Text(
slot.name,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: selected ? Colors.white : AppColors.textPrimary,
),
textAlign: TextAlign.center,
),
],
),
),
),
);
},
),
const SizedBox(height: 8),
],
);
}
}