Skip to content

Instantly share code, notes, and snippets.

@riccardopirani
Created June 8, 2020 09:43
Show Gist options
  • Save riccardopirani/0e451450996b16ee7cf4320a75bb9e6b to your computer and use it in GitHub Desktop.
Save riccardopirani/0e451450996b16ee7cf4320a75bb9e6b to your computer and use it in GitHub Desktop.
SearchDelegate
class DataSouceSelezionaArticolo extends SearchDelegate<String>{
Rapporto rp;
DataSouceSelezionaArticolo(this.rp);
@override
List<Widget> buildActions(BuildContext context) {
return [IconButton(icon: Icon(Icons.clear), onPressed: () {
query="";
} )];
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(icon: AnimatedIcon(icon:AnimatedIcons.menu_arrow, progress: transitionAnimation,),
onPressed: (){
Navigator.pop(context);
});
}
@override
Widget buildResults(BuildContext context) {
return null;
}
@override
Widget buildSuggestions(BuildContext context) {
var suggestionList=listaGestioneArticoli;
if(query.isEmpty==false){
suggestionList=ricercaArticolo(query);
}
return ListView.builder(
itemBuilder: (context,index) => ListTile(
leading: Icon(Icons.build),
title: Text("CodArt: "+suggestionList[index].getCodArt()+"\nDescrizione: "+suggestionList[index].getDescrizione()+"\nPrezzo: "+suggestionList[index].getPrezzo().toString()),
//Funzione che esegue il tap sul ListTile
//Quando viene eseguito il tap viene visualizzata la schermata del rapportino
onTap: () {
//Salvo l'id della articolo selezionato
Storage.salva("ArticoloSelezionato", suggestionList[index].getIdArticolo().toString());
final gr=new GestioneArticoliPage(rp,false);
Navigator.push(context, MaterialPageRoute(builder: (context) => gr));
},
),
itemCount: suggestionList.length,
);
}
//Funzione che esegue la ricerca degli articoli
List ricercaArticolo(String testoricerca){
List ltemp=new List();
ltemp = listaGestioneArticoli.where((l) => l.getCodArt().toLowerCase().startsWith(testoricerca)).toList();
return ltemp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment