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

keyboard issue while closing #190

Open
sabari7320 opened this issue Nov 21, 2024 · 6 comments
Open

keyboard issue while closing #190

sabari7320 opened this issue Nov 21, 2024 · 6 comments
Labels
in triage Issue is currently being triaged waiting for author waiting for author to respond back with more info

Comments

@sabari7320
Copy link

sabari7320 commented Nov 21, 2024

Describe the bug
When I select a value from the dropdown and then close the keyboard, the selected value disappears, and the dropdown list resets to its initial state

SearchField(
autovalidateMode: AutovalidateMode.onUserInteraction,
onTapOutside: null,
        focusNode: _otherTextFieldFocusNode,
          suggestionStyle: TextStyle(decoration: TextDecoration.none),
          searchInputDecoration: SearchInputDecoration(
            border: InputBorder.none,
            labelText: 'State',
            enabledBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.grey),
                borderRadius: BorderRadius.circular(10)),
            focusedBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.grey),
                borderRadius: BorderRadius.circular(10)),
            disabledBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.grey),
                borderRadius: BorderRadius.circular(10)),
            errorBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.red),
                borderRadius: BorderRadius.circular(10)),
            focusedErrorBorder:OutlineInputBorder(
                borderSide: BorderSide(color: Colors.red),
                borderRadius: BorderRadius.circular(10)),
            hintStyle: TextStyle(color: Colors.black),
            contentPadding: const EdgeInsets.symmetric(vertical: 1.0, horizontal: 15),
          ),

          onSuggestionTap: (selectedValue) {
            print("Selected state: ${selectedValue.item}");
            stateController.text = selectedValue.item!;
            fetchCityList(countryController.text, selectedValue.item!);
            FocusScope.of(context).unfocus();
          },
          suggestions: stateList.isEmpty
          ? [SearchFieldListItem("No state available", child: Text("No state available"))]
              :stateList.map((state) => SearchFieldListItem(
            state,
            item: state,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(state),
            ),
          ))
              .toList(),
          itemHeight: 55,
          maxSuggestionsInViewPort: 4,
          controller: stateController,
          validator: (selectedValue) {
            if (selectedValue == null || !stateList.contains(selectedValue)) {
              return 'Please select State';
            }
            return null;
          },
        ),
media_20241105_152647_3776325864368482703.mp4
@maheshj01
Copy link
Owner

maheshj01 commented Nov 22, 2024

Hi @sabari7320,
I tried to reproduce the bug using the below code sample, But I am unable to reproduce it. Please provide more details

  1. version of searchfield
  2. output of flutter doctor -v
  3. is this reproducible on a specific device or all devices?
  4. is this reproducible in debug/release or both

It would be great if you can try to modify the below code sample and provide a reproducible code sample with steps to reproduce the issue.

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',
    ];
    selected = suggestions[0];
    super.initState();
  }

  int suggestionsCount = 12;
  final _otherTextFieldFocusNode = FocusNode();
  final TextEditingController searchController = TextEditingController();
  var suggestions = <String>[];
  int counter = 0;
  var selected = '';
  @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')),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            children: [
              Spacer(),
              SearchField(
                autovalidateMode: AutovalidateMode.onUserInteraction,
                onTapOutside: null,
                focusNode: _otherTextFieldFocusNode,
                suggestionStyle: TextStyle(decoration: TextDecoration.none),
                searchInputDecoration: SearchInputDecoration(
                  border: InputBorder.none,
                  labelText: 'State',
                  enabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.grey),
                      borderRadius: BorderRadius.circular(10)),
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.grey),
                      borderRadius: BorderRadius.circular(10)),
                  disabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.grey),
                      borderRadius: BorderRadius.circular(10)),
                  errorBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.red),
                      borderRadius: BorderRadius.circular(10)),
                  focusedErrorBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.red),
                      borderRadius: BorderRadius.circular(10)),
                  hintStyle: TextStyle(color: Colors.black),
                  contentPadding:
                      const EdgeInsets.symmetric(vertical: 1.0, horizontal: 15),
                ),
                onSuggestionTap: (selectedValue) {},
                suggestions: suggestions.isEmpty
                    ? [
                        SearchFieldListItem("No state available",
                            child: Text("No state available"))
                      ]
                    : suggestions
                        .map((state) => SearchFieldListItem(
                              state,
                              item: state,
                              child: Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: Text(state),
                              ),
                            ))
                        .toList(),
                itemHeight: 55,
                maxSuggestionsInViewPort: 4,
                validator: (selectedValue) {
                  if (selectedValue == null ||
                      !suggestions.contains(selectedValue)) {
                    return 'Please select State';
                  }
                  return null;
                },
              ),
              SizedBox(height: 100),
            ],
          ),
        ));
  }
}

@maheshj01 maheshj01 added the waiting for author waiting for author to respond back with more info label Nov 22, 2024
@sunilpandit2
Copy link

i am facing same issue

@maheshj01
Copy link
Owner

@sunilpandit2 Can you provide the information requested above? It will help me investigate the issue

@sabari7320
Copy link
Author

sabari7320 commented Nov 25, 2024

if i click the back button again the same values appear
in my mobile

@maheshj01
Copy link
Owner

@sabari7320 can you provide this info ?

@maheshj01
Copy link
Owner

@sabari7320 Can you try the latest release v1.1.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in triage Issue is currently being triaged waiting for author waiting for author to respond back with more info
Projects
None yet
Development

No branches or pull requests

3 participants