fysoul17 / google_maps_place_picker

Place picker on Google Maps for Flutter
MIT License
224 stars 367 forks source link

How to control or customise the back arrow operation? #25

Closed newbieflutter closed 4 years ago

newbieflutter commented 4 years ago

I am now calling this google map picker from another page. From that page say I call it like this.

Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) => AddressChangePage()),
                  );

So now here is the codes for my picker page. It call the page all works well. The problem first was on function onPlacePicked I put this function Navigator.of(context).pop(); it didnt as it takes to am empty black page then this work so I put this function ``` Navigator.push( context, MaterialPageRoute(builder: (context) => MainSearchPage()), );


this work but the problem I dont know how to code the back arrow with this same function too?

class AddressChangePage extends StatelessWidget { // Light Theme final ThemeData lightTheme = ThemeData.light().copyWith( // Background color of the FloatingCard cardColor: Colors.white, buttonTheme: ButtonThemeData( // Select here's button color buttonColor: Color.fromRGBO(0, 116, 226, 1), textTheme: ButtonTextTheme.primary, ), );

// Dark Theme final ThemeData darkTheme = ThemeData.dark().copyWith( // Background color of the FloatingCard cardColor: Colors.white, buttonTheme: ButtonThemeData( // Select here's button color buttonColor: Colors.blue, textTheme: ButtonTextTheme.primary, ), );

// This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Google Map Place Picker Demo', theme: lightTheme, darkTheme: lightTheme, themeMode: ThemeMode.light, home: AddressChangeDetails(), debugShowCheckedModeBanner: false, ); } }

class AddressChangeDetails extends StatefulWidget {

final Color cardBackgroundColor = Color(0xFFFFFFFF); final String logo = Assets.setLocation;

AddressChangeDetails({Key key}) : super(key: key);

static final kInitialPosition = LatLng(5.285153, 100.456238);

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

class _AddressChangeDetailsState extends State { PickResult selectedPlace; double _height, _width, _fixedPadding; String code = "";

@override Widget build(BuildContext context) {

    return Scaffold(

        body: Center(
          child: 
              PlacePicker(
                          apiKey: "**************",
                          initialPosition: kInitialPosition,
                      useCurrentLocation: false,
                      //desiredLocationAccuracy: best,
                      usePlaceDetailSearch: false,
                      cameraMoveDebounceInMilliseconds:100,
                      autoCompleteDebounceInMilliseconds:100,
                      forceAndroidLocationManager: true,
                      forceSearchOnZoomChanged : true,
                      onPlacePicked: (result) {
                        selectedPlace = result;

                        Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => MainSearchPage()),
                        );
                        setState(() {});
                      },
                      myLocationButtonCooldown : 5,

                      //autocompleteLanguage: "eng",
                      region: 'my',

                      selectInitialPosition: true,

                    )

    )
);

} }

fysoul17 commented 4 years ago

This is not the question related to the package. StackOverFlow will be the place you can ask this sort of question I think.

But, FYI, Putting Scaffold in MainSearchPage's build method may solve your issue.

newbieflutter commented 4 years ago

Hi Fysoul, I dont quite get you when you said putting scallfold in the MainSearchPage ? Which mainsearch page are you referring too ?

fysoul17 commented 4 years ago
Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => MainSearchPage()),
                        );

It is in your code.

If you use PlacePicker within another widget such as MainSearchPage as you said, app bar or other outer screen UI is depending on MainSearchPage not PlacePicker.

So I think you need more understanding of how flutter works rather than how this package can do to achieve your goal.

newbieflutter commented 4 years ago

Hi, Ok thank you.