Last active
March 20, 2023 15:17
-
-
Save kirshiyin89/2944e1aa5211df6dd97823ff547abf9f to your computer and use it in GitHub Desktop.
MaterialApp class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_typeahead/flutter_typeahead.dart'; | |
import 'data.dart'; | |
class MyMaterialApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Datamuse Autocomplete Demo', | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Autocomplete'), | |
), | |
body: NavigationExample()); | |
} | |
} | |
class NavigationExample extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Padding( | |
padding: EdgeInsets.all(32.0), | |
child: Column( | |
children: <Widget>[ | |
SizedBox( | |
height: 10.0, | |
), | |
TypeAheadField( | |
textFieldConfiguration: TextFieldConfiguration( | |
autofocus: true, | |
style: DefaultTextStyle.of(context) | |
.style | |
.copyWith(fontStyle: FontStyle.italic), | |
decoration: InputDecoration( | |
border: OutlineInputBorder(), | |
hintText: 'What is on your mind?'), | |
), | |
suggestionsCallback: (pattern) async { | |
return await BackendService.getSuggestions(pattern); | |
}, | |
itemBuilder: (context, Map<String, String> suggestion) { | |
return ListTile( | |
title: Text(suggestion['name']!), | |
subtitle: Text('${suggestion['score']}'), | |
); | |
}, | |
onSuggestionSelected: (Map<String, String> suggestion) { | |
// your implementation here | |
}, | |
), | |
], | |
), | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment