address_search_text_field 1.2.1 copy "address_search_text_field: ^1.2.1" to clipboard
address_search_text_field: ^1.2.1 copied to clipboard

discontinuedreplaced by: address_search_field
outdated

An address search box that gets nearby addresses by typing a reference, returns an object with place primary data. The object can also find an address using coordinates.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:address_search_text_field/address_search_text_field.dart';
import 'package:toast/toast.dart'; // External library

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: PageOne(),
    );
  }
}

class PageOne extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _PageOneState();
}

class _PageOneState extends State<PageOne> {
  String texto = "";

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Container(
          width: size.width * 0.80,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              AddressSearchTextField.widget(
                context: context,
                country: "Ecuador",
                exceptions: [
                  "Esmeraldas, Ecuador",
                  "Esmeraldas Province, Ecuador",
                  "Ecuador"
                ],
                coordForRef: true,
                onDone: (AddressPoint point) async {
                  AddressPoint point2;
                  if (point.latitude != null)
                    point2 = await AddressPoint.fromPoint(
                      latitude: point.latitude,
                      longitude: point.longitude,
                    );
                  setState(() {
                    texto = "${point.toString()}\n\n${point2.toString()}";
                  });
                  Navigator.of(context).pop();
                },
              ),
              Container(
                margin: EdgeInsets.symmetric(vertical: 30.0),
                child: Text(texto),
              ),
              FlatButton(
                onPressed: () => Navigator.push(context,
                    MaterialPageRoute(builder: (context) => PageTwo())),
                child: Text("Page Two"),
                color: Colors.blue,
              )
            ],
          ),
        ),
      ),
    );
  }
}

class PageTwo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: AddressSearchBox(
        country: "Ecuador",
        exceptions: [
          "Esmeraldas, Ecuador",
          "Esmeraldas Province, Ecuador",
          "Ecuador"
        ],
        onDone: (AddressPoint point) async {
          // I use toast dependency to prettier show the result
          Toast.show(
            point.toString(),
            context,
            duration: Toast.LENGTH_LONG,
            gravity: Toast.BOTTOM,
          );
        },
      ),
    );
  }
}
4
likes
0
pub points
17%
popularity

Publisher

unverified uploader

An address search box that gets nearby addresses by typing a reference, returns an object with place primary data. The object can also find an address using coordinates.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, geocoder, geolocator, location

More

Packages that depend on address_search_text_field