Skip to content

feat: Added a Search bar #2702

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

Open
wants to merge 5 commits into
base: flutter
Choose a base branch
from

Conversation

Yugesh-Kumar-S
Copy link

@Yugesh-Kumar-S Yugesh-Kumar-S commented May 24, 2025

Closes #2704
Since the PSLab has many instruments , it becomes hard for users to scroll down to search a specific instrument . So i have added a search bar that filters the instruments based on the instrument name.

Changes

  • Implemented a search bar

Screenshots / Recordings

Screen.Recording.2025-05-25.185557.mp4

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Add a search bar to the Instruments screen to allow users to filter the list of instruments by name.

New Features:

  • Add a styled search TextField with clear button at the top of the Instruments screen
  • Implement case-insensitive filtering of the instrument list based on the search query
  • Show an empty-state view with icon and message when no instruments match the search term

Copy link

sourcery-ai bot commented May 24, 2025

Reviewer's Guide

Introduces a real-time search feature in InstrumentsScreen by adding state and filtering logic, refactoring the UI to include a search bar with clear/empty-state handling, and updating the list rendering to reflect the filtered results.

Sequence Diagram: Instrument Filtering

sequenceDiagram
    actor User
    participant TextField
    participant ISS as _InstrumentsScreenState

    User->>TextField: Types search query
    TextField->>ISS: onChanged(query)
    ISS->>ISS: _filterInstruments(query)
    ISS->>ISS: setState()
Loading

Sequence Diagram: Clearing Search Input

sequenceDiagram
    actor User
    participant CB as ClearButton
    participant ISS as _InstrumentsScreenState
    participant SC as _searchController

    User->>CB: Taps clear icon
    CB->>ISS: onPressed()
    ISS->>SC: clear()
    ISS->>ISS: _filterInstruments('')
    ISS->>ISS: setState()
Loading

Class Diagram: Changes to _InstrumentsScreenState

classDiagram
    class _InstrumentsScreenState {
        +TextEditingController _searchController
        +List<int> _filteredIndices
        +void initState()
        +void dispose()
        +void _filterInstruments(String query)
        +Widget build(BuildContext context)
        +void _onItemTapped(int index)
    }
Loading

File-Level Changes

Change Details Files
Implemented search filter logic and state management
  • Added TextEditingController (_searchController) and List (_filteredIndices)
  • Created _filterInstruments() to update filteredIndices based on the query
  • Initialized _filteredIndices in initState to show all items by default
  • Disposed _searchController in dispose()
lib/view/instruments_screen.dart
Refactored InstrumentsScreen UI to integrate the search bar
  • Wrapped the list view in a Column to place the TextField above the list
  • Inserted TextField with prefix/suffix icons, themed borders, and clear‐button behavior
  • Conditionally render a ‘no results’ placeholder when filteredIndices is empty
  • Updated ListView.builder to use _filteredIndices for itemCount and lookup
lib/view/instruments_screen.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CloudyPadmal
Copy link
Collaborator

Looks like a good addition. The build is failing for deprecated libraries.

@Yugesh-Kumar-S
Copy link
Author

Looks like a good addition. The build is failing for deprecated libraries.

Replaced deprecated libraries with their latest supported alternatives to fix the build issues.

Copy link

github-actions bot commented May 25, 2025

@AsCress AsCress self-requested a review May 26, 2025 02:22
@hpdang hpdang requested a review from CloudyPadmal May 26, 2025 11:27
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit too wide. Can you check what is the average padding between a search bar and a similar looking list item in other established Flutter apps?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked a few Flutter apps, and it seems that 16px is commonly used for horizontal padding, while vertical padding ranges from 8px to 16px. I will make the changes based on your suggestion sir.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding: const EdgeInsets.symmetric(vertical: 8.0,horizontal: 16.0)
image

Copy link
Collaborator

@CloudyPadmal CloudyPadmal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good addition!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants