var userDetails = {};
var i;
List returnTicketDetails = [] ;
body: new Column(
children: <Widget>[
new Container(
color: Theme.of(context).primaryColor,
child: new Padding(
padding: const EdgeInsets.all(8.0),
child: new Card(
child: new ListTile(
leading: new Icon(Icons.search),
title: new TextField(
controller: controller,
decoration: new InputDecoration(
hintText: 'Search', border: InputBorder.none),
// onChanged: onSearchTextChanged,
),
trailing: new IconButton(icon: new Icon(Icons.cancel), onPressed: () {
controller.clear();
// onSearchTextChanged('');
},),
),
new Expanded(
child: userDetails.length != 0 || controller.text.isNotEmpty
? new ListView.builder(
itemCount: userDetails.length,
itemBuilder: (context, i) {
return new Card(
child: new Column
(mainAxisSize: MainAxisSize.min, children:
<Widget>[
new Row(children: <Widget>[
new Container(
width: 80.0,
height: 80.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new NetworkImage(
"https:..")
)
)),
new Text(userDetails[returnTicketDetails[i]["user_id"]]["first_name"]
),),
,),
new Text(userDetails[returnTicketDetails[i]["user_id"]]["last_name"]),
);
},
)
: new ListView.builder(
itemCount: userDetails.length,
itemBuilder: (context, i) {
return new Card(
child: new ListTile(
//title: new Text(userDetails[returnTicketDetails[i]["user_id"]]["first_name"]),
),
margin: const EdgeInsets.all(0.0),
);
);
}
_getTicketDetails() async {
final response = await http.get(
"https..", headers: {
HttpHeaders.AUTHORIZATION: access_token
});
returnTicketDetails = json.decode(response.body);
for ( i = 0; i < (returnTicketDetails?.length ?? 0); i++) {
final ticketresponse = await http.get(
"https...", headers: {
HttpHeaders.AUTHORIZATION:
access_token
});
userDetails[returnTicketDetails[i]["user_id"]] =
json.decode(ticketresponse.body);
}
}
I was wondering how to make the search function works according to the index of my ListView
? So for instance if I input a z
according to my case, I should not display anything in the List
.
I have also updated and posted the function _getTicketDeatils()
here.
With reference to Vinoth Kumar's answer, it's good to note that
.contains()
is case-sensitive. So, to exhaust all matches, you could transform the strings to lowercase:Works perfectly for me.
I'm learning Flutter and was looking for a searchable list which @Vinoth Kumar example does perfectly.
I've split the code into different files and reduced the HomePage body into several methods to make it more maintainable/readable for myself and I figured it would be worth sharing.
main.dart
homepage.dart
userDetails.dart
In Flutter, we have to manage with a custom filter widget and we have to compare tow different objects lists. Such as
I found example here
Here is another method to filter the list
add this in your pub.yaml file: flutter_slidable:^0.5.4
I've replaced hardcoded model input with getting data from url as you needed.