update setting tab or hp
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter_svg/flutter_svg.dart';
|
|||||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||||
import 'package:mobile_pos/constant.dart';
|
import 'package:mobile_pos/constant.dart';
|
||||||
import 'package:mobile_pos/currency.dart';
|
import 'package:mobile_pos/currency.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import '../../Const/api_config.dart';
|
import '../../Const/api_config.dart';
|
||||||
import '../../GlobalComponents/bar_code_scaner_widget.dart';
|
import '../../GlobalComponents/bar_code_scaner_widget.dart';
|
||||||
@@ -41,6 +42,7 @@ class PosSaleScreen extends ConsumerStatefulWidget {
|
|||||||
|
|
||||||
class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||||
final productController = TextEditingController();
|
final productController = TextEditingController();
|
||||||
|
bool isTab = true;
|
||||||
List<Product> filteredProducts = [];
|
List<Product> filteredProducts = [];
|
||||||
Party? selectedCustomer;
|
Party? selectedCustomer;
|
||||||
CategoryModel? selectedCategory;
|
CategoryModel? selectedCategory;
|
||||||
@@ -63,6 +65,7 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_loadState();
|
||||||
ref.refresh(cartNotifier);
|
ref.refresh(cartNotifier);
|
||||||
filteredProducts = ref.read(productProvider).value ?? [];
|
filteredProducts = ref.read(productProvider).value ?? [];
|
||||||
productController.addListener(_applyFilters);
|
productController.addListener(_applyFilters);
|
||||||
@@ -147,6 +150,13 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _loadState() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
setState(() {
|
||||||
|
isTab = prefs.getBool('isTab') ?? true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
bool _hasInitializedFilters = false;
|
bool _hasInitializedFilters = false;
|
||||||
|
|
||||||
@@ -163,6 +173,111 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(lang.S.of(context).posSale),
|
title: Text(lang.S.of(context).posSale),
|
||||||
centerTitle: true,
|
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(
|
body: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -866,8 +981,12 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (isTab)
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.all(16),
|
margin: const EdgeInsets.all(16),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -1149,6 +1268,9 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user