Update: lib/screens/product_list_screen.dart

This commit is contained in:
Hadi Mottale 2025-07-08 12:35:20 +03:30
parent 5757d0f823
commit 25ad603299
1 changed files with 48 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../services/database_helper.dart'; import '../services/database_helper.dart';
import '../models/product.dart'; import '../models/product.dart';
import 'add_edit_product_screen.dart'; import 'add_edit_product_screen.dart';
@ -77,11 +78,54 @@ class _ProductListScreenState extends State<ProductListScreen> {
), ),
child: ListTile( child: ListTile(
leading: CircleAvatar( leading: CircleAvatar(
child: Text(product.quantity.toString()), backgroundColor: Colors.grey[200],
backgroundImage:
product.imageUrl != null &&
product.imageUrl!.startsWith('http')
? NetworkImage(product.imageUrl!)
as ImageProvider<Object>?
: null,
child:
product.imageUrl == null ||
!product.imageUrl!.startsWith('http')
? const Icon(
Icons.inventory_2,
color: Colors.blueGrey,
)
: null,
), ),
title: Text(product.name), title: Text(product.name),
subtitle: Text( subtitle: Column(
'کد: ${product.code} | قیمت: ${product.price} تومان', crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'کد: ${product.code} | قیمت: ${product.price} تومان',
),
if (product.category != null || product.brand != null)
Text(
'دسته: ${product.category ?? 'نامشخص'} | برند: ${product.brand ?? 'نامشخص'}',
style: TextStyle(
color: Colors.grey[700],
fontSize: 12,
),
),
if (product.location != null)
Text(
'موقعیت: ${product.location}',
style: TextStyle(
color: Colors.grey[700],
fontSize: 12,
),
),
if (product.expirationDate != null)
Text(
'انقضا: ${DateFormat('yyyy-MM-dd').format(product.expirationDate!)}',
style: TextStyle(
color: Colors.red[700],
fontSize: 12,
),
),
],
), ),
trailing: Row( trailing: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -110,8 +154,7 @@ class _ProductListScreenState extends State<ProductListScreen> {
TextButton( TextButton(
onPressed: () { onPressed: () {
_deleteProduct(product.id!); _deleteProduct(product.id!);
if (!mounted) if (!mounted) return;
return; // Add this check
Navigator.pop(context); Navigator.pop(context);
}, },
child: const Text('بله'), child: const Text('بله'),