I'm using a package call alphabet_list_scroll_view 2.0.0 in my flutter project.
I'm using the example code from their documentation but I'm getting
RangeError (index): Invalid value: Valid value range is empty: 0
for some reason. I'm trying to add itemCount right above itemBuilder but I'm getting the parameter is not existed.
Any help would be really appreciated with dummy/mock list..
Here is part of the code from the example code that they provided.
class _AboutScreenState extends State<AboutScreen> {
List<User> userList = [];
List<String> strList = ['Ja', 'bo', 'Ce', 'Do', 'Ha', 'Tu', 'Zu'];
List<Widget> favouriteList = [];
List<Widget> normalList = [];
TextEditingController searchController = TextEditingController();
@override
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: AlphabetListScrollView(
strList: strList,
highlightTextStyle: TextStyle(
color: Colors.yellow,
),
showPreview: true,
itemBuilder: (context, index) {
return normalList[index];
},
indexedHeight: (i) {
return 80;
},
keyboardUsage: true,
),
));
}
}
CodePudding user response:
You are populating the normalList
but using on itemBuilder
. You can do it on initState to solve this error.
@override
void initState() {
super.initState();
for (final item in strList) {
normalList.add(Text(item));
}
}
And itemcount isnt a valid key in alphabet list scroll view