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:flutter/material.dart';
|
||||||
import 'package:gap/gap.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/stocks.dart';
|
||||||
import 'package:pharmacy_mobile/tables/storage.dart';
|
import 'package:pharmacy_mobile/tables/storage.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/customer_pagebackground_widget.dart';
|
import 'package:pharmacy_mobile/widgets/customer_pagebackground_widget.dart';
|
||||||
|
|
@ -18,12 +21,15 @@ class CustomerSearchPage extends StatefulWidget {
|
||||||
|
|
||||||
class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
final _searchController = TextEditingController();
|
final _searchController = TextEditingController();
|
||||||
|
final _authService = AuthService();
|
||||||
final _storage = Storage();
|
final _storage = Storage();
|
||||||
// final _refMedicines = RefMedicines();
|
// final _refMedicines = RefMedicines();
|
||||||
final _stocks = Stocks();
|
final _stocks = Stocks();
|
||||||
|
final _carts = Carts();
|
||||||
// final _refMedicines = RefMedicines();
|
// final _refMedicines = RefMedicines();
|
||||||
late String imageUrl = '';
|
late String imageUrl = '';
|
||||||
late List _stockList = [];
|
late List _stockList = [];
|
||||||
|
late List _cartList = [];
|
||||||
// late final List _medicinesList = [];
|
// late final List _medicinesList = [];
|
||||||
|
|
||||||
Future<void> _getURL() async {
|
Future<void> _getURL() async {
|
||||||
|
|
@ -37,6 +43,18 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
_stockList = await _stocks.getList();
|
_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 {
|
// Future<void> _getAllMedicines() async {
|
||||||
// _medicinesList = await _refMedicines.getList();
|
// _medicinesList = await _refMedicines.getList();
|
||||||
// }
|
// }
|
||||||
|
|
@ -63,6 +81,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
|
|
||||||
void autoRun() async {
|
void autoRun() async {
|
||||||
await _getAllStocks();
|
await _getAllStocks();
|
||||||
|
await _getCarts();
|
||||||
// await _getAllMedicines();
|
// await _getAllMedicines();
|
||||||
await _getURL();
|
await _getURL();
|
||||||
}
|
}
|
||||||
|
|
@ -141,41 +160,41 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
const Row(
|
const Row(
|
||||||
children: [
|
children: [
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: 'imageUrl',
|
imageUrl: 'imageUrl',
|
||||||
text: 'item[medicine_name]',
|
text: 'item[medicine_name]',
|
||||||
subtext: 'item[generic_name]',
|
subtext: 'item[generic_name]',
|
||||||
price: 123,
|
price: 123,
|
||||||
quantity: 123,
|
quantity: 123,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: 'imageUrl',
|
imageUrl: 'imageUrl',
|
||||||
text: 'item[medicine_name]',
|
text: 'item[medicine_name]',
|
||||||
subtext: 'item[generic_name]',
|
subtext: 'item[generic_name]',
|
||||||
price: 123,
|
price: 123,
|
||||||
quantity: 123,
|
quantity: 123,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: 'imageUrl',
|
imageUrl: 'imageUrl',
|
||||||
text: 'item[medicine_name]',
|
text: 'item[medicine_name]',
|
||||||
subtext: 'item[generic_name]',
|
subtext: 'item[generic_name]',
|
||||||
price: 123,
|
price: 123,
|
||||||
quantity: 123,
|
quantity: 123,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
)
|
cart: 0)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
for (var item in _stockList)
|
for (var item in _stockList)
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: item['medicine_name'].toString(),
|
text: item['medicine_name'].toString(),
|
||||||
subtext: item['generic_name'].toString(),
|
subtext: item['generic_name'].toString(),
|
||||||
price: item['price'].toDouble(),
|
price: item['price'].toDouble(),
|
||||||
quantity: item['quantity'].toDouble(),
|
quantity: item['quantity'].toDouble(),
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
),
|
cart: 0),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
|
|
@ -186,29 +205,29 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 0,
|
quantity: 0,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 2),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
|
|
@ -219,29 +238,29 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
|
|
@ -252,29 +271,29 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
|
|
@ -285,29 +304,29 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
isLoading: imageUrl.isEmpty,
|
||||||
),
|
cart: 0),
|
||||||
ItemCardWidget(
|
ItemCardWidget(
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
text: 'sample',
|
text: 'sample',
|
||||||
subtext: 'generic_name',
|
subtext: 'generic_name',
|
||||||
price: 500,
|
price: 500,
|
||||||
quantity: 15,
|
quantity: 15,
|
||||||
isLoading: imageUrl.isEmpty,
|
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 price;
|
||||||
final double quantity;
|
final double quantity;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
final double cart;
|
||||||
|
|
||||||
const ItemCardWidget(
|
const ItemCardWidget(
|
||||||
{super.key,
|
{super.key,
|
||||||
|
|
@ -20,7 +21,8 @@ class ItemCardWidget extends StatelessWidget {
|
||||||
required this.subtext,
|
required this.subtext,
|
||||||
required this.price,
|
required this.price,
|
||||||
required this.quantity,
|
required this.quantity,
|
||||||
required this.isLoading});
|
required this.isLoading,
|
||||||
|
required this.cart});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
@ -110,13 +112,32 @@ class ItemCardWidget extends StatelessWidget {
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
|
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
|
||||||
decoration: BoxDecoration(
|
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),
|
border: Border.all(color: Colors.black),
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
child: FaIcon(
|
child: (cart > 0)
|
||||||
FontAwesomeIcons.cartShopping,
|
? Row(
|
||||||
size: 12,
|
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