Initial commit - app-padrao-1.0
This commit is contained in:
94
lib/features/products/data/models/product_model.dart
Normal file
94
lib/features/products/data/models/product_model.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'product_model.g.dart';
|
||||
|
||||
@HiveType(typeId: 2)
|
||||
class ProductModel extends HiveObject {
|
||||
@HiveField(0)
|
||||
final String id;
|
||||
|
||||
@HiveField(1)
|
||||
final String userId;
|
||||
|
||||
@HiveField(2)
|
||||
final String name;
|
||||
|
||||
@HiveField(3)
|
||||
final String category; // 'pastas', 'bebidas', 'acessorios', 'outros'
|
||||
|
||||
@HiveField(4)
|
||||
final int quantity;
|
||||
|
||||
@HiveField(5)
|
||||
final double purchasePrice;
|
||||
|
||||
@HiveField(6)
|
||||
final double salePrice;
|
||||
|
||||
@HiveField(7)
|
||||
final int minStock;
|
||||
@HiveField(8)
|
||||
final String? imagePath;
|
||||
|
||||
ProductModel({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.name,
|
||||
required this.category,
|
||||
required this.quantity,
|
||||
required this.purchasePrice,
|
||||
required this.salePrice,
|
||||
required this.minStock,
|
||||
this.imagePath,
|
||||
});
|
||||
|
||||
bool get isLowStock => quantity <= minStock;
|
||||
|
||||
ProductModel copyWith({
|
||||
String? id,
|
||||
String? userId,
|
||||
String? name,
|
||||
String? category,
|
||||
int? quantity,
|
||||
double? purchasePrice,
|
||||
double? salePrice,
|
||||
int? minStock,
|
||||
String? imagePath,
|
||||
}) {
|
||||
return ProductModel(
|
||||
id: id ?? this.id,
|
||||
userId: userId ?? this.userId,
|
||||
name: name ?? this.name,
|
||||
category: category ?? this.category,
|
||||
quantity: quantity ?? this.quantity,
|
||||
purchasePrice: purchasePrice ?? this.purchasePrice,
|
||||
salePrice: salePrice ?? this.salePrice,
|
||||
minStock: minStock ?? this.minStock,
|
||||
imagePath: imagePath ?? this.imagePath,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ProductCategories {
|
||||
static const String pastes = 'pastas';
|
||||
static const String beverages = 'bebidas';
|
||||
static const String accessories = 'acessorios';
|
||||
static const String other = 'outros';
|
||||
|
||||
static List<String> get all => [pastes, beverages, accessories, other];
|
||||
|
||||
static String getDisplayName(String category) {
|
||||
switch (category) {
|
||||
case pastes:
|
||||
return 'Pastas e Pomadas';
|
||||
case beverages:
|
||||
return 'Bebidas (Frigobar)';
|
||||
case accessories:
|
||||
return 'Acessórios';
|
||||
case other:
|
||||
return 'Outros';
|
||||
default:
|
||||
return category;
|
||||
}
|
||||
}
|
||||
}
|
||||
65
lib/features/products/data/models/product_model.g.dart
Normal file
65
lib/features/products/data/models/product_model.g.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'product_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class ProductModelAdapter extends TypeAdapter<ProductModel> {
|
||||
@override
|
||||
final int typeId = 2;
|
||||
|
||||
@override
|
||||
ProductModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return ProductModel(
|
||||
id: fields[0] as String,
|
||||
userId: fields[1] as String,
|
||||
name: fields[2] as String,
|
||||
category: fields[3] as String,
|
||||
quantity: fields[4] as int,
|
||||
purchasePrice: fields[5] as double,
|
||||
salePrice: fields[6] as double,
|
||||
minStock: fields[7] as int,
|
||||
imagePath: fields[8] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ProductModel obj) {
|
||||
writer
|
||||
..writeByte(9)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.userId)
|
||||
..writeByte(2)
|
||||
..write(obj.name)
|
||||
..writeByte(3)
|
||||
..write(obj.category)
|
||||
..writeByte(4)
|
||||
..write(obj.quantity)
|
||||
..writeByte(5)
|
||||
..write(obj.purchasePrice)
|
||||
..writeByte(6)
|
||||
..write(obj.salePrice)
|
||||
..writeByte(7)
|
||||
..write(obj.minStock)
|
||||
..writeByte(8)
|
||||
..write(obj.imagePath);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ProductModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
Reference in New Issue
Block a user