update
This commit is contained in:
parent
d3a4b45603
commit
28cb4cac67
4 changed files with 101 additions and 9 deletions
|
|
@ -10,9 +10,11 @@ import 'package:pharmacy_mobile/widgets/dropdown_wrappermulti_widget.dart';
|
|||
import 'package:pharmacy_mobile/widgets/form_border_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:pharmacy_mobile/widgets/warning_widget.dart';
|
||||
|
||||
class DeleteStockPage extends StatefulWidget {
|
||||
const DeleteStockPage({super.key});
|
||||
|
|
@ -28,6 +30,10 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
|||
|
||||
late List _stockList = [];
|
||||
late String _selectedStock = '';
|
||||
late bool _aboveQuantity = false;
|
||||
late bool _noStock = false;
|
||||
late double _serverQuantity = 0;
|
||||
late String _selectedUUID = '';
|
||||
|
||||
void _getStocks() async {
|
||||
_stockList = await _stocks.getList();
|
||||
|
|
@ -49,14 +55,49 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
|||
_getQuantity(_selectedStock);
|
||||
}
|
||||
|
||||
// void _saveDeletion() async {
|
||||
// _stocks.deleteStock('uuid');
|
||||
// }
|
||||
void _saveDeletion() async {
|
||||
final newQuantity = _serverQuantity - double.parse(_quantityController.text);
|
||||
final newQuantityFixed = newQuantity.toStringAsFixed(0);
|
||||
// log(newQuantityFixed);
|
||||
try {
|
||||
_stocks.updateStock(_selectedUUID, 'quantity', newQuantityFixed);
|
||||
if (mounted) {
|
||||
showNotification(context, '$_selectedStock updated', true);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: $e', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _getQuantity(String name) async {
|
||||
final uuid = await _stocks.getUUID(name);
|
||||
final quantity = await _stocks.getQuantity(uuid);
|
||||
log(quantity);
|
||||
_serverQuantity = double.parse(quantity);
|
||||
_selectedUUID = uuid;
|
||||
}
|
||||
|
||||
void _setQuantity(dynamic quantity) async {
|
||||
if (_selectedStock.isEmpty) {
|
||||
_noStock = true;
|
||||
setState(() {});
|
||||
} else {
|
||||
_noStock = false;
|
||||
if (double.parse(quantity) > _serverQuantity) {
|
||||
_aboveQuantity = true;
|
||||
setState(() {});
|
||||
} else {
|
||||
_aboveQuantity = false;
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -95,9 +136,20 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
|||
DropDownWidget(
|
||||
label: 'Stocks', list: _stockList, listTitle: 'medicine_name', onChanged: _updateStock),
|
||||
const Gap(16),
|
||||
InputWidget(label: 'Quantity', controller: _quantityController),
|
||||
InputWidget(label: 'Quantity', controller: _quantityController, onChanged: _setQuantity),
|
||||
const Gap(32),
|
||||
// ButtonWidget(text: 'Remove Stock', onPressed: (_) => {})
|
||||
if (_noStock)
|
||||
WarningWidget(
|
||||
text: 'Removing Disabled',
|
||||
warning: 'Quantity is above sssss',
|
||||
)
|
||||
else if (_aboveQuantity)
|
||||
WarningWidget(
|
||||
text: 'Removing Disabled',
|
||||
warning: 'Quantity is above stocked',
|
||||
)
|
||||
else
|
||||
ButtonWidget(text: 'Remove Stock', onPressed: _saveDeletion)
|
||||
])
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Stocks {
|
|||
return data.first['quantity'].toString();
|
||||
}
|
||||
|
||||
Future<void> updateStock(String uuid, String column) async {
|
||||
await _supabase.from('stocks').update({'quantity': 12}).eq('stock_uuid', uuid);
|
||||
Future<void> updateStock(String uuid, String column, String value) async {
|
||||
await _supabase.from('stocks').update({column: value}).eq('stocks_uuid', uuid).select();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:pharmacy_mobile/widgets/dropdown_widget.dart';
|
||||
|
||||
class InputWidget extends StatelessWidget {
|
||||
final String label;
|
||||
final TextEditingController controller;
|
||||
final bool? password;
|
||||
final OnChangedCallback? onChanged;
|
||||
|
||||
const InputWidget({super.key, required this.label, required this.controller, this.password});
|
||||
const InputWidget({super.key, required this.label, required this.controller, this.password, this.onChanged});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -29,6 +31,7 @@ class InputWidget extends StatelessWidget {
|
|||
contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 24)),
|
||||
style: GoogleFonts.outfit(textStyle: const TextStyle(color: Color.fromRGBO(0, 0, 0, 1), fontSize: 16)),
|
||||
obscureText: password ?? false,
|
||||
onChanged: onChanged,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
37
lib/widgets/warning_widget.dart
Normal file
37
lib/widgets/warning_widget.dart
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
|
||||
class WarningWidget extends StatelessWidget {
|
||||
final String text;
|
||||
final String warning;
|
||||
const WarningWidget({super.key, required this.text, required this.warning});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color.fromARGB(102, 121, 15, 5),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(width: 2, color: const Color.fromARGB(255, 42, 2, 2))),
|
||||
// width: 200,
|
||||
// height: 100,
|
||||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
|
||||
child: Center(
|
||||
child: TextWidget(
|
||||
text: text,
|
||||
size: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Gap(16),
|
||||
TextWidget(
|
||||
text: warning,
|
||||
size: 14,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue