import 'package:sysfarma_mobile/src/core/network/api_client.dart'; import 'package:sysfarma_mobile/src/core/theme/app_tokens.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; class StocktakeItemKardexScreen extends ConsumerStatefulWidget { const StocktakeItemKardexScreen({ super.key, required this.countId, required this.itemId, }); final int countId; final int itemId; @override ConsumerState createState() => _StocktakeItemKardexScreenState(); } class _StocktakeItemKardexScreenState extends ConsumerState { late Future>> _future; @override void initState() { super.initState(); _future = _load(); } Future>> _load() async { final response = await ref .read(apiClientProvider) .physicalCountItemKardex(widget.countId, widget.itemId); return response.data ?? const >[]; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Kardex producto')), body: FutureBuilder>>( future: _future, builder: (context, snapshot) { final rows = snapshot.data ?? const >[]; return ListView( padding: AppTokens.pagePadding, children: [ if (snapshot.connectionState == ConnectionState.waiting) const Center(child: CircularProgressIndicator()) else if (rows.isEmpty) const Text('No hay movimientos para mostrar.') else ...rows.map((row) { final qty = double.tryParse('${row['quantity']}') ?? 0; return Card( margin: const EdgeInsets.only(bottom: 10), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), child: ListTile( leading: CircleAvatar( backgroundColor: (qty < 0 ? AppTokens.danger : AppTokens.success) .withValues(alpha: 0.12), child: Icon( qty < 0 ? Icons.south_west_rounded : Icons.north_east_rounded, color: qty < 0 ? AppTokens.danger : AppTokens.success, ), ), title: Text('${row['origin_type'] ?? 'Movimiento'} / ${row['quantity'] ?? 0}'), subtitle: Text('${row['date_of_issue'] ?? ''}\n${row['description'] ?? ''}'), isThreeLine: true, ), ); }), ], ); }, ), ); } }