From 101b5af0a6c11ee9ce3321cd423e647e8c84f64b Mon Sep 17 00:00:00 2001 From: eko54r Date: Sun, 15 Feb 2026 21:36:52 +0700 Subject: [PATCH] update setting tab or hp --- lib/Screens/pos_sale/pos_sale.dart | 128 ++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 3 deletions(-) diff --git a/lib/Screens/pos_sale/pos_sale.dart b/lib/Screens/pos_sale/pos_sale.dart index a48a829..cc455c6 100644 --- a/lib/Screens/pos_sale/pos_sale.dart +++ b/lib/Screens/pos_sale/pos_sale.dart @@ -6,6 +6,7 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_typeahead/flutter_typeahead.dart'; import 'package:mobile_pos/constant.dart'; import 'package:mobile_pos/currency.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import '../../Const/api_config.dart'; import '../../GlobalComponents/bar_code_scaner_widget.dart'; @@ -41,6 +42,7 @@ class PosSaleScreen extends ConsumerStatefulWidget { class _PosSaleScreenState extends ConsumerState { final productController = TextEditingController(); + bool isTab = true; List filteredProducts = []; Party? selectedCustomer; CategoryModel? selectedCategory; @@ -63,6 +65,7 @@ class _PosSaleScreenState extends ConsumerState { @override void initState() { super.initState(); + _loadState(); ref.refresh(cartNotifier); filteredProducts = ref.read(productProvider).value ?? []; productController.addListener(_applyFilters); @@ -147,6 +150,13 @@ class _PosSaleScreenState extends ConsumerState { }); } + Future _loadState() async { + final prefs = await SharedPreferences.getInstance(); + setState(() { + isTab = prefs.getBool('isTab') ?? true; + }); + } + final TextEditingController _searchController = TextEditingController(); bool _hasInitializedFilters = false; @@ -163,7 +173,112 @@ class _PosSaleScreenState extends ConsumerState { appBar: AppBar( title: Text(lang.S.of(context).posSale), centerTitle: true, + actions: [ + Row( + children: [ + Text( + 'Tab', + style: TextStyle( + color: isTab ? kMainColor : kSubPeraColor, + fontWeight: FontWeight.bold, + fontSize: 16, + ), + ), + Switch( + value: !isTab, + activeColor: kMainColor, + onChanged: (value) async { + setState(() { + isTab = !value; + }); + final prefs = await SharedPreferences.getInstance(); + await prefs.setBool('isTab', isTab); + }, + ), + Text( + 'HP', + style: TextStyle( + color: !isTab ? kMainColor : kSubPeraColor, + fontWeight: FontWeight.bold, + fontSize: 16, + ), + ), + const SizedBox(width: 16), + ], + ) + ], ), + bottomNavigationBar: isTab + ? null + : Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.05), + spreadRadius: 1, + blurRadius: 5, + offset: const Offset(0, -3), + ), + ], + ), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: kMainColor, + padding: const EdgeInsets.symmetric(vertical: 12), + ), + onPressed: providerData.cartItemList.isEmpty + ? null + : () async { + if (!permissionService.hasPermission(Permit.saleReturnsRead.value)) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + backgroundColor: kMainColor, + content: Text(lang.S.of(context).inventoryPermission), + ), + ); + return; + } + bool branchResult = await checkActionWhenNoBranch(context: context, ref: ref); + if (!branchResult) { + return; + } + + // Navigate to the next screen if permission is granted + bool result = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => AddSalesScreen( + customerModel: selectedCustomer, + isFromPos: true, + ), + ), + ); + + // Handle result after returning from AddSalesScreen + if (result) { + _searchController.clear(); + selectedCustomer = null; + setState(() {}); + } + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'Continue', + style: TextStyle(color: Colors.white, fontSize: 16), + ), + const SizedBox(width: 8), + Text( + '(${providerData.cartItemList.length} Items): $currency${providerData.getTotalAmount()}', + style: const TextStyle(color: Colors.white, fontSize: 14), + ), + ], + ), + ), + ), body: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -866,9 +981,13 @@ class _PosSaleScreenState extends ConsumerState { ), ), ), - Expanded( - flex: 1, - child: Container( + if (isTab) + Expanded( + flex: 1, + child: Column( + children: [ + Expanded( + child: Container( margin: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.white, @@ -1145,6 +1264,9 @@ class _PosSaleScreenState extends ConsumerState { ), ], ), + ), + ), + ], ), ), ],