Skip to content

Instantly share code, notes, and snippets.

@jesusrp98
Created January 10, 2019 12:20
Show Gist options
  • Save jesusrp98/df95c6f44055583422279fe27cf419a9 to your computer and use it in GitHub Desktop.
Save jesusrp98/df95c6f44055583422279fe27cf419a9 to your computer and use it in GitHub Desktop.
Auxiliary method which helps filter launches by its name
searchLaunches(BuildContext context, List list) {
return MaterialPageRoute<Launch>(
builder: (context) => Material(
child: MaterialSearch<Launch>(
barBackgroundColor: Theme.of(context).primaryColor,
iconColor: Colors.white,
placeholder: FlutterI18n.translate(
context,
'spacex.other.tooltip.search',
),
limit: list.length,
results: list
.map((item) => MaterialSearchResult<Launch>(
icon: Icons.search,
value: item,
text: item.name,
))
.toList(),
filter: (dynamic value, String criteria) => (value as Launch)
.name
.toLowerCase()
.trim()
.contains(RegExp(r'' + criteria.toLowerCase().trim() + '')),
onSelect: (dynamic launch) => Navigator.push(
context,
MaterialPageRoute(builder: (_) => LaunchPage(launch)),
),
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment