Skip to content

Instantly share code, notes, and snippets.

@yshean
Created June 1, 2020 04:07
Show Gist options
  • Save yshean/1f1a6f751560a967d122d3e6db323418 to your computer and use it in GitHub Desktop.
Save yshean/1f1a6f751560a967d122d3e6db323418 to your computer and use it in GitHub Desktop.
Address search v1
import 'package:flutter/material.dart';
class AddressSearch extends SearchDelegate<Suggestion> {
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
tooltip: 'Clear',
icon: Icon(Icons.clear),
onPressed: () {
query = '';
},
)
];
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
tooltip: 'Back',
icon: Icon(Icons.arrow_back),
onPressed: () {
close(context, null);
},
);
}
@override
Widget buildResults(BuildContext context) {
return null;
}
@override
Widget buildSuggestions(BuildContext context) {
return FutureBuilder(
// We will put the api call here
future: null,
builder: (context, snapshot) => query == ''
? Container(
padding: EdgeInsets.all(16.0),
child: Text('Enter your address'),
)
: snapshot.hasData
? ListView.builder(
itemBuilder: (context, index) => ListTile(
// we will display the data returned from our future here
title:
Text(snapshot.data[index]),
onTap: () {
close(context, snapshot.data[index]);
},
),
itemCount: snapshot.data.length,
)
: Container(child: Text('Loading...')),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment