Last active
June 1, 2020 03:54
-
-
Save yshean/2e7b063c8243434a3628fd743ae02dfa to your computer and use it in GitHub Desktop.
TextField setup for address input v2
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:google_places_flutter/address_search.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Google Places Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.amber, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: MyHomePage(title: 'Places Autocomplete Demo'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
final _controller = TextEditingController(); | |
@override | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Column( | |
children: <Widget>[ | |
TextField( | |
controller: _controller, | |
onTap: () async { | |
// should show search screen here | |
showSearch( | |
context: context, | |
// we haven't created AddressSearch class | |
// this should be extending SearchDelegate | |
delegate: AddressSearch(), | |
); | |
}, | |
decoration: InputDecoration( | |
icon: Container( | |
margin: EdgeInsets.only(left: 20), | |
width: 10, | |
height: 10, | |
child: Icon( | |
Icons.home, | |
color: Colors.black, | |
), | |
), | |
hintText: "Enter your shipping address", | |
border: InputBorder.none, | |
contentPadding: EdgeInsets.only(left: 8.0, top: 16.0), | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment