update
This commit is contained in:
parent
ff619ac88a
commit
a76d3a0f35
3 changed files with 175 additions and 118 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_medicines.dart';
|
||||
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
||||
import 'package:pharmacy_mobile/tables/cart.dart';
|
||||
import 'package:pharmacy_mobile/tables/stocks.dart';
|
||||
import 'package:pharmacy_mobile/tables/storage.dart';
|
||||
import 'package:pharmacy_mobile/widgets/customer_pagebackground_widget.dart';
|
||||
|
|
@ -18,12 +21,15 @@ class CustomerSearchPage extends StatefulWidget {
|
|||
|
||||
class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||
final _searchController = TextEditingController();
|
||||
final _authService = AuthService();
|
||||
final _storage = Storage();
|
||||
// final _refMedicines = RefMedicines();
|
||||
final _stocks = Stocks();
|
||||
final _carts = Carts();
|
||||
// final _refMedicines = RefMedicines();
|
||||
late String imageUrl = '';
|
||||
late List _stockList = [];
|
||||
late List _cartList = [];
|
||||
// late final List _medicinesList = [];
|
||||
|
||||
Future<void> _getURL() async {
|
||||
|
|
@ -37,6 +43,18 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
_stockList = await _stocks.getList();
|
||||
}
|
||||
|
||||
Future<String> _getCurrentUser() async {
|
||||
final result = _authService.getCurrentUser();
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
Future<void> _getCarts() async {
|
||||
final currentUser = await _getCurrentUser();
|
||||
log('currentUser: $currentUser');
|
||||
_cartList = await _carts.getCart(currentUser);
|
||||
log('cart: ${_cartList.toString()}');
|
||||
}
|
||||
|
||||
// Future<void> _getAllMedicines() async {
|
||||
// _medicinesList = await _refMedicines.getList();
|
||||
// }
|
||||
|
|
@ -63,6 +81,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
|
||||
void autoRun() async {
|
||||
await _getAllStocks();
|
||||
await _getCarts();
|
||||
// await _getAllMedicines();
|
||||
await _getURL();
|
||||
}
|
||||
|
|
@ -141,41 +160,41 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
const Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
),
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
),
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
)
|
||||
imageUrl: 'imageUrl',
|
||||
text: 'item[medicine_name]',
|
||||
subtext: 'item[generic_name]',
|
||||
price: 123,
|
||||
quantity: 123,
|
||||
isLoading: true,
|
||||
cart: 0)
|
||||
],
|
||||
)
|
||||
else
|
||||
for (var item in _stockList)
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: item['medicine_name'].toString(),
|
||||
subtext: item['generic_name'].toString(),
|
||||
price: item['price'].toDouble(),
|
||||
quantity: item['quantity'].toDouble(),
|
||||
isLoading: false,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: item['medicine_name'].toString(),
|
||||
subtext: item['generic_name'].toString(),
|
||||
price: item['price'].toDouble(),
|
||||
quantity: item['quantity'].toDouble(),
|
||||
isLoading: false,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
const Gap(16),
|
||||
|
|
@ -186,29 +205,29 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
child: Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 0,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 0,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 2),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
const Gap(16),
|
||||
|
|
@ -219,29 +238,29 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
child: Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
const Gap(16),
|
||||
|
|
@ -252,29 +271,29 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
child: Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
const Gap(16),
|
||||
|
|
@ -285,29 +304,29 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
child: Row(
|
||||
children: [
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
ItemCardWidget(
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
),
|
||||
imageUrl: imageUrl,
|
||||
text: 'sample',
|
||||
subtext: 'generic_name',
|
||||
price: 500,
|
||||
quantity: 15,
|
||||
isLoading: imageUrl.isEmpty,
|
||||
cart: 0),
|
||||
],
|
||||
)),
|
||||
],
|
||||
|
|
|
|||
17
lib/tables/cart.dart
Normal file
17
lib/tables/cart.dart
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class Carts {
|
||||
final SupabaseClient _supabase = Supabase.instance.client;
|
||||
|
||||
Future<List> getCart(String email) async {
|
||||
try {
|
||||
final data = await _supabase.from('carts').select('carts_uuid').eq('email', email);
|
||||
log('data: $data');
|
||||
return data.toList();
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ class ItemCardWidget extends StatelessWidget {
|
|||
final double price;
|
||||
final double quantity;
|
||||
final bool isLoading;
|
||||
final double cart;
|
||||
|
||||
const ItemCardWidget(
|
||||
{super.key,
|
||||
|
|
@ -20,7 +21,8 @@ class ItemCardWidget extends StatelessWidget {
|
|||
required this.subtext,
|
||||
required this.price,
|
||||
required this.quantity,
|
||||
required this.isLoading});
|
||||
required this.isLoading,
|
||||
required this.cart});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -110,13 +112,32 @@ class ItemCardWidget extends StatelessWidget {
|
|||
Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: cart > 0 ? const Color.fromRGBO(99, 44, 113, 1) : const Color.fromRGBO(255, 255, 255, 1),
|
||||
border: Border.all(color: Colors.black),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: FaIcon(
|
||||
FontAwesomeIcons.cartShopping,
|
||||
size: 12,
|
||||
))
|
||||
child: (cart > 0)
|
||||
? Row(
|
||||
children: [
|
||||
const FaIcon(
|
||||
FontAwesomeIcons.cartShopping,
|
||||
size: 12,
|
||||
color: Color.fromRGBO(255, 255, 255, 1),
|
||||
),
|
||||
const Gap(4),
|
||||
TextWidget(
|
||||
text: cart.toStringAsFixed(0),
|
||||
size: 12,
|
||||
color: const Color.fromRGBO(255, 255, 255, 1),
|
||||
bold: true,
|
||||
)
|
||||
],
|
||||
)
|
||||
: const FaIcon(
|
||||
FontAwesomeIcons.cartShopping,
|
||||
size: 12,
|
||||
color: Color.fromRGBO(0, 0, 0, 1),
|
||||
))
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue