Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomSearchDelegateFerns extends SearchDelegate {
- @override
- List<Widget> buildActions(BuildContext context) {
- return [
- IconButton(
- onPressed: (){
- query = '';
- },
- icon: const Icon(Icons.clear))
- ];
- }
- @override
- Widget buildLeading(BuildContext context) {
- return IconButton(
- onPressed: (){
- close(context, null);
- },
- icon: const Icon(Icons.arrow_back)
- );
- }
- List<String> searchTermsName = [
- 'Адиантум венерин волос',
- 'Адиантум хвостатый',
- 'Адиантум стоповидный',
- 'Птерис критский',
- 'Птерис мечевидный',
- 'Блехнум',
- 'Нефролепис сердцелистный',
- 'Нефролепис мечевидный',
- 'Нефролепис возвышенный',
- 'Асплениум гнездовой',
- 'Асплениум луковиценосный',
- 'Асплениум двуформенный',
- 'Циртомиум серповидный',
- 'Даваллия канарская',
- 'Даваллия рассечённая',
- ];
- List<String> searchTermsImage = [
- 'https://cdn.botanichka.ru/wp-content/uploads/2009/11/Adiantum-capillus-veneris-3-1-210x210.jpg',
- 'https://i.pinimg.com/736x/68/9d/bb/689dbbc3500b965a0e4add738a2990ad.jpg',
- 'https://i.pinimg.com/736x/bb/35/b6/bb35b645ad0bb170d46e23ce5471d063.jpg',
- 'https://cdn.100sp.ru/pictures/351388381',
- 'https://i.etsystatic.com/20406392/r/il/a18300/2509424111/il_794xN.2509424111_fif3.jpg',
- 'https://cdn.botanichka.ru/wp-content/uploads/2017/09/Blechnum-03-640x800.jpg',
- 'https://cdn.botanichka.ru/wp-content/uploads/2010/04/Nephrolepis_cordifolia_03-640x825.jpg',
- 'https://cdn.botanichka.ru/wp-content/uploads/2010/04/Nephrolepis_biserrata_1-640x853.jpg',
- 'https://cdn.botanichka.ru/wp-content/uploads/2010/04/Nephrolepis_exaltata_01-640x853.jpg',
- 'https://i.pinimg.com/564x/c0/a8/17/c0a8178fe01b66f687df4cfd1e1c8371.jpg',
- 'https://bloom-story.ru/wa-data/public/shop/products/04/27/2704/images/6536/6536.750.jpg',
- 'https://www.gardentags.com/profile/elicia/images/327842/750/asplenium-dimorphum-x-difforme.jpeg',
- 'https://cvetpodokonnik.ru/wa-data/public/shop/products/96/07/796/images/2302/2302.970.jpg',
- 'https://klau.club/uploads/posts/2023-03/thumbs/1677622360_klau-club-p-davana-rastenie-krasivo-23.png',
- 'https://i5.walmartimages.com/asr/db453a16-9cba-482c-acf7-95d28963df2b_1.a26702021d8199000def5af913252372.jpeg',
- ];
- List<String> searchTermsSubName = [
- 'Adiantum capillus-veneris',
- 'Adiantum caudatum',
- 'Adiantum pedatum',
- 'Pteris cretica',
- 'Pteris ensiformis',
- 'Blechnum spicant',
- 'Nephrolepis cordifolia',
- 'Nephrolepis biserrata',
- 'Nephrolepis exaltata',
- 'Asplenium nidus',
- 'Asplenium bulbiferum',
- 'Asplenium dimorphum',
- 'Cyrtomium falcatum',
- 'Davallia canariensis',
- 'Davallia dissecta',
- ];
- @override
- Widget buildResults(BuildContext context) {
- List<String> matchQueryName = [];
- List<String> matchQueryImage = [];
- List<String> matchQuerySubName = [];
- int i = 0;
- for (var fruit in searchTermsName) {
- if (fruit.toLowerCase().contains(query.toLowerCase())){
- matchQueryName.add(fruit);
- matchQueryImage.add(searchTermsImage[i]);
- matchQuerySubName.add(searchTermsSubName[i]);
- }
- i++;
- }
- int z = 0;
- for (var fruit in searchTermsSubName) {
- if (fruit.toLowerCase().contains(query.toLowerCase())){
- matchQueryName.add(searchTermsName[z]);
- matchQueryImage.add(searchTermsImage[z]);
- matchQuerySubName.add(searchTermsSubName[z]);
- }
- z++;
- }
- return ListView.builder(
- itemCount: matchQueryName.length,
- itemBuilder: (context, index){
- var name = matchQueryName[index];
- var image = matchQueryImage[index];
- var subName = matchQuerySubName[index];
- return elements(ElementName: name, ElementSubName: subName, ElementImage: image);
- }
- );
- }
- @override
- Widget buildSuggestions(BuildContext context) {
- List<String> matchQueryName = [];
- List<String> matchQueryImage = [];
- List<String> matchQuerySubName = [];
- int i = 0;
- for (var fruit in searchTermsName) {
- if (fruit.toLowerCase().contains(query.toLowerCase())){
- matchQueryName.add(fruit);
- matchQueryImage.add(searchTermsImage[i]);
- matchQuerySubName.add(searchTermsSubName[i]);
- }
- i++;
- }
- int z = 0;
- for (var fruit in searchTermsSubName) {
- if (fruit.toLowerCase().contains(query.toLowerCase())){
- matchQueryName.add(searchTermsName[z]);
- matchQueryImage.add(searchTermsImage[z]);
- matchQuerySubName.add(searchTermsSubName[z]);
- }
- z++;
- }
- return ListView.builder(
- itemBuilder: (context, index){
- var name = matchQueryName[index];
- var image = matchQueryImage[index];
- var subName = matchQuerySubName[index];
- return elements(ElementName: name, ElementSubName: subName, ElementImage: image);
- },
- itemCount: query == '' ? matchQueryName.length ~/ 2 : matchQueryName.length,
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement