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

Exception that occurs when accessing data without data #192

Open
cw-20021366 opened this issue Nov 27, 2024 · 5 comments
Open

Exception that occurs when accessing data without data #192

cw-20021366 opened this issue Nov 27, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@cw-20021366
Copy link

cw-20021366 commented Nov 27, 2024

Describe the bug
I am making a program for MacOS/Windows.
I want to receive focus and send data continuously whenever the Enter key is pressed as a keyboard event in SearchField. In order to prevent the suggestions list from being displayed every time the focus comes, I did the following, but an exception occurred at a specific location in SearchField.

Exception Screenshots

2024-11-27.9.24.28.mov

Code sample

Show code
  String keyboardInputStr = '';
  bool isKeyboardEnter = false;
  bool isSendMsg = false;
  int selectCompanyKindSet = 0;
  final TextEditingController sendMsgControl = TextEditingController();
  final FocusNode sendFocusNode = FocusNode();
  List<String> companyKindSet = ['company1', 'company2'];
  List<String> noneCmdSet = [];
  List<List<String>> cmdSetList = [
    //company1
    [
      "Log Level 설정(양산레벨)> ABC",
      "Log Level 설정(Info레벨)> AAA",
      "Log Level 설정(디버깅레벨)> BBB",
      "모듈 설정값 확인> CCCC",
      "ALFI 항목 확인> KKK",
      "모듈 리부팅> 0000",
      "페어링 정보 확인> 11111",
      "인증 정보 확인> 2222",
      "FOTA 정보 확인> 3333",
      "FOTA 정보 초기화> 4444",
      "현재 시간 정보 확인> 555",
      "WLAN 연결 정보 확인> 6666",
      "PING 테스트> ping=192.168.0.1",
      "다운로드 모드 진입> 7777",
      "WiFi Scan List 출력> 888",
      "공장 초기화> 9999"
    ],
    //company2
    [
      "Log Level 설정(양산레벨)> ppppp",
      "Log Level 설정(WiFi Info 레벨)> lllll",
      "Log Level 설정(Common Info 레벨)> ccccc",
      "모듈 설정값 확인> ggggg",
      "FOTA 정보 확인> 11111",
      "테스트 모드 진입> 3434",
      "WiFi Scan List 출력(테스트모드에서만 가능)> 09900",
      "테스트 모드 종료> 123211",
      "공장(설정) 초기화> fddsfsdfdsf"
    ]
  ];

.....  
                            SizedBox(
                              width: dispWidth * 0.8,
                              child: KeyboardListener(
                                focusNode: sendFocusNode,
                                onKeyEvent: (event) {
                                  if (event.logicalKey == LogicalKeyboardKey.enter) {
                                    if (event is KeyDownEvent) {
                                      isKeyboardEnter = true;
                                    }
                                  } else {
                                    if (isSendMsg) {
                                      setState(() {
                                        isSendMsg = false;
                                      });
                                    }
                                  }
                                },
                                child: SearchField<String>(
                                  textInputAction: TextInputAction.send,
                                  suggestionDirection: SuggestionDirection.up,
                                  suggestionAction: SuggestionAction.next,
                                  searchInputDecoration: SearchInputDecoration(
                                    labelText: 'Input Msg',
                                    cursorColor: Colors.blue,
                                    border: OutlineInputBorder(
                                      borderRadius: BorderRadius.circular(10),
                                    ),
                                  ),
                                  onSuggestionTap: (SearchFieldListItem<String> item) {
                                    //debugPrint('onSuggestionTap');
                                    if (isKeyboardEnter) {
                                      sendMsgControl.text = keyboardInputStr;
                                      //debugPrint('isKeyboardEnter call');
                                      isKeyboardEnter = false;
                                      FocusManager.instance.primaryFocus?.requestFocus();
                                      sendMsgFuc();
                                      keyboardInputStr = '';
                                      setState(() {
                                        isSendMsg = true;
                                      });
                                    } else {
                                      //debugPrint('mouse select call');
                                      String inputText = item.searchKey;
                                      int parserCnt = item.searchKey.indexOf('> ');
                                      if (parserCnt > 0) {
                                        inputText = item.searchKey.substring(parserCnt + 2, item.searchKey.length);
                                      }
                                      sendMsgControl.text = inputText;
                                    }
                                  },
                                  suggestions: !isSendMsg
                                      ? cmdSetList[selectCompanyKindSet]
                                          .map(
                                            (e) => SearchFieldListItem<String>(e,
                                                item: e, child: searchChild(e, isSelected: e == sendMsgControl.text)),
                                          )
                                          .toList()
                                      : noneCmdSet
                                          .map(
                                            (e) => SearchFieldListItem<String>(e,
                                                item: e, child: searchChild(e, isSelected: e == sendMsgControl.text)),
                                          )
                                          .toList(),
                                  controller: sendMsgControl,
                                  onSubmit: (sendStr) {
                                    //debugPrint('onSubmit $sendStr');
                                    FocusManager.instance.primaryFocus?.requestFocus();
                                    sendMsgFuc();
                                    isKeyboardEnter = false;
                                    setState(() {
                                      isSendMsg = true;
                                    });
                                  },
                                  onTapOutside: (sendStr) {
                                    FocusManager.instance.primaryFocus?.unfocus();
                                  },
                                  onTap: () {
                                    setState(() {
                                      isSendMsg = false;
                                    });
                                  },
                                  onSearchTextChanged: (sendStr) {
                                    //debugPrint('onSearchTextChanged $sendStr');
                                    keyboardInputStr = sendStr;
                                    final filter = cmdSetList[selectCompanyKindSet].where((element) => element.contains(sendStr)).toList();
                                    return filter.map((e) => SearchFieldListItem<String>(e, child: searchChild(e))).toList();
                                  },
                                ),
                              ),
                            ),

Exception Exception Log

Show log
======== Exception caught by widgets library =======================================================
The following RangeError was thrown building _FocusInheritedScope:
RangeError (length): Invalid value: Valid value range is empty: 0

The relevant error-causing widget was: 
  KeyboardListener KeyboardListener:file:///Users/hwkim/Documents/GitHub/flutter_window_test/lib/main.dart:1039:38
When the exception was thrown, this was the stack: 
#0      List.[] (dart:core-patch/growable_array.dart)
#1      _SearchFieldState.didUpdateWidget.<anonymous closure> (package:searchfield/src/searchfield.dart:677:64)
#2      ListBase.indexWhere (dart:collection/list.dart:460:15)
#3      _SearchFieldState.didUpdateWidget (package:searchfield/src/searchfield.dart:676:41)
#4      StatefulElement.update (package:flutter/src/widgets/framework.dart:5789:55)
#5      Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#6      SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#7      Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#8      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#9      Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#10     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#11     _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:105:11)
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#14     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#15     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#16     StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#17     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#18     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#19     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#20     StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#21     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#22     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#23     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#24     Element.updateChildren (package:flutter/src/widgets/framework.dart:4090:32)
#25     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7060:17)
#26     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#27     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#28     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#29     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#30     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#31     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#32     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#33     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#34     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#35     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#36     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#38     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#39     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#40     StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#41     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#42     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#43     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#44     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#45     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#46     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#47     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#48     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#49     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#50     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#51     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#52     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#53     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#54     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#55     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#56     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#57     StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#58     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#59     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#60     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#61     StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#62     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#63     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#64     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#65     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#66     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#67     Element.updateChildren (package:flutter/src/widgets/framework.dart:4090:32)
#68     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7060:17)
#69     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#70     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#71     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#72     StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#73     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#74     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#75     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#76     StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#77     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#78     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#79     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#80     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#81     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#82     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#83     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#84     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#85     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#86     Element.updateChildren (package:flutter/src/widgets/framework.dart:4090:32)
#87     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7060:17)
#88     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#89     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#90     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#91     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#92     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#93     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#94     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#95     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#96     StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#97     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#98     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#99     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#100    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#101    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#102    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#103    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#104    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#105    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#106    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#107    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#108    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#109    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#110    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#111    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#112    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#113    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#114    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#115    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#116    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#117    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#118    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#119    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#120    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#121    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#122    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#123    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#124    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#125    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#126    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#127    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#128    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#129    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#130    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#131    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#132    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#133    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#134    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#135    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#136    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#137    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#138    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#139    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#140    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#141    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#142    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#143    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#144    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#145    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#146    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#147    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#148    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#149    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#150    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#151    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#152    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#153    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#154    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#155    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#156    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#157    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#158    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#159    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#160    StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#161    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#162    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#163    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#164    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#165    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#166    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#167    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#168    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#169    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#170    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#171    Element.updateChildren (package:flutter/src/widgets/framework.dart:4090:32)
#172    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7060:17)
#173    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#174    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#175    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#176    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#177    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#178    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#179    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#180    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#181    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#182    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#183    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#184    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#185    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#186    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#187    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#188    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#189    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#190    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#191    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#192    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#193    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#194    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#195    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#196    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#197    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#198    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#199    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#200    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#201    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#202    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#203    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#204    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#205    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#206    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#207    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#208    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#209    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#210    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#211    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#212    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#213    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#214    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#215    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#216    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#217    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#218    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#219    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#220    _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:105:11)
#221    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#222    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#223    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#224    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#225    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#226    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#227    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#228    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#229    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#230    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#231    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#232    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#233    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#234    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#235    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#236    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#237    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#238    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#239    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#240    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#241    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#242    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#243    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#244    StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#245    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#246    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#247    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#248    StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#249    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#250    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#251    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#252    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#253    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#254    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#255    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#256    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#257    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#258    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#259    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#260    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#261    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#262    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#263    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#264    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#265    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#266    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#267    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#268    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#269    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#270    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#271    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#272    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#273    BuildScope._tryRebuild (package:flutter/src/widgets/framework.dart:2693:15)
#274    BuildScope._flushDirtyElements (package:flutter/src/widgets/framework.dart:2752:11)
#275    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3048:18)
#276    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1162:21)
#277    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:468:5)
#278    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#279    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1318:9)
#280    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#281    _invoke (dart:ui/hooks.dart:312:13)
#282    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#283    _drawFrame (dart:ui/hooks.dart:283:31)
====================================================================================================

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
'package:flutter/src/rendering/object.dart': Failed assertion: line 3374 pos 12: 'attached': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack: 
#2      RenderObject.getTransformTo (package:flutter/src/rendering/object.dart:3374:12)
#3      RenderBox.localToGlobal (package:flutter/src/rendering/box.dart:2887:39)
#4      RenderEditable._snapToPhysicalPixel (package:flutter/src/rendering/editable.dart:2276:33)
#5      RenderEditable.getLocalRectForCaret (package:flutter/src/rendering/editable.dart:1822:28)
#6      EditableTextState._updateComposingRectIfNeeded (package:flutter/src/widgets/editable_text.dart:4498:38)
#7      EditableTextState._schedulePeriodicPostFrameCallbacks (package:flutter/src/widgets/editable_text.dart:4405:5)
#8      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#9      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1331:11)
#10     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#11     _invoke (dart:ui/hooks.dart:312:13)
#12     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#13     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)
====================================================================================================

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
'package:flutter/src/rendering/object.dart': Failed assertion: line 3374 pos 12: 'attached': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack: 
#2      RenderObject.getTransformTo (package:flutter/src/rendering/object.dart:3374:12)
#3      RenderBox.localToGlobal (package:flutter/src/rendering/box.dart:2887:39)
#4      RenderEditable._snapToPhysicalPixel (package:flutter/src/rendering/editable.dart:2276:33)
#5      RenderEditable.getLocalRectForCaret (package:flutter/src/rendering/editable.dart:1822:28)
#6      EditableTextState._scheduleShowCaretOnScreen.<anonymous closure> (package:flutter/src/widgets/editable_text.dart:4051:45)
#7      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#8      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1331:11)
#9      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#10     _invoke (dart:ui/hooks.dart:312:13)
#11     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#12     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)
====================================================================================================

Temporarily handle exceptions in your 'searchfield.dart' code

Show code
void didUpdateWidget(covariant SearchField<T> oldWidget) {
    if (oldWidget.controller != widget.controller) {
      searchController = widget.controller ?? TextEditingController();
    }
    if (_suggestionDirection != oldWidget.suggestionDirection) {
      _suggestionDirection = widget.suggestionDirection;
    }
    if (oldWidget.suggestions != widget.suggestions) {
      length = widget.suggestions.length;
      suggestionStream.sink.add(widget.suggestions);
      lastSearchResult.clear();
      lastSearchResult.addAll(widget.suggestions);
      // if a item was already selected
      if (selected != null && selected! >= 0) {
        if (oldWidget.suggestions.isNotEmpty) { //add here
          selected = widget.suggestions.indexWhere(
                  (element) => element == oldWidget.suggestions[selected!]);
        }
      }
    }
    ....
}

Success Screenshots

2024-11-27.9.17.11.mov
@maheshj01 maheshj01 added the in triage Issue is currently being triaged label Nov 28, 2024
@maheshj01
Copy link
Owner

maheshj01 commented Nov 29, 2024

Hi @cw-20021366 I made a PR #191 Which I believe will fix this issue.
You might want to try the latest version which will be published soon or you can try the latest fix by adding to pubspec

 searchfield:
    git:
      url: https://github.com/maheshmnj/searchfield.git
      ref: master

and then Deleting 'pubspec.lock' run flutter clean and flutter pub get

Code sample
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')),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: ListView(
            children: [
              SearchField(
                suggestionDirection: SuggestionDirection.flex,
                onSearchTextChanged: (query) {
                  final filter = suggestions
                      .where((element) =>
                          element.toLowerCase().contains(query.toLowerCase()))
                      .toList();
                  return filter
                      .map((e) =>
                          SearchFieldListItem<String>(e, child: searchChild(e)))
                      .toList();
                },
                selectedValue: selectedValue,
                autovalidateMode: AutovalidateMode.onUserInteraction,
                validator: (value) {
                  if (value == null || !suggestions.contains(value.trim())) {
                    return 'Enter a valid country name';
                  }
                  return null;
                },
                maxSuggestionsInViewPort: 10,
                onSubmit: (x) {},
                autofocus: false,
                key: const Key('searchfield'),
                hint: 'Search by country name',
                itemHeight: 50,
                scrollbarDecoration: ScrollbarDecoration(
                  thickness: 12,
                  radius: Radius.circular(6),
                  trackColor: Colors.grey,
                  trackBorderColor: Colors.red,
                  thumbColor: Colors.orange,
                ),
                suggestionStyle:
                    const TextStyle(fontSize: 18, color: Colors.black),
                suggestionItemDecoration: BoxDecoration(
                  // color: Colors.grey[100],
                  // borderRadius: BorderRadius.circular(10),
                  border: Border(
                    bottom: BorderSide(
                      color: Colors.grey.shade200,
                      width: 1,
                    ),
                  ),
                ),
                searchInputDecoration: SearchInputDecoration(
                  searchStyle: TextStyle(fontSize: 18, color: Colors.black),
                  hintStyle: TextStyle(fontSize: 18, color: Colors.grey),
                  focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(24),
                    borderSide: const BorderSide(
                      width: 1,
                      color: Colors.orange,
                      style: BorderStyle.solid,
                    ),
                  ),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(24),
                    borderSide: const BorderSide(
                      width: 1,
                      color: Colors.black,
                      style: BorderStyle.solid,
                    ),
                  ),
                  contentPadding: const EdgeInsets.symmetric(
                    horizontal: 20,
                  ),
                ),
                suggestionsDecoration: SuggestionDecoration(
                    // border: Border.all(color: Colors.orange),
                    elevation: 8.0,
                    selectionColor: Colors.grey.shade100,
                    hoverColor: Colors.purple.shade100,
                    gradient: LinearGradient(
                      colors: [
                        Color(0xfffc466b),
                        Color.fromARGB(255, 103, 128, 255)
                      ],
                      stops: [0.25, 0.75],
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                    ),
                    borderRadius: BorderRadius.only(
                      bottomLeft: Radius.circular(10),
                      bottomRight: Radius.circular(10),
                    )),
                suggestions: suggestions
                    .map((e) =>
                        SearchFieldListItem<String>(e, child: searchChild(e)))
                    .toList(),
                suggestionState: Suggestion.expand,
                onSuggestionTap: (SearchFieldListItem<String> x) {
                  setState(() {
                    selectedValue = x;
                  });
                },
              ),
            ],
          ),
        ));
  }
}

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

v1.2.0 is now live on pub.dev see the Changelog for details. Please try it out and let me know if that fixes the issue.

@cw-20021366
Copy link
Author

cw-20021366 commented Dec 2, 2024

Hi. @maheshj01
I tried v1.2.0 but unfortunately Ihad the same problem.

======== Exception caught by widgets library =======================================================
The following RangeError was thrown building _FocusInheritedScope:
RangeError (length): Invalid value: Valid value range is empty: 0

The relevant error-causing widget was: 
  KeyboardListener KeyboardListener:file:///Users/hwkim/Documents/GitHub/flutter_window_test/lib/main.dart:1028:38
When the exception was thrown, this was the stack: 
#0      List.[] (dart:core-patch/growable_array.dart)
#1      _SearchFieldState.didUpdateWidget.<anonymous closure> (package:searchfield/src/searchfield.dart:665:58)
#2      ListBase.indexWhere (dart:collection/list.dart:460:15)
#3      _SearchFieldState.didUpdateWidget (package:searchfield/src/searchfield.dart:664:45)
#4      StatefulElement.update (package:flutter/src/widgets/framework.dart:5789:55)
#5      Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#6      SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#7      Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#8      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#9      Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#10     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#11     _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:105:11)
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#14     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#15     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#16     StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#17     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#18     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#19     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#20     StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#21     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#22     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#23     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#24     Element.updateChildren (package:flutter/src/widgets/framework.dart:4090:32)
#25     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7060:17)
#26     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#27     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#28     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#29     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#30     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#31     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#32     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#33     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#34     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#35     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#36     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#38     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#39     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#40     StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#41     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#42     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#43     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#44     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#45     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#46     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#47     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#48     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#49     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#50     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#51     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#52     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#53     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#54     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#55     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#56     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#57     StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#58     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#59     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#60     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#61     StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#62     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#63     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#64     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#65     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#66     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#67     Element.updateChildren (package:flutter/src/widgets/framework.dart:4090:32)
#68     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7060:17)
#69     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#70     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#71     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#72     StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#73     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#74     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#75     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#76     StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#77     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#78     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#79     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#80     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#81     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#82     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#83     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#84     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#85     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#86     Element.updateChildren (package:flutter/src/widgets/framework.dart:4090:32)
#87     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7060:17)
#88     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#89     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#90     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#91     ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#92     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#93     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#94     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#95     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#96     StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#97     Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#98     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#99     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#100    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#101    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#102    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#103    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#104    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#105    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#106    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#107    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#108    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#109    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#110    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#111    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#112    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#113    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#114    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#115    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#116    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#117    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#118    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#119    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#120    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#121    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#122    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#123    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#124    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#125    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#126    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#127    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#128    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#129    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#130    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#131    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#132    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#133    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#134    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#135    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#136    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#137    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#138    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#139    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#140    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#141    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#142    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#143    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#144    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#145    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#146    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#147    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#148    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#149    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#150    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#151    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#152    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#153    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#154    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#155    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#156    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#157    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#158    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#159    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#160    StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#161    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#162    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#163    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#164    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#165    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#166    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#167    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#168    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#169    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#170    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#171    Element.updateChildren (package:flutter/src/widgets/framework.dart:4090:32)
#172    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:7060:17)
#173    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#174    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#175    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#176    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#177    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#178    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#179    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#180    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#181    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#182    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#183    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#184    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#185    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#186    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#187    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#188    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#189    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#190    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#191    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#192    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#193    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#194    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#195    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#196    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#197    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#198    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#199    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#200    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#201    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#202    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#203    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#204    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#205    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#206    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#207    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#208    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#209    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#210    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#211    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#212    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#213    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#214    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#215    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#216    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#217    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#218    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#219    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#220    _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:105:11)
#221    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#222    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#223    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#224    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#225    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#226    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#227    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#228    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#229    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#230    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#231    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#232    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#233    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#234    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#235    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#236    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#237    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#238    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#239    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#240    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#241    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#242    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#243    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#244    StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#245    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#246    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#247    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#248    StatelessElement.update (package:flutter/src/widgets/framework.dart:5693:5)
#249    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#250    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6907:14)
#251    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#252    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#253    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#254    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#255    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#256    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#257    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#258    ProxyElement.update (package:flutter/src/widgets/framework.dart:5946:5)
#259    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#260    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#261    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#262    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#263    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#264    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#265    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#266    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#267    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#268    StatefulElement.update (package:flutter/src/widgets/framework.dart:5803:5)
#269    Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#270    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#271    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#272    Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#273    BuildScope._tryRebuild (package:flutter/src/widgets/framework.dart:2693:15)
#274    BuildScope._flushDirtyElements (package:flutter/src/widgets/framework.dart:2752:11)
#275    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3048:18)
#276    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1162:21)
#277    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:468:5)
#278    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#279    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1318:9)
#280    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#281    _invoke (dart:ui/hooks.dart:312:13)
#282    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#283    _drawFrame (dart:ui/hooks.dart:283:31)
====================================================================================================

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
'package:flutter/src/rendering/object.dart': Failed assertion: line 3374 pos 12: 'attached': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack: 
#2      RenderObject.getTransformTo (package:flutter/src/rendering/object.dart:3374:12)
#3      RenderBox.localToGlobal (package:flutter/src/rendering/box.dart:2887:39)
#4      RenderEditable._snapToPhysicalPixel (package:flutter/src/rendering/editable.dart:2276:33)
#5      RenderEditable.getLocalRectForCaret (package:flutter/src/rendering/editable.dart:1822:28)
#6      EditableTextState._updateComposingRectIfNeeded (package:flutter/src/widgets/editable_text.dart:4498:38)
#7      EditableTextState._schedulePeriodicPostFrameCallbacks (package:flutter/src/widgets/editable_text.dart:4405:5)
#8      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#9      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1331:11)
#10     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#11     _invoke (dart:ui/hooks.dart:312:13)
#12     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#13     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)
====================================================================================================

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
'package:flutter/src/rendering/object.dart': Failed assertion: line 3374 pos 12: 'attached': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack: 
#2      RenderObject.getTransformTo (package:flutter/src/rendering/object.dart:3374:12)
#3      RenderBox.localToGlobal (package:flutter/src/rendering/box.dart:2887:39)
#4      RenderEditable._snapToPhysicalPixel (package:flutter/src/rendering/editable.dart:2276:33)
#5      RenderEditable.getLocalRectForCaret (package:flutter/src/rendering/editable.dart:1822:28)
#6      EditableTextState._scheduleShowCaretOnScreen.<anonymous closure> (package:flutter/src/widgets/editable_text.dart:4051:45)
#7      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#8      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1331:11)
#9      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#10     _invoke (dart:ui/hooks.dart:312:13)
#11     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#12     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)
====================================================================================================

@maheshj01 maheshj01 removed the waiting for author waiting for author to respond back with more info label Dec 2, 2024
@maheshj01
Copy link
Owner

Thanks for the update, I will investigate this issue over the weekend.

@maheshj01
Copy link
Owner

Complete reproducible code

code sample
// import 'package:example/pagination.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.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.light,
      ),
      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;

  String keyboardInputStr = '';
  bool isKeyboardEnter = false;
  bool isSendMsg = false;
  final TextEditingController sendMsgControl = TextEditingController();
  final FocusNode sendFocusNode = FocusNode();
  List<String> noneCmdSet = [];
  List<String> cmdSetList = [
    "Log Level 설정(양산레벨)> ABC",
    "Log Level 설정(Info레벨)> AAA",
    "Log Level 설정(디버깅레벨)> BBB",
    "모듈 설정값 확인> CCCC",
    "ALFI 항목 확인> KKK",
    "모듈 리부팅> 0000",
    "페어링 정보 확인> 11111",
    "인증 정보 확인> 2222",
    "FOTA 정보 확인> 3333",
    "FOTA 정보 초기화> 4444",
    "현재 시간 정보 확인> 555",
    "WLAN 연결 정보 확인> 6666",
    "PING 테스트> ping=192.168.0.1",
    "다운로드 모드 진입> 7777",
    "WiFi Scan List 출력> 888",
    "공장 초기화> 9999"
  ];
  @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(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SizedBox(
                child: KeyboardListener(
                  focusNode: sendFocusNode,
                  onKeyEvent: (event) {
                    if (event.logicalKey == LogicalKeyboardKey.enter) {
                      if (event is KeyDownEvent) {
                        isKeyboardEnter = true;
                      }
                    } else {
                      if (isSendMsg) {
                        setState(() {
                          isSendMsg = false;
                        });
                      }
                    }
                  },
                  child: SearchField<String>(
                    textInputAction: TextInputAction.send,
                    suggestionDirection: SuggestionDirection.up,
                    suggestionAction: SuggestionAction.next,
                    searchInputDecoration: SearchInputDecoration(
                      labelText: 'Input Msg',
                      cursorColor: Colors.blue,
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10),
                      ),
                    ),
                    selectedValue: selectedValue,
                    onSuggestionTap: (SearchFieldListItem<String> item) {
                      setState(() {
                        selectedValue = item;
                      });
                    },
                    suggestions: !isSendMsg
                        ? cmdSetList
                            .map(
                              (e) => SearchFieldListItem<String>(e,
                                  item: e,
                                  child: searchChild(e,
                                      isSelected: e == sendMsgControl.text)),
                            )
                            .toList()
                        : noneCmdSet
                            .map(
                              (e) => SearchFieldListItem<String>(e,
                                  item: e,
                                  child: searchChild(e,
                                      isSelected: e == sendMsgControl.text)),
                            )
                            .toList(),
                    controller: sendMsgControl,
                    onSubmit: (sendStr) {
                      //debugPrint('onSubmit $sendStr');
                      FocusManager.instance.primaryFocus?.requestFocus();
                      isKeyboardEnter = false;
                      setState(() {
                        isSendMsg = true;
                      });
                    },
                    onTap: () {
                      setState(() {
                        isSendMsg = false;
                      });
                    },
                    onSearchTextChanged: (sendStr) {
                      //debugPrint('onSearchTextChanged $sendStr');
                      keyboardInputStr = sendStr;
                      final filter = cmdSetList
                          .where((element) => element.contains(sendStr))
                          .toList();
                      return filter
                          .map((e) => SearchFieldListItem<String>(e,
                              child: searchChild(e)))
                          .toList();
                    },
                  ),
                ),
              ),
            ],
          ),
        ));
  }
}

@maheshj01 maheshj01 added bug Something isn't working and removed in triage Issue is currently being triaged labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants