-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Comments
Hi @cw-20021366 I made a PR #191 Which I believe will fix this issue. searchfield:
git:
url: https://github.com/maheshmnj/searchfield.git
ref: master and then Deleting 'pubspec.lock' run Code sampleimport '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;
});
},
),
],
),
));
}
} |
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. |
Hi. @maheshj01
|
Thanks for the update, I will investigate this issue over the weekend. |
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();
},
),
),
),
],
),
));
}
}
|
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
Exception Exception Log
Show log
Temporarily handle exceptions in your 'searchfield.dart' code
Show code
Success Screenshots
2024-11-27.9.17.11.mov
The text was updated successfully, but these errors were encountered: