309 lines
12 KiB
Dart
309 lines
12 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
import 'package:gap/gap.dart';
|
|
import 'package:pharmacy_mobile/tables/ref_medicines.dart';
|
|
import 'package:pharmacy_mobile/tables/stocks.dart';
|
|
import 'package:pharmacy_mobile/tables/storage.dart';
|
|
import 'package:pharmacy_mobile/widgets/customer_pagebackground_widget.dart';
|
|
import 'package:pharmacy_mobile/widgets/customer_title_widget.dart';
|
|
import 'package:pharmacy_mobile/widgets/indicator_widget.dart';
|
|
import 'package:pharmacy_mobile/widgets/input_widget.dart';
|
|
import 'package:pharmacy_mobile/widgets/item_card_widget.dart';
|
|
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
|
import 'package:toggle_switch/toggle_switch.dart';
|
|
|
|
class CustomerSearchPage extends StatefulWidget {
|
|
const CustomerSearchPage({super.key});
|
|
|
|
@override
|
|
State<CustomerSearchPage> createState() => _CustomerSearchPageState();
|
|
}
|
|
|
|
class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|
final _searchController = TextEditingController();
|
|
final _storage = Storage();
|
|
final _refMedicines = RefMedicines();
|
|
final _stocks = Stocks();
|
|
// final _refMedicines = RefMedicines();
|
|
late String imageUrl = '';
|
|
late List _stockList = [];
|
|
late List _medicinesList = [];
|
|
|
|
Future<void> _getURL() async {
|
|
final image = await _storage.getPublicURL('ref_medicines_images', 'a3e430fe-86c1-4d46-9c6a-aed2dae57fef.webp');
|
|
setState(() {
|
|
imageUrl = image;
|
|
});
|
|
}
|
|
|
|
Future<void> _getAllStocks() async {
|
|
_stockList = await _stocks.getList();
|
|
}
|
|
|
|
Future<void> _getAllMedicines() async {
|
|
_medicinesList = await _refMedicines.getList();
|
|
}
|
|
|
|
// void getURLs() async {
|
|
// try {
|
|
// for (int i = 1; i <= 4; i++) {
|
|
// final image = await _storage.getPublicURL(
|
|
// context,
|
|
// 'ref_medicines_images',
|
|
// 'ca3e2949-4964-4d25-a274-2a18608b7bdb.webp', // Replace with your actual image path
|
|
// );
|
|
// log(image);
|
|
// setState(() {
|
|
// imageUrl.add(image);
|
|
// });
|
|
// }
|
|
// } catch (e, stackTrace) {
|
|
// log('Error getting URLs: $e', stackTrace: stackTrace);
|
|
// }
|
|
// }
|
|
|
|
// void _filterList() {}
|
|
|
|
void autoRun() async {
|
|
await _getAllStocks();
|
|
// await _getAllMedicines();
|
|
await _getURL();
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
autoRun();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_searchController.dispose();
|
|
imageUrl = '';
|
|
_stockList = [];
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// const double imageSize = 180;
|
|
|
|
return Scaffold(
|
|
body: CustomerPagebackgroundWidget(
|
|
height: MediaQuery.of(context).size.height + 800,
|
|
child: Column(
|
|
children: [
|
|
Column(
|
|
children: [
|
|
const Gap(68),
|
|
const CustomerTitleWidget(),
|
|
const Gap(8),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: Column(
|
|
children: [
|
|
InputWidget(
|
|
label: '',
|
|
controller: _searchController,
|
|
placeholder: 'Search for medicine',
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Gap(32),
|
|
// Row(
|
|
// mainAxisAlignment: MainAxisAlignment.end,
|
|
// children: [
|
|
// ToggleSwitch(
|
|
// fontSize: 12,
|
|
// minWidth: 64,
|
|
// minHeight: 32,
|
|
// initialLabelIndex: 1,
|
|
// cornerRadius: 20,
|
|
// activeFgColor: Colors.white,
|
|
// inactiveBgColor: const Color.fromRGBO(81, 81, 81, 1),
|
|
// inactiveFgColor: const Color.fromRGBO(177, 175, 175, 1),
|
|
// totalSwitches: 2,
|
|
// labels: ['All', 'Stocks'],
|
|
// activeBgColors: [
|
|
// [const Color.fromRGBO(40, 112, 143, 1)],
|
|
// [const Color.fromRGBO(40, 112, 143, 1)],
|
|
// ],
|
|
// // onToggle: (index) {
|
|
// // print('switched to: $index');
|
|
// // },
|
|
// ),
|
|
// const Gap(8)
|
|
// ],
|
|
// ),
|
|
const IndicatorWidget(text: 'All Stocks'),
|
|
const Gap(8),
|
|
SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Row(
|
|
children: [
|
|
if (imageUrl.isEmpty)
|
|
const Row(
|
|
children: [
|
|
ItemCardWidget(
|
|
imageUrl: 'imageUrl',
|
|
text: 'item[medicine_name]',
|
|
price: 123,
|
|
quantity: 123,
|
|
isLoading: true,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: 'imageUrl',
|
|
text: 'item[medicine_name]',
|
|
price: 123,
|
|
quantity: 123,
|
|
isLoading: true,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: 'imageUrl',
|
|
text: 'item[medicine_name]',
|
|
price: 123,
|
|
quantity: 123,
|
|
isLoading: true,
|
|
)
|
|
],
|
|
)
|
|
else
|
|
for (var item in _stockList)
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: item['medicine_name'].toString(),
|
|
price: item['price'].toDouble(),
|
|
quantity: item['quantity'].toDouble(),
|
|
isLoading: false,
|
|
),
|
|
],
|
|
)),
|
|
const Gap(16),
|
|
const IndicatorWidget(text: 'For Fever'),
|
|
const Gap(8),
|
|
SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Row(
|
|
children: [
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 0,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
],
|
|
)),
|
|
const Gap(16),
|
|
const IndicatorWidget(text: 'For Headaches'),
|
|
const Gap(8),
|
|
SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Row(
|
|
children: [
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
],
|
|
)),
|
|
const Gap(16),
|
|
const IndicatorWidget(text: 'For Colds and Coughes'),
|
|
const Gap(8),
|
|
SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Row(
|
|
children: [
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
],
|
|
)),
|
|
const Gap(16),
|
|
const IndicatorWidget(text: 'For Infection and Irritations'),
|
|
const Gap(8),
|
|
SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Row(
|
|
children: [
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
ItemCardWidget(
|
|
imageUrl: imageUrl,
|
|
text: 'sample',
|
|
price: 500,
|
|
quantity: 15,
|
|
isLoading: imageUrl.isEmpty,
|
|
),
|
|
],
|
|
)),
|
|
],
|
|
)
|
|
],
|
|
)));
|
|
}
|
|
}
|