maheshj01 / searchfield

A highly customizable simple and easy to use flutter Widget to add a searchfield to your Flutter Application.This Widget allows you to search and select from list of suggestions.
MIT License
84 stars 63 forks source link

Selecting Suggestions with a Keyboard throws error #166

Closed Princewil closed 2 months ago

Princewil commented 2 months ago

Hi dear, thanks a lot for this package.

I recommend you go through the video attached to this first.

I create a desktop application where the user interact more with their physical keyboard. I used this package to give suggestions of product stored on the backend as seen in the video. The searchtextfield is meant to only contain any selected suggestion from the suggestion list, anything else is disregarded. So I observed when I use my keyboard to interact with the suggestions and click on the enter key, the onSubmit callback is called but this callback returns the string on the textfield and not the selected suggestion. And it becomes a problem if there is not text on the textfield as seen on this video. Now In my attempt in trying to return something I wrote a logic that returns the best possible suggestion using the returned string gotten from the callback(see code

Screenshot 2024-09-01 at 11 28 02

). But this does not give the best results as seen in the video.

https://github.com/user-attachments/assets/31ba284c-f0c3-45ff-885c-fee38dba7417

Describe the solution you'd like Is there a way to return the index of selected suggestion via the onsubmit callback

Describe alternatives you've considered Or probably return the suggestion itself.

Thanks

maheshj01 commented 2 months ago

Hi @Princewil, Are you using the latest version of the plugin on pub.dev? I am guessing you are seeing the same issue as https://github.com/maheshj01/searchfield/issues/159 which was fixed in the latest release

Princewil commented 2 months ago

Yea I am using the latest version which is v1.0.9

maheshj01 commented 2 months ago

@Princewil Please share a minimal and complete reprpduciblel code sample.

Princewil commented 2 months ago

Now run the below code on your desktop and try selecting any suggestion with YOUR PHYSICAL KEYBOARD ONLY and press the ENTER Key to pick an option

import 'package:flutter/material.dart';
import 'package:searchfield/searchfield.dart';

class Code extends StatelessWidget {
  const Code({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SearchField(
          suggestions: ['ABC', 'DEF', 'GHI', 'JKL']
              .map((e) => SearchFieldListItem(e, child: Text(e)))
              .toList(),
          onSubmit: (v) => print(v),
          onSuggestionTap: (v) {
            print('SuggestionTaped => ${v.searchKey}');
          },
          onScroll: (p, p1) {
            print(p);
            print(p1);
          },
        ),
      ),
    );
  }
}

You get this error Null check operator used on a null value

maheshj01 commented 2 months ago

@Princewil I Appreciate the minimal code sample, I was able to reproduce the issue, I will take a look at it.

Thanks

Princewil commented 2 months ago

Alright bro Thanks

maheshj01 commented 2 months ago

released in v1.1.1