feat: inventory
This commit is contained in:
@@ -1,63 +1,33 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../application/analytic/inventory_analytic_loader/inventory_analytic_loader_bloc.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../domain/analytic/analytic.dart';
|
||||
import '../../../injection.dart';
|
||||
import '../../components/appbar/appbar.dart';
|
||||
import 'widgets/ingredient_tile.dart';
|
||||
import 'widgets/product_tile.dart';
|
||||
import 'widgets/stat_card.dart';
|
||||
import 'widgets/tabbar_delegate.dart';
|
||||
|
||||
// Sample inventory data for products
|
||||
class ProductItem {
|
||||
final String id;
|
||||
final String name;
|
||||
final String category;
|
||||
final int quantity;
|
||||
final double price;
|
||||
final String status;
|
||||
final String image;
|
||||
|
||||
ProductItem({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.category,
|
||||
required this.quantity,
|
||||
required this.price,
|
||||
required this.status,
|
||||
required this.image,
|
||||
});
|
||||
}
|
||||
|
||||
// Sample inventory data for ingredients
|
||||
class IngredientItem {
|
||||
final String id;
|
||||
final String name;
|
||||
final String unit;
|
||||
final double quantity;
|
||||
final double minQuantity;
|
||||
final String status;
|
||||
final String image;
|
||||
|
||||
IngredientItem({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.unit,
|
||||
required this.quantity,
|
||||
required this.minQuantity,
|
||||
required this.status,
|
||||
required this.image,
|
||||
});
|
||||
}
|
||||
|
||||
// Custom SliverPersistentHeaderDelegate untuk TabBar
|
||||
|
||||
@RoutePage()
|
||||
class InventoryPage extends StatefulWidget {
|
||||
class InventoryPage extends StatefulWidget implements AutoRouteWrapper {
|
||||
const InventoryPage({super.key});
|
||||
|
||||
@override
|
||||
State<InventoryPage> createState() => _InventoryPageState();
|
||||
|
||||
@override
|
||||
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
||||
create: (_) =>
|
||||
getIt<InventoryAnalyticLoaderBloc>()
|
||||
..add(InventoryAnalyticLoaderEvent.fetched()),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
class _InventoryPageState extends State<InventoryPage>
|
||||
@@ -68,111 +38,6 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
late Animation<Offset> _slideAnimation;
|
||||
late TabController _tabController;
|
||||
|
||||
final List<ProductItem> productItems = [
|
||||
ProductItem(
|
||||
id: '1',
|
||||
name: 'Laptop Gaming ASUS ROG',
|
||||
category: 'Elektronik',
|
||||
quantity: 5,
|
||||
price: 15000000,
|
||||
status: 'available',
|
||||
image: '💻',
|
||||
),
|
||||
ProductItem(
|
||||
id: '2',
|
||||
name: 'Kemeja Formal Pria',
|
||||
category: 'Fashion',
|
||||
quantity: 25,
|
||||
price: 250000,
|
||||
status: 'available',
|
||||
image: '👔',
|
||||
),
|
||||
ProductItem(
|
||||
id: '3',
|
||||
name: 'Smartphone Samsung Galaxy',
|
||||
category: 'Elektronik',
|
||||
quantity: 12,
|
||||
price: 8500000,
|
||||
status: 'available',
|
||||
image: '📱',
|
||||
),
|
||||
ProductItem(
|
||||
id: '4',
|
||||
name: 'Tas Ransel Travel',
|
||||
category: 'Fashion',
|
||||
quantity: 8,
|
||||
price: 350000,
|
||||
status: 'low_stock',
|
||||
image: '🎒',
|
||||
),
|
||||
ProductItem(
|
||||
id: '4',
|
||||
name: 'Tas Ransel Travel',
|
||||
category: 'Fashion',
|
||||
quantity: 8,
|
||||
price: 350000,
|
||||
status: 'low_stock',
|
||||
image: '🎒',
|
||||
),
|
||||
ProductItem(
|
||||
id: '4',
|
||||
name: 'Tas Ransel Travel',
|
||||
category: 'Fashion',
|
||||
quantity: 8,
|
||||
price: 350000,
|
||||
status: 'low_stock',
|
||||
image: '🎒',
|
||||
),
|
||||
];
|
||||
|
||||
final List<IngredientItem> ingredientItems = [
|
||||
IngredientItem(
|
||||
id: '1',
|
||||
name: 'Tepung Terigu',
|
||||
unit: 'kg',
|
||||
quantity: 50.5,
|
||||
minQuantity: 10.0,
|
||||
status: 'available',
|
||||
image: '🌾',
|
||||
),
|
||||
IngredientItem(
|
||||
id: '2',
|
||||
name: 'Gula Pasir',
|
||||
unit: 'kg',
|
||||
quantity: 2.5,
|
||||
minQuantity: 5.0,
|
||||
status: 'low_stock',
|
||||
image: '🍬',
|
||||
),
|
||||
IngredientItem(
|
||||
id: '3',
|
||||
name: 'Telur Ayam',
|
||||
unit: 'butir',
|
||||
quantity: 120,
|
||||
minQuantity: 50,
|
||||
status: 'available',
|
||||
image: '🥚',
|
||||
),
|
||||
IngredientItem(
|
||||
id: '4',
|
||||
name: 'Susu Segar',
|
||||
unit: 'liter',
|
||||
quantity: 0,
|
||||
minQuantity: 10.0,
|
||||
status: 'out_of_stock',
|
||||
image: '🥛',
|
||||
),
|
||||
IngredientItem(
|
||||
id: '5',
|
||||
name: 'Mentega',
|
||||
unit: 'kg',
|
||||
quantity: 15.2,
|
||||
minQuantity: 5.0,
|
||||
status: 'available',
|
||||
image: '🧈',
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -244,95 +109,118 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.background,
|
||||
body: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: SlideTransition(
|
||||
position: _slideAnimation,
|
||||
child: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) {
|
||||
return [
|
||||
_buildSliverAppBar(),
|
||||
SliverPersistentHeader(
|
||||
pinned: true,
|
||||
delegate: InventorySliverTabBarDelegate(
|
||||
tabBar: TabBar(
|
||||
body:
|
||||
BlocBuilder<
|
||||
InventoryAnalyticLoaderBloc,
|
||||
InventoryAnalyticLoaderState
|
||||
>(
|
||||
builder: (context, state) {
|
||||
return FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: SlideTransition(
|
||||
position: _slideAnimation,
|
||||
child: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) {
|
||||
return [
|
||||
_buildSliverAppBar(),
|
||||
SliverPersistentHeader(
|
||||
pinned: true,
|
||||
delegate: InventorySliverTabBarDelegate(
|
||||
tabBar: TabBar(
|
||||
controller: _tabController,
|
||||
indicator: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: AppColor.primaryGradient,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColor.primary.withOpacity(0.3),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
indicatorPadding: const EdgeInsets.all(6),
|
||||
labelColor: AppColor.textWhite,
|
||||
unselectedLabelColor: AppColor.textSecondary,
|
||||
labelStyle: const TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 13,
|
||||
),
|
||||
unselectedLabelStyle: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 13,
|
||||
),
|
||||
dividerColor: Colors.transparent,
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
overlayColor: MaterialStateProperty.all(
|
||||
Colors.transparent,
|
||||
),
|
||||
tabs: [
|
||||
Tab(
|
||||
height: 40,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.inventory_2_rounded,
|
||||
size: 16,
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
Text('Produk'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Tab(
|
||||
height: 40,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.restaurant_menu_rounded,
|
||||
size: 16,
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
Text('Bahan'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
body: TabBarView(
|
||||
controller: _tabController,
|
||||
indicator: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: AppColor.primaryGradient,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColor.primary.withOpacity(0.3),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
indicatorPadding: const EdgeInsets.all(6),
|
||||
labelColor: AppColor.textWhite,
|
||||
unselectedLabelColor: AppColor.textSecondary,
|
||||
labelStyle: const TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 13,
|
||||
),
|
||||
unselectedLabelStyle: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 13,
|
||||
),
|
||||
dividerColor: Colors.transparent,
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
overlayColor: MaterialStateProperty.all(
|
||||
Colors.transparent,
|
||||
),
|
||||
tabs: [
|
||||
Tab(
|
||||
height: 40,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.inventory_2_rounded, size: 16),
|
||||
SizedBox(width: 6),
|
||||
Text('Produk'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Tab(
|
||||
height: 40,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.restaurant_menu_rounded, size: 16),
|
||||
SizedBox(width: 6),
|
||||
Text('Bahan'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
children: [
|
||||
_buildProductTab(state.inventoryAnalytic),
|
||||
_buildIngredientTab(state.inventoryAnalytic),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
);
|
||||
},
|
||||
body: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [_buildProductTab(), _buildIngredientTab()],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -347,41 +235,19 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProductTab() {
|
||||
Widget _buildProductTab(InventoryAnalytic inventoryAnalytic) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: _buildProductStats()),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
childAspectRatio: 0.75,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) =>
|
||||
InventoryProductTile(item: productItems[index]),
|
||||
childCount: productItems.length,
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: _buildProductStats(inventoryAnalytic.summary),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIngredientTab() {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: _buildIngredientStats()),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) =>
|
||||
InventoryIngredientTile(item: ingredientItems[index]),
|
||||
childCount: ingredientItems.length,
|
||||
InventoryProductTile(item: inventoryAnalytic.products[index]),
|
||||
childCount: inventoryAnalytic.products.length,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -389,15 +255,28 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProductStats() {
|
||||
final totalProducts = productItems.length;
|
||||
final availableProducts = productItems
|
||||
.where((item) => item.status == 'available')
|
||||
.length;
|
||||
final lowStockProducts = productItems
|
||||
.where((item) => item.status == 'low_stock')
|
||||
.length;
|
||||
Widget _buildIngredientTab(InventoryAnalytic inventoryAnalytic) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: _buildIngredientStats(inventoryAnalytic.summary),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) => InventoryIngredientTile(
|
||||
item: inventoryAnalytic.ingredients[index],
|
||||
),
|
||||
childCount: inventoryAnalytic.ingredients.length,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProductStats(InventorySummary inventory) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
@@ -407,20 +286,18 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
Expanded(
|
||||
child: _buildStatCard(
|
||||
'Total Produk',
|
||||
totalProducts.toString(),
|
||||
inventory.totalProducts.toString(),
|
||||
Icons.inventory_2_rounded,
|
||||
AppColor.primary,
|
||||
'+12%',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: _buildStatCard(
|
||||
'Tersedia',
|
||||
availableProducts.toString(),
|
||||
'Produk Terjual',
|
||||
inventory.totalSoldProducts.toString(),
|
||||
Icons.check_circle_rounded,
|
||||
AppColor.success,
|
||||
'+5%',
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -431,15 +308,19 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
Expanded(
|
||||
child: _buildStatCard(
|
||||
'Stok Rendah',
|
||||
lowStockProducts.toString(),
|
||||
inventory.lowStockProducts.toString(),
|
||||
Icons.warning_rounded,
|
||||
AppColor.warning,
|
||||
'-8%',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Container(), // Empty space for balance
|
||||
child: _buildStatCard(
|
||||
'Stok Kosong',
|
||||
inventory.zeroStockProducts.toString(),
|
||||
Icons.error_rounded,
|
||||
AppColor.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -448,18 +329,7 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIngredientStats() {
|
||||
final totalIngredients = ingredientItems.length;
|
||||
final availableIngredients = ingredientItems
|
||||
.where((item) => item.status == 'available')
|
||||
.length;
|
||||
final lowStockIngredients = ingredientItems
|
||||
.where((item) => item.status == 'low_stock')
|
||||
.length;
|
||||
final outOfStockIngredients = ingredientItems
|
||||
.where((item) => item.status == 'out_of_stock')
|
||||
.length;
|
||||
|
||||
Widget _buildIngredientStats(InventorySummary inventory) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
@@ -469,20 +339,18 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
Expanded(
|
||||
child: _buildStatCard(
|
||||
'Total Bahan',
|
||||
totalIngredients.toString(),
|
||||
inventory.totalIngredients.toString(),
|
||||
Icons.restaurant_menu_rounded,
|
||||
AppColor.primary,
|
||||
'+8%',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: _buildStatCard(
|
||||
'Tersedia',
|
||||
availableIngredients.toString(),
|
||||
'Bahan Terjual',
|
||||
inventory.totalSoldIngredients.toString(),
|
||||
Icons.check_circle_rounded,
|
||||
AppColor.success,
|
||||
'+15%',
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -493,20 +361,18 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
Expanded(
|
||||
child: _buildStatCard(
|
||||
'Stok Kurang',
|
||||
lowStockIngredients.toString(),
|
||||
inventory.lowStockIngredients.toString(),
|
||||
Icons.warning_rounded,
|
||||
AppColor.warning,
|
||||
'-3%',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: _buildStatCard(
|
||||
'Habis',
|
||||
outOfStockIngredients.toString(),
|
||||
inventory.zeroStockIngredients.toString(),
|
||||
Icons.error_rounded,
|
||||
AppColor.error,
|
||||
'+1',
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -521,7 +387,6 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
String value,
|
||||
IconData icon,
|
||||
Color color,
|
||||
String change,
|
||||
) {
|
||||
return TweenAnimationBuilder<double>(
|
||||
tween: Tween<double>(begin: 0, end: 1),
|
||||
@@ -534,7 +399,6 @@ class _InventoryPageState extends State<InventoryPage>
|
||||
value: value,
|
||||
icon: icon,
|
||||
color: color,
|
||||
change: change,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:line_icons/line_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../../common/extension/extension.dart';
|
||||
import '../../../../common/theme/theme.dart';
|
||||
import '../../../../domain/analytic/analytic.dart';
|
||||
import '../../../components/spacer/spacer.dart';
|
||||
import '../inventory_page.dart';
|
||||
|
||||
class InventoryIngredientTile extends StatelessWidget {
|
||||
final IngredientItem item;
|
||||
final InventoryIngredient item;
|
||||
const InventoryIngredientTile({super.key, required this.item});
|
||||
|
||||
@override
|
||||
@@ -16,94 +19,458 @@ class InventoryIngredientTile extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: _getStatusColor().withOpacity(0.2),
|
||||
width: 1.5,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColor.primaryWithOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
color: _getStatusColor().withOpacity(0.08),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
BoxShadow(
|
||||
color: AppColor.textLight.withOpacity(0.06),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: AppColor.backgroundGradient),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(item.image, style: const TextStyle(fontSize: 24)),
|
||||
),
|
||||
),
|
||||
const SpaceWidth(16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.name,
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.textPrimary,
|
||||
// Main Row
|
||||
Row(
|
||||
children: [
|
||||
// Enhanced Icon Container
|
||||
Container(
|
||||
width: 65,
|
||||
height: 65,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: _getGradientColors(),
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _getStatusColor().withOpacity(0.2),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
SpaceHeight(4),
|
||||
Text(
|
||||
'Stok: ${item.quantity} ${item.unit}',
|
||||
style: AppStyle.md.copyWith(color: AppColor.textSecondary),
|
||||
child: Stack(
|
||||
children: [
|
||||
Center(
|
||||
child: Icon(
|
||||
_getIngredientIcon(),
|
||||
size: 28,
|
||||
color: AppColor.white,
|
||||
),
|
||||
),
|
||||
// Status indicator dot
|
||||
Positioned(
|
||||
top: 6,
|
||||
right: 6,
|
||||
child: Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: _getStatusColor(),
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SpaceHeight(4),
|
||||
Text(
|
||||
'Min: ${item.minQuantity} ${item.unit}',
|
||||
style: AppStyle.sm.copyWith(color: AppColor.textSecondary),
|
||||
),
|
||||
|
||||
const SpaceWidth(16),
|
||||
|
||||
// Content Section
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Ingredient Name
|
||||
Text(
|
||||
item.ingredientName,
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColor.textPrimary,
|
||||
height: 1.2,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
||||
SpaceHeight(6),
|
||||
|
||||
// Stock Information Row
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
LineIcons.warehouse,
|
||||
size: 14,
|
||||
color: AppColor.textSecondary,
|
||||
),
|
||||
const SpaceWidth(4),
|
||||
Text(
|
||||
'Stok: ',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${NumberFormat('#,###', 'id_ID').format(item.quantity)} ${item.unitName}',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: _getQuantityColor(),
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SpaceHeight(4),
|
||||
|
||||
// Reorder Level Information
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
LineIcons.exclamationTriangle,
|
||||
size: 14,
|
||||
color: AppColor.warning,
|
||||
),
|
||||
const SpaceWidth(4),
|
||||
Text(
|
||||
'Min: ',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${NumberFormat('#,###', 'id_ID').format(item.reorderLevel)} ${item.unitName}',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.warning,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SpaceHeight(6),
|
||||
|
||||
// Unit Cost
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
LineIcons.dollarSign,
|
||||
size: 14,
|
||||
color: AppColor.success,
|
||||
),
|
||||
const SpaceWidth(4),
|
||||
Text(
|
||||
item.unitCost.currencyFormatRp,
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.success,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'/${item.unitName}',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Status Badge
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _getStatusColor().withOpacity(0.3),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_getStatusText(),
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColor.white,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: getStatusColor(item.status),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
getStatusText(item.status),
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.textWhite,
|
||||
|
||||
// Additional Information Card (if low stock or has movements)
|
||||
if (item.isLowStock || item.totalIn > 0 || item.totalOut > 0) ...[
|
||||
SpaceHeight(12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.background,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColor.borderLight, width: 0.5),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Warning message for low stock
|
||||
if (item.isLowStock && !item.isZeroStock) ...[
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
LineIcons.exclamationTriangle,
|
||||
size: 16,
|
||||
color: AppColor.warning,
|
||||
),
|
||||
const SpaceWidth(6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Stok mendekati batas minimum (${item.reorderLevel} ${item.unitName})',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.warning,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (item.totalIn > 0 || item.totalOut > 0) SpaceHeight(8),
|
||||
],
|
||||
|
||||
// Movement Information
|
||||
if (item.totalIn > 0 || item.totalOut > 0)
|
||||
Row(
|
||||
children: [
|
||||
// Stock In
|
||||
if (item.totalIn > 0) ...[
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.success.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Icon(
|
||||
LineIcons.arrowUp,
|
||||
size: 12,
|
||||
color: AppColor.success,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(6),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Masuk',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${NumberFormat('#,###', 'id_ID').format(item.totalIn)} ${item.unitName}',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.success,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// Stock Out
|
||||
if (item.totalOut > 0) ...[
|
||||
if (item.totalIn > 0) const SpaceWidth(16),
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.error.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Icon(
|
||||
LineIcons.arrowDown,
|
||||
size: 12,
|
||||
color: AppColor.error,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(6),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Keluar',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${NumberFormat('#,###', 'id_ID').format(item.totalOut)} ${item.unitName}',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.error,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// Total Value
|
||||
if (item.totalValue > 0) ...[
|
||||
const SpaceWidth(16),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'Nilai Total',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_formatCurrencyShort(item.totalValue),
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.info,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color getStatusColor(String status) {
|
||||
switch (status) {
|
||||
case 'available':
|
||||
return AppColor.success;
|
||||
case 'low_stock':
|
||||
return AppColor.warning;
|
||||
case 'out_of_stock':
|
||||
return AppColor.error;
|
||||
default:
|
||||
return AppColor.textSecondary;
|
||||
}
|
||||
// Helper methods
|
||||
Color _getStatusColor() {
|
||||
if (item.isZeroStock) return AppColor.error;
|
||||
if (item.isLowStock) return AppColor.warning;
|
||||
return AppColor.success;
|
||||
}
|
||||
|
||||
String getStatusText(String status) {
|
||||
switch (status) {
|
||||
case 'available':
|
||||
return 'Tersedia';
|
||||
case 'low_stock':
|
||||
return 'Stok Rendah';
|
||||
case 'out_of_stock':
|
||||
return 'Habis';
|
||||
default:
|
||||
return 'Unknown';
|
||||
List<Color> _getGradientColors() {
|
||||
if (item.isZeroStock) {
|
||||
return [AppColor.error, AppColor.error.withOpacity(0.7)];
|
||||
}
|
||||
if (item.isLowStock) {
|
||||
return [AppColor.warning, AppColor.warning.withOpacity(0.7)];
|
||||
}
|
||||
return [AppColor.success, AppColor.success.withOpacity(0.7)];
|
||||
}
|
||||
|
||||
Color _getQuantityColor() {
|
||||
if (item.isZeroStock) return AppColor.error;
|
||||
if (item.isLowStock) return AppColor.warning;
|
||||
return AppColor.textPrimary;
|
||||
}
|
||||
|
||||
String _getStatusText() {
|
||||
if (item.isZeroStock) return 'HABIS';
|
||||
if (item.isLowStock) return 'MINIM';
|
||||
return 'TERSEDIA';
|
||||
}
|
||||
|
||||
IconData _getIngredientIcon() {
|
||||
final name = item.ingredientName.toLowerCase();
|
||||
|
||||
// Food ingredients
|
||||
if (name.contains('tepung') || name.contains('flour')) {
|
||||
return LineIcons.breadSlice;
|
||||
} else if (name.contains('gula') || name.contains('sugar')) {
|
||||
return LineIcons.cube;
|
||||
} else if (name.contains('garam') || name.contains('salt')) {
|
||||
return LineIcons.breadSlice;
|
||||
} else if (name.contains('minyak') || name.contains('oil')) {
|
||||
return LineIcons.tint;
|
||||
} else if (name.contains('susu') || name.contains('milk')) {
|
||||
return LineIcons.glasses;
|
||||
} else if (name.contains('telur') || name.contains('egg')) {
|
||||
return LineIcons.egg;
|
||||
} else if (name.contains('daging') || name.contains('meat')) {
|
||||
return LineIcons.hamburger;
|
||||
} else if (name.contains('sayur') || name.contains('vegetable')) {
|
||||
return LineIcons.carrot;
|
||||
} else if (name.contains('bumbu') || name.contains('spice')) {
|
||||
return LineIcons.leaf;
|
||||
} else if (name.contains('buah') || name.contains('fruit')) {
|
||||
return LineIcons.apple;
|
||||
} else if (name.contains('beras') || name.contains('rice')) {
|
||||
return LineIcons.seedling;
|
||||
} else if (name.contains('kopi') || name.contains('coffee')) {
|
||||
return LineIcons.coffee;
|
||||
}
|
||||
|
||||
// Default ingredient icon
|
||||
return LineIcons.utensils;
|
||||
}
|
||||
|
||||
String _formatCurrencyShort(int amount) {
|
||||
if (amount.abs() >= 1000000000) {
|
||||
return 'Rp ${(amount / 1000000000).toStringAsFixed(1)}B';
|
||||
} else if (amount.abs() >= 1000000) {
|
||||
return 'Rp ${(amount / 1000000).toStringAsFixed(1)}M';
|
||||
} else if (amount.abs() >= 1000) {
|
||||
return 'Rp ${(amount / 1000).toStringAsFixed(0)}K';
|
||||
} else {
|
||||
return 'Rp ${NumberFormat('#,###', 'id_ID').format(amount)}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,154 +1,514 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:line_icons/line_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../../common/extension/extension.dart';
|
||||
import '../../../../common/theme/theme.dart';
|
||||
import '../../../../domain/analytic/analytic.dart';
|
||||
import '../../../components/spacer/spacer.dart';
|
||||
import '../inventory_page.dart';
|
||||
|
||||
class InventoryProductTile extends StatelessWidget {
|
||||
final ProductItem item;
|
||||
final InventoryProduct item;
|
||||
const InventoryProductTile({super.key, required this.item});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColor.primary.withOpacity(0.08), width: 1),
|
||||
border: Border.all(
|
||||
color: _getStatusColor().withOpacity(0.2),
|
||||
width: 1.5,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColor.primary.withOpacity(0.06),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
color: _getStatusColor().withOpacity(0.06),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 6),
|
||||
),
|
||||
BoxShadow(
|
||||
color: AppColor.textLight.withOpacity(0.08),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Image Container
|
||||
Container(
|
||||
height: 85,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: AppColor.backgroundGradient,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
// Main Content Row
|
||||
Row(
|
||||
children: [
|
||||
// Enhanced Product Icon
|
||||
Container(
|
||||
width: 70,
|
||||
height: 70,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.textWhite.withOpacity(0.9),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
gradient: LinearGradient(
|
||||
colors: _getGradientColors(),
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _getStatusColor().withOpacity(0.25),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Center(
|
||||
child: Icon(
|
||||
_getCategoryIcon(),
|
||||
size: 32,
|
||||
color: AppColor.white,
|
||||
),
|
||||
),
|
||||
// Status indicator
|
||||
Positioned(
|
||||
top: 6,
|
||||
right: 6,
|
||||
child: Container(
|
||||
width: 14,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: _getStatusColor(),
|
||||
width: 2.5,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 5,
|
||||
height: 5,
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(item.image, style: const TextStyle(fontSize: 32)),
|
||||
),
|
||||
),
|
||||
|
||||
const SpaceWidth(16),
|
||||
|
||||
// Product Information
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Product Name and Category Row
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.productName,
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColor.textPrimary,
|
||||
height: 1.2,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: AppColor.primary.withOpacity(0.15),
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
item.categoryName,
|
||||
style: AppStyle.xs.copyWith(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColor.primary,
|
||||
letterSpacing: 0.2,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SpaceHeight(8),
|
||||
|
||||
// Price and Status Row
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Price
|
||||
Text(
|
||||
item.unitCost.currencyFormatRp,
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: AppColor.success,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
// Status Badge
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _getStatusColor().withOpacity(0.3),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
_getStatusText(),
|
||||
style: AppStyle.xs.copyWith(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColor.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SpaceHeight(10),
|
||||
|
||||
// Stock Information Grid
|
||||
Row(
|
||||
children: [
|
||||
// Quantity Info
|
||||
Expanded(
|
||||
child: _buildInfoItem(
|
||||
LineIcons.boxes,
|
||||
'Stok',
|
||||
'${NumberFormat('#,###', 'id_ID').format(item.quantity)} pcs',
|
||||
_getQuantityColor(),
|
||||
),
|
||||
),
|
||||
const SpaceWidth(16),
|
||||
// Total Value Info
|
||||
Expanded(
|
||||
child: _buildInfoItem(
|
||||
LineIcons.dollarSign,
|
||||
'Nilai',
|
||||
_formatCurrencyShort(item.totalValue),
|
||||
AppColor.info,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// Content Container
|
||||
Expanded(
|
||||
child: Padding(
|
||||
// Additional Information (conditionally shown)
|
||||
if (_shouldShowAdditionalInfo()) ...[
|
||||
SpaceHeight(12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.background,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColor.borderLight, width: 0.5),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Product Name
|
||||
Text(
|
||||
item.name,
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColor.textPrimary,
|
||||
height: 1.2,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
||||
SpaceHeight(4),
|
||||
|
||||
// Category
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
item.category,
|
||||
style: AppStyle.xs.copyWith(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColor.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// Price
|
||||
Text(
|
||||
'Rp ${item.price}',
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColor.primary,
|
||||
),
|
||||
),
|
||||
|
||||
SpaceHeight(6),
|
||||
|
||||
// Quantity & Status
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'${item.quantity} pcs',
|
||||
style: AppStyle.xs.copyWith(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColor.textSecondary,
|
||||
// Low Stock Warning
|
||||
if (item.isLowStock && !item.isZeroStock) ...[
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.warning.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
LineIcons.exclamationTriangle,
|
||||
size: 16,
|
||||
color: AppColor.warning,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: getStatusColor(item.status),
|
||||
shape: BoxShape.circle,
|
||||
const SpaceWidth(10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Stok Menipis',
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColor.warning,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Segera reorder minimal ${NumberFormat('#,###', 'id_ID').format(item.reorderLevel)} pcs',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
// Zero Stock Warning
|
||||
if (item.isZeroStock) ...[
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.error.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
LineIcons.timesCircle,
|
||||
size: 16,
|
||||
color: AppColor.error,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Stok Habis',
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColor.error,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Produk tidak tersedia untuk dijual',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
// Movement Information
|
||||
if (_hasMovementData()) ...[
|
||||
if ((item.isLowStock || item.isZeroStock)) SpaceHeight(12),
|
||||
Row(
|
||||
children: [
|
||||
if (item.totalIn > 0)
|
||||
Expanded(
|
||||
child: _buildMovementInfo(
|
||||
LineIcons.arrowUp,
|
||||
'Masuk',
|
||||
'${NumberFormat('#,###', 'id_ID').format(item.totalIn)} pcs',
|
||||
AppColor.success,
|
||||
),
|
||||
),
|
||||
if (item.totalIn > 0 && item.totalOut > 0)
|
||||
const SpaceWidth(16),
|
||||
if (item.totalOut > 0)
|
||||
Expanded(
|
||||
child: _buildMovementInfo(
|
||||
LineIcons.arrowDown,
|
||||
'Keluar',
|
||||
'${NumberFormat('#,###', 'id_ID').format(item.totalOut)} pcs',
|
||||
AppColor.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoItem(
|
||||
IconData icon,
|
||||
String label,
|
||||
String value,
|
||||
Color valueColor,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.background,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: AppColor.borderLight, width: 0.5),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 14, color: AppColor.textSecondary),
|
||||
const SpaceWidth(6),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: AppStyle.xs.copyWith(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColor.textSecondary,
|
||||
),
|
||||
),
|
||||
SpaceHeight(1),
|
||||
Text(
|
||||
value,
|
||||
style: AppStyle.xs.copyWith(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: valueColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color getStatusColor(String status) {
|
||||
switch (status) {
|
||||
case 'available':
|
||||
return AppColor.success;
|
||||
case 'low_stock':
|
||||
return AppColor.warning;
|
||||
case 'out_of_stock':
|
||||
return AppColor.error;
|
||||
default:
|
||||
return AppColor.textSecondary;
|
||||
Widget _buildMovementInfo(
|
||||
IconData icon,
|
||||
String label,
|
||||
String value,
|
||||
Color color,
|
||||
) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Icon(icon, size: 12, color: color),
|
||||
),
|
||||
const SpaceWidth(8),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: color,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
bool _shouldShowAdditionalInfo() {
|
||||
return item.isLowStock || item.isZeroStock || _hasMovementData();
|
||||
}
|
||||
|
||||
bool _hasMovementData() {
|
||||
return item.totalIn > 0 || item.totalOut > 0;
|
||||
}
|
||||
|
||||
Color _getStatusColor() {
|
||||
if (item.isZeroStock) return AppColor.error;
|
||||
if (item.isLowStock) return AppColor.warning;
|
||||
return AppColor.success;
|
||||
}
|
||||
|
||||
List<Color> _getGradientColors() {
|
||||
if (item.isZeroStock) {
|
||||
return [AppColor.error, AppColor.error.withOpacity(0.7)];
|
||||
}
|
||||
if (item.isLowStock) {
|
||||
return [AppColor.warning, AppColor.warning.withOpacity(0.7)];
|
||||
}
|
||||
return [AppColor.primary, AppColor.primary.withOpacity(0.7)];
|
||||
}
|
||||
|
||||
Color _getQuantityColor() {
|
||||
if (item.isZeroStock) return AppColor.error;
|
||||
if (item.isLowStock) return AppColor.warning;
|
||||
return AppColor.textPrimary;
|
||||
}
|
||||
|
||||
String _getStatusText() {
|
||||
if (item.isZeroStock) return 'HABIS';
|
||||
if (item.isLowStock) return 'MINIM';
|
||||
return 'TERSEDIA';
|
||||
}
|
||||
|
||||
IconData _getCategoryIcon() {
|
||||
final category = item.categoryName.toLowerCase();
|
||||
if (category.contains('elektronik') || category.contains('gadget')) {
|
||||
return LineIcons.mobilePhone;
|
||||
} else if (category.contains('fashion') || category.contains('pakaian')) {
|
||||
return LineIcons.tShirt;
|
||||
} else if (category.contains('makanan') || category.contains('food')) {
|
||||
return LineIcons.utensils;
|
||||
} else if (category.contains('kesehatan') || category.contains('health')) {
|
||||
return LineIcons.medkit;
|
||||
} else if (category.contains('rumah') || category.contains('home')) {
|
||||
return LineIcons.home;
|
||||
} else if (category.contains('olahraga') || category.contains('sport')) {
|
||||
return LineIcons.dumbbell;
|
||||
}
|
||||
return LineIcons.box;
|
||||
}
|
||||
|
||||
String _formatCurrencyShort(int amount) {
|
||||
if (amount.abs() >= 1000000000) {
|
||||
return 'Rp ${(amount / 1000000000).toStringAsFixed(1)}B';
|
||||
} else if (amount.abs() >= 1000000) {
|
||||
return 'Rp ${(amount / 1000000).toStringAsFixed(1)}M';
|
||||
} else if (amount.abs() >= 1000) {
|
||||
return 'Rp ${(amount / 1000).toStringAsFixed(0)}K';
|
||||
} else {
|
||||
return 'Rp ${NumberFormat('#,###', 'id_ID').format(amount)}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@ class InventoryStatCard extends StatelessWidget {
|
||||
final String value;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final String change;
|
||||
const InventoryStatCard({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.change,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -52,20 +50,6 @@ class InventoryStatCard extends StatelessWidget {
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: _getChangeColor(change).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
change,
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: _getChangeColor(change),
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SpaceHeight(16),
|
||||
@@ -88,14 +72,4 @@ class InventoryStatCard extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getChangeColor(String change) {
|
||||
if (change.startsWith('+')) {
|
||||
return AppColor.success;
|
||||
} else if (change.startsWith('-')) {
|
||||
return AppColor.error;
|
||||
} else {
|
||||
return AppColor.warning;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user