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

Search feature #8

Closed
raffaelecolleo opened this issue Nov 7, 2018 · 1 comment
Closed

Search feature #8

raffaelecolleo opened this issue Nov 7, 2018 · 1 comment

Comments

@raffaelecolleo
Copy link

raffaelecolleo commented Nov 7, 2018

Hi guys,
I am developing an app and I would like to integrate it with a search function.
Basically I am going to add to my appbar a new class that will extend searchDelegate and build all the necessary things for a "modal" search.

`
class ShowSearch extends SearchDelegate {

@OverRide
List buildActions(BuildContext context) {
// TODO: implement buildActions
return [IconButton(
icon: Icon(Icons.clear),
onPressed: (){
query = "";
}
)];
}

@OverRide
Widget buildLeading(BuildContext context) {
// TODO: implement buildLeading
return IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
close(context, null);
});
}

@OverRide
Widget buildSuggestions(BuildContext context) {
// TODO: implement buildSuggestions
}

@OverRide
Widget buildResults(BuildContext context) {
// TODO: implement buildResults
int _totalCounter = 100;

return PagewiseGridView(
    pageSize: 10,
    totalCount: _totalCounter,
    crossAxisCount: 2,
    mainAxisSpacing: 10.0,
    crossAxisSpacing: 5.0,
    padding: EdgeInsets.all(5.0),
    itemBuilder: _itemBuilder,
    pageFuture: BackendService().getSearchItems,
);

}
`

and this is getSearchItems

`
static Future getSearchModels(query, searchIndex) async {
searchIndex = await searchIndex+1;
var query = "flutter";

var mySearchRes = await http.get(Uri.encodeFull("https://www.mydomain.com/wp-json/myapp/v1/search/$query/$searchIndex"), headers: {"Accept": "application/json"});
var mySearchResBody = json.decode(mySearchRes.body);

List searchList = [];

for (var modelSearches in mySearchResBody["posts"]){
  searchList.add(modelSearches);
}
return searchList;

}
`

My problem is that it shows a red screen saying
type 'Future<List<dynamic>>' is not a subtype of type '(int) => Future<List<dynamic>>'
when I change the pageFuture to
pageFuture: BackendService().getSearchItems("flutter", 1),
where flutter is what I am searching and 1 is the page number that is retrieving 10 results at the time.

How can I fix this...

@raffaelecolleo
Copy link
Author

Solved.
Just Changed
pageFuture: BackendService().getSearchItems
to
pageFuture: (pageIndex){ return myFuncion(); }

Thanks anyway guys!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant