import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:gap/gap.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/input_widget.dart'; import 'package:pharmacy_mobile/widgets/item_card_widget.dart'; class CustomerSearchPage extends StatefulWidget { const CustomerSearchPage({super.key}); @override State createState() => _CustomerSearchPageState(); } class _CustomerSearchPageState extends State { final _searchController = TextEditingController(); final _storage = Storage(); final _stocks = Stocks(); // final _refMedicines = RefMedicines(); late String imageUrl = ''; late List _stockList = []; Future _getURL() async { final image = await _storage.getPublicURL('ref_medicines_images', 'a3e430fe-86c1-4d46-9c6a-aed2dae57fef.webp'); setState(() { imageUrl = image; }); } Future _getAllStocks() async { _stockList = await _stocks.getList(); log(_stockList.toString()); } // 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 _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 + 350, child: Column( children: [ Column( children: [ const Gap(96), const CustomerTitleWidget(), const Gap(8), Container( padding: const EdgeInsets.only(left: 64, right: 64), child: Column( children: [ InputWidget( label: '', controller: _searchController, placeholder: 'Search for medicine', ), ], ), ), const Gap(32), SizedBox( height: MediaQuery.of(context).size.height + 110, child: SingleChildScrollView( child: Column( children: List.generate(_stockList.length, (index) { return Padding( padding: const EdgeInsets.fromLTRB(0, 8, 0, 8), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ItemCardWidget( imageUrl: imageUrl, text: 'sample', price: 500, quantity: 15, isLoading: imageUrl.isEmpty, ), ItemCardWidget( imageUrl: imageUrl, text: 'sample', price: 20, quantity: 85, isLoading: imageUrl.isEmpty, ), ], ), ); }), ), ), ) ], ) ], ))); } }