我想知道怎样才能使搜索功能根据我的ListView
的索引工作?例如,如果我根据自己的情况输入101,我不应该在List
中显示任何内容.
我还在这里更新并发布了函数_getTicketDeatils()
.
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);
}
}