Code Monkey home page Code Monkey logo

Comments (1)

rajeshzmoke avatar rajeshzmoke commented on July 20, 2024

This is my navigation code

 String birthPlace = await Navigator.of(context).push(
          MaterialPageRoute(
            builder: (BuildContext context) => WillPopScope(
                  onWillPop: requestPop,
                  child: CustomSearchScaffold(),
                ),
          ),
        );

The places screen

import 'dart:async';

import 'package:flutter_google_places_autocomplete/flutter_google_places_autocomplete.dart';
import 'package:flutter/material.dart';

const kGoogleApiKey = "myrealapikey";

GoogleMapsPlaces _places = GoogleMapsPlaces(kGoogleApiKey);

final searchScaffoldKey = GlobalKey<ScaffoldState>();

Future<Null> displayPrediction(Prediction p, ScaffoldState scaffold) async {
  if (p != null) {
    PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);
    print('detail $detail');
    var lat = detail.result.geometry.location.lat;
    var lng = detail.result.geometry.location.lng;
    print("${p.description} $lat/$lng ");
    Navigator.of(scaffold.context).pop("${p.description}");

    scaffold
        .showSnackBar(SnackBar(content: Text("${p.description} $lat/$lng ")));
  }
}

class CustomSearchScaffold extends GooglePlacesAutocompleteWidget {
  static const String routeName = 'places';
  CustomSearchScaffold()
      : super(apiKey: kGoogleApiKey, language: "en", components: [
          Component(Component.country, "in"),
          Component(Component.country, "us"),
        ]);

  @override
  _CustomSearchScaffoldState createState() => _CustomSearchScaffoldState();
}

class _CustomSearchScaffoldState extends GooglePlacesAutocompleteState {
  @override
  Widget build(BuildContext context) {
    final appBar = AppBar(
      titleSpacing: 20.0,
      automaticallyImplyLeading: false,
      title: AppBarPlacesAutoCompleteTextField(),
      backgroundColor: Color.fromRGBO(57, 73, 171, 1.0),
    );
    final body = GooglePlacesAutocompleteResult(onTap: (p) {
      // displayPrediction(p, searchScaffoldKey.currentState);
    });
    return Scaffold(key: searchScaffoldKey, appBar: appBar, body: body);
  }

  @override
  void onResponseError(PlacesAutocompleteResponse response) {
    super.onResponseError(response);
    searchScaffoldKey.currentState
        .showSnackBar(SnackBar(content: Text(response.errorMessage)));
  }

  @override
  void onResponse(PlacesAutocompleteResponse response) {
    super.onResponse(response);
    if (response != null && response.predictions.isNotEmpty) {
      searchScaffoldKey.currentState
          .showSnackBar(SnackBar(content: Text("Got answer")));
    }
  }
}

from flutter_google_places.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.