google_places_search_field 1.0.2 copy "google_places_search_field: ^1.0.2" to clipboard
google_places_search_field: ^1.0.2 copied to clipboard

A customizable Flutter widget for searching locations using Google Places Autocomplete with LatLng callback support

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart' as maps;
import 'package:google_places_search_field/google_places_search_field.dart';

void main() {
  runApp(const GooglePlacesExampleApp());
}

class GooglePlacesExampleApp extends StatelessWidget {
  const GooglePlacesExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Google Places Search Field Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  maps.LatLng? _selectedLatLng;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Places Search Field')),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            GooglePlacesSearchField(
              apiKey: 'YOUR_GOOGLE_API_KEY', // Replace with your actual API key
              onLatLngSelected: (maps.LatLng latLng) {
                setState(() {
                  _selectedLatLng = latLng;
                });
              },
            ),
            const SizedBox(height: 20),
            if (_selectedLatLng != null)
              Text(
                'Selected Location: ${_selectedLatLng!.latitude}, ${_selectedLatLng!.longitude}',
                style: const TextStyle(fontSize: 16),
              ),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
32
downloads

Publisher

verified publisherpranavk.com

Weekly Downloads

A customizable Flutter widget for searching locations using Google Places Autocomplete with LatLng callback support

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_google_places_sdk, google_maps_flutter

More

Packages that depend on google_places_search_field