如何使用颤振谷歌地方包以及如何仅在屏幕上实现它,而无需在颤振中打开新屏幕。
颤动谷歌地方包 - https://pub.dev/packages/flutter_google_places#-readme-tab-
当你调用PlacesAutocomplete.show
将mode
设置为Mode.overlay
时,包支持Mode.overlay
代码片段
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildDropdownMenu(),
RaisedButton(
onPressed: _handlePressButton,
child: Text("Search places"),
),
...
Widget _buildDropdownMenu() => DropdownButton(
value: _mode,
items: <DropdownMenuItem<Mode>>[
DropdownMenuItem<Mode>(
child: Text("Overlay"),
value: Mode.overlay,
),
DropdownMenuItem<Mode>(
child: Text("Fullscreen"),
value: Mode.fullscreen,
),
],
onChanged: (m) {
setState(() {
_mode = m;
});
},
);
...
Future<void> _handlePressButton() async {
// show input autocomplete with selected mode
// then get the Prediction selected
Prediction p = await PlacesAutocomplete.show(
context: context,
apiKey: kGoogleApiKey,
onError: onError,
mode: _mode,
language: "fr",
components: [Component(Component.country, "fr")],
);
displayPrediction(p, homeScaffoldKey.currentState);
}
您可以直接复制粘贴运行示例
完整示例
https://github.com/fluttercommunity/flutter_google_places/blob/master/example/lib/main.dart