|
|
|
@@ -1,3 +1,4 @@ |
|
|
|
import 'package:farm_tpf/custom_model/SuppliesUsing.dart'; |
|
|
|
import 'package:farm_tpf/custom_model/Supply.dart'; |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; |
|
|
|
@@ -15,10 +16,14 @@ class ResourceHelperScreen extends StatefulWidget { |
|
|
|
final String type; |
|
|
|
final int selectedId; |
|
|
|
final String titleName; |
|
|
|
final List<SuppliesUsing> currentItems; |
|
|
|
final int currentEditId; |
|
|
|
ResourceHelperScreen( |
|
|
|
{@required this.type, |
|
|
|
@required this.selectedId, |
|
|
|
@required this.titleName}); |
|
|
|
@required this.titleName, |
|
|
|
@required this.currentItems, |
|
|
|
@required this.currentEditId}); |
|
|
|
@override |
|
|
|
_ResourceHelperScreenState createState() => _ResourceHelperScreenState(); |
|
|
|
} |
|
|
|
@@ -33,6 +38,8 @@ class _ResourceHelperScreenState extends State<ResourceHelperScreen> { |
|
|
|
selectedId: widget.selectedId, |
|
|
|
type: widget.type, |
|
|
|
titleName: widget.titleName, |
|
|
|
currentItems: widget.currentItems, |
|
|
|
currentEditId: widget.currentEditId, |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
@@ -42,10 +49,14 @@ class HoldInfinityWidget extends StatelessWidget { |
|
|
|
final int selectedId; |
|
|
|
final String type; |
|
|
|
final String titleName; |
|
|
|
final List<SuppliesUsing> currentItems; |
|
|
|
final int currentEditId; |
|
|
|
HoldInfinityWidget( |
|
|
|
{@required this.selectedId, |
|
|
|
@required this.type, |
|
|
|
@required this.titleName}); |
|
|
|
@required this.titleName, |
|
|
|
@required this.currentItems, |
|
|
|
@required this.currentEditId}); |
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
@@ -62,6 +73,8 @@ class HoldInfinityWidget extends StatelessWidget { |
|
|
|
child: InfinityView( |
|
|
|
selectedId: selectedId, |
|
|
|
type: type, |
|
|
|
currentItems: currentItems, |
|
|
|
currentEditId: currentEditId, |
|
|
|
)) |
|
|
|
], |
|
|
|
)); |
|
|
|
@@ -71,7 +84,13 @@ class HoldInfinityWidget extends StatelessWidget { |
|
|
|
class InfinityView extends StatefulWidget { |
|
|
|
final int selectedId; |
|
|
|
final String type; |
|
|
|
InfinityView({@required this.selectedId, @required this.type}); |
|
|
|
final List<SuppliesUsing> currentItems; |
|
|
|
final int currentEditId; |
|
|
|
InfinityView( |
|
|
|
{@required this.selectedId, |
|
|
|
@required this.type, |
|
|
|
@required this.currentItems, |
|
|
|
@required this.currentEditId}); |
|
|
|
@override |
|
|
|
_InfinityViewState createState() => _InfinityViewState(); |
|
|
|
} |
|
|
|
@@ -103,7 +122,11 @@ class _InfinityViewState extends State<InfinityView> { |
|
|
|
itemBuilder: (BuildContext context, int index) { |
|
|
|
return index >= state.items.length |
|
|
|
? BottomLoader() |
|
|
|
: ItemInfinityWidget(item: state.items[index]); |
|
|
|
: ItemInfinityWidget( |
|
|
|
item: state.items[index], |
|
|
|
currentItems: widget.currentItems, |
|
|
|
currentEditId: widget.currentEditId, |
|
|
|
); |
|
|
|
}, |
|
|
|
itemCount: state.items.length), |
|
|
|
onRefresh: () async { |
|
|
|
@@ -126,8 +149,15 @@ class _InfinityViewState extends State<InfinityView> { |
|
|
|
|
|
|
|
class ItemInfinityWidget extends StatelessWidget { |
|
|
|
final Supply item; |
|
|
|
final List<SuppliesUsing> currentItems; |
|
|
|
final int currentEditId; |
|
|
|
|
|
|
|
const ItemInfinityWidget({Key key, @required this.item}) : super(key: key); |
|
|
|
const ItemInfinityWidget( |
|
|
|
{Key key, |
|
|
|
@required this.item, |
|
|
|
@required this.currentItems, |
|
|
|
@required this.currentEditId}) |
|
|
|
: super(key: key); |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
@@ -149,9 +179,19 @@ class ItemInfinityWidget extends StatelessWidget { |
|
|
|
if (value.quantity <= 0) { |
|
|
|
Utils.showSnackBarWarning(message: "Vật tư đã hết"); |
|
|
|
} else { |
|
|
|
//close nackbar if open |
|
|
|
if (Get.isSnackbarOpen) Get.back(); |
|
|
|
Navigator.of(context).pop(value); |
|
|
|
var editedId = (currentEditId > 0) ? currentEditId : -1; |
|
|
|
if (currentItems |
|
|
|
.map((e) => e.tbSuppliesInWarehouseId) |
|
|
|
.contains(item.id) && |
|
|
|
item.id != editedId) { |
|
|
|
Utils.showSnackBarWarning( |
|
|
|
message: |
|
|
|
"Vật tư đã được thêm, vui lòng chọn vật tư khác"); |
|
|
|
} else { |
|
|
|
//close nackbar if open |
|
|
|
if (Get.isSnackbarOpen) Get.back(); |
|
|
|
Navigator.of(context).pop(value); |
|
|
|
} |
|
|
|
} |
|
|
|
}), |
|
|
|
)), |