Doubts onPressed integration with Google Maps Flutter

Asked

Viewed 417 times

0

I set up a canvas and I’m having a hard time doing something On the buttons I wanted to put to work onPressed linked to the google maps API. Like, when I click on one of the buttons, it will tell me which are the nearest stores, however, since I’m a beginner, I’m having trouble doing this.

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

void main() => runApp(Materialapp(debugging()));

class Gridlayout extends Statelesswidget { List Events = [ "Clinic", "Petshop," "Pharmacy", "Indefinite." "Hospital SOS", "?" ];

@override Widget build(Buildcontext context) { Return Scaffold( body: Container( Décoration: Boxdecoration( image: Decorationimage ( image: Assetimage("Assets/bg.png"), fit: Boxfit.cover), Child: Container( margin: const Edgeinsets.only(top: 10), Child: Gridview( Physics: Bouncingscrollphysics(), gridDelegate: Slivergriddelegatewithfixedcrossaxiscount(crossAxisCount: 2), Children: Events.map((title) { Return Gesturedetector( Child: Card( Shape: Roundedrectangleborder(borderRadius: Borderradius.circular(100.0),), color: Colors.white60, margin: const Edgeinsets.all(20.0), Child: Flatbutton( onPressed: (){

                    } ,
                    child: getCardByTitle(title)),
              ),
              onTap: () {
                Fluttertoast.showToast(
                    msg: title,
                    toastLength: Toast.LENGTH_SHORT,
                    gravity: ToastGravity.CENTER,
                    backgroundColor: Colors.blueAccent,
                    textColor: Colors.white,
                    fontSize: 16.0);
              },
            );
          }).toList(),
        )),
  ),
);

}

Column getCardByTitle(String title) { String img = ""; if (title == "Clinic") img = "Assets/Clinic.png"; Else if (title == "Petshop") img = "Assets/petshop.png"; Else if (title == "Pharmacy") img = "Assets/farm.png"; Else if (title == "Undefined") img = "Assets/img3.png"; Else if (title == "SOS hospital") img = "Assets/Hosp.png"; Else img = "Assets/expert.png";

return Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Center( child: Container( child: Stack( children: <Widget>[ Image.asset( img, width: 50.0, height: 50.0, ) ], ), ), ), Text( title, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold), textAlign: TextAlign.center , ) ], );

} }

tter

  • I could not understand your problem, but looking through the cell phone print I would have a solution... you already tried using the Widget Inkwell? you put your Container inside it and it is clickable.

  • I don’t know if I set up the right code, but visually that’s the way I want it. The app is to find nearby stores. When I click for example on "clinic", the app will show me which clinics are closest to my location, after selecting one, the app redirects to google maps. I think it’s clearer now

  • From what I understand, your doubt is not about function onPressed in itself and its functioning, but how in this function integrate with Google Maps to show the establishments nearby? If this is the case, could update the title to make it clearer

  • I changed the title, and that’s exactly the question

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.