Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index out of bound on SuggestionDirection.up #205

Closed
muhammad-hassan-shakeel opened this issue Jan 27, 2025 · 2 comments
Closed

Index out of bound on SuggestionDirection.up #205

muhammad-hassan-shakeel opened this issue Jan 27, 2025 · 2 comments
Labels
bug Something isn't working fixed The issue is fixed in new release P1 High Priority: This is a show stopper and must be addressed immediately

Comments

@muhammad-hassan-shakeel

Describe the bug
After setting suggestionDirection = SuggestionDirection.up, tapping an element from suggestion list throws index out of bound exception

To Reproduce
Steps to reproduce the behavior:

  1. Add suggestionDirection: SuggestionDirection.up in the searchfield widget.
  2. Run the example application (I tried on the web)
  3. Tap on the search field
  4. Select any element from the suggestion list
  5. the element won't appear selected on the text field and console will show index out of bound exception
    [Yes] By clicking this checkbox, I confirm I am using the latest version of the package found on pub.dev/searchfield

Expected behavior
Element from suggestions should get selected and show on the text field without index out of bound exception.

Actual behavior
Element from suggestions doesn't get selected and throws index out of bound exception.

Screenshots
If applicable, add screenshots to help explain your problem.

Code sample

Show code sample
// import 'package:example/pagination.dart';
import 'package:flutter/material.dart';
import 'package:searchfield/searchfield.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter App',
      theme: ThemeData(
        colorSchemeSeed: Colors.indigo,
        useMaterial3: true,
        brightness: Brightness.light,
      ),
      darkTheme: ThemeData(
        colorSchemeSeed: Colors.blue,
        useMaterial3: true,
        brightness: Brightness.dark,
      ),
      home: SearchFieldSample(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class SearchFieldSample extends StatefulWidget {
  const SearchFieldSample({Key? key}) : super(key: key);

  @override
  State<SearchFieldSample> createState() => _SearchFieldSampleState();
}

class _SearchFieldSampleState extends State<SearchFieldSample> {
  @override
  void initState() {
    suggestions = [
      'United States',
      'Germany',
      'Canada',
      'United Kingdom',
      'France',
      'Italy',
      'Spain',
      'Australia',
      'India',
      'China',
      'Japan',
      'Brazil',
      'South Africa',
      'Mexico',
      'Argentina',
      'Russia',
      'Indonesia',
      'Turkey',
      'Saudi Arabia',
      'Nigeria',
      'Egypt',
    ];
    super.initState();
  }

  var suggestions = <String>[];
  var selectedValue = null;
  @override
  Widget build(BuildContext context) {
    Widget searchChild(x, {bool isSelected = false}) => Padding(
          padding: const EdgeInsets.symmetric(horizontal: 12),
          child: Text(x,
              style: TextStyle(
                  fontSize: 18,
                  color: isSelected ? Colors.green : Colors.black)),
        );
    return Scaffold(
        appBar: AppBar(title: Text('Searchfield Demo test')),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            spacing: 20,
            children: [
              SearchField(
                hint: 'Basic SearchField',
                dynamicHeight: true,
                maxSuggestionBoxHeight: 300,
                suggestionDirection: SuggestionDirection.up,
                onSuggestionTap: (SearchFieldListItem<String> item) {
                  setState(() {
                    selectedValue = item;
                  });
                },
                selectedValue: selectedValue,
                suggestions: suggestions
                    .map(
                      (x) => SearchFieldListItem<String>(
                        x,
                        item: x,
                        child: searchChild(x),
                      ),
                    )
                    .toList(),
                suggestionState: Suggestion.expand,
              ),
            ],
          ),
        ));
  }
}

Additional context
Add any other context about the problem here.

@maheshj01 maheshj01 added the in triage Issue is currently being triaged label Jan 27, 2025
@maheshj01
Copy link
Owner

Thanks for filing the issue and I really appreciate the PR. I was able to reproduce the issue.

@maheshj01 maheshj01 added bug Something isn't working P1 High Priority: This is a show stopper and must be addressed immediately and removed in triage Issue is currently being triaged labels Jan 27, 2025
@maheshj01
Copy link
Owner

Fixed and released in v1.2.4
Thank you for your contribution @muhammad-hassan-shakeel

@maheshj01 maheshj01 added the fixed The issue is fixed in new release label Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed The issue is fixed in new release P1 High Priority: This is a show stopper and must be addressed immediately
Projects
None yet
Development

No branches or pull requests

2 participants