Search code examples
flutterdartlocation

W/GooglePlayServicesUtil(16928): Google Play Store is missing. flutter


i am trying to get user location but get the google play store service is missing while i dont use any google apps or service in my app. help i get this error everytime, i try to get my current location i marked it by -----> it should give me the latitude and longitude

W/GooglePlayServicesUtil(16928): Google Play Store is missing. flutter

here is my main code i am trying to click on prefixicon to get my location

import 'package:flutter/material.dart';
import 'package:project/screens/sign_page.dart';
import 'package:project/screens/home_screen.dart';
import 'package:geolocator/geolocator.dart';

//textediting controller needed to be added
// Define a custom Form widget.
class MyCustomForm extends StatefulWidget {
  const MyCustomForm({Key? key}) : super(key: key);

  @override
  MyCustomFormState createState() {
    return MyCustomFormState();
  }
}

// Define a corresponding State class.
// This class holds data related to the form.
class MyCustomFormState extends State<MyCustomForm> {
  final _formKey = new GlobalKey<FormState>();
  getcurrentlocation() async {
    Position position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.high);
    var latitude = position.latitude;
    var longitude = position.longitude;

    print(latitude);
    print(longitude);
  }

  TextEditingController name = TextEditingController();
  TextEditingController phone = TextEditingController();
  TextEditingController address = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Material(
        child: Form(
            key: _formKey,
            child: SafeArea(
              child: Column(
                children: [
                  Container(
                    height: MediaQuery.of(context).size.height * 0.15,
                    width: double.infinity,
                    decoration: BoxDecoration(
                        image: DecorationImage(
                            image: AssetImage("assets/images/background.png"),
                            fit: BoxFit.cover)),
                    padding: EdgeInsets.only(top: 47, left: 20),
                    child: Text(
                      "Personal info",
                      style: TextStyle(
                          fontSize: 45,
                          fontWeight: FontWeight.bold,
                          color: Colors.white),
                    ),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    padding: EdgeInsets.only(left: 29),
                    child: Text(
                      "Name",
                      style: TextStyle(fontSize: 18, color: Colors.black),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: 25, vertical: 20),
                    child: TextFormField(
                      keyboardType: TextInputType.name,
                      controller: name,
                      onFieldSubmitted: (value) {},
                      validator: (value) {
                        if (value!.isEmpty) {
                          return 'Enter a valid Name!';
                        }
                        return null;
                      },
                      decoration: InputDecoration(
                        filled: true,
                        isDense: true, // Added this
                        contentPadding: EdgeInsets.symmetric(vertical: 22),
                        fillColor: Color.fromRGBO(238, 247, 246, 1),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(12.0)),
                          borderSide: BorderSide(color: Colors.white, width: 2),
                        ),

                        hintText: '',
                      ),
                    ),
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    padding: EdgeInsets.only(left: 29),
                    child: Text(
                      "Address",
                      style: TextStyle(fontSize: 18, color: Colors.black),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: 25, vertical: 20),
                    child: TextFormField(
                      keyboardType: TextInputType.text,
                      controller: address,
                      onFieldSubmitted: (value) {},
                      validator: (value) {
                        if (value!.isEmpty) {
                          return 'Enter a valid address!';
                        }
                        return null;
                      },
                      decoration: InputDecoration(
                        prefixIcon: IconButton(
                          onPressed: () async {
                            getcurrentlocation();     **----->here!**
                          },
                          icon: Icon(Icons.location_on),
                        ),
                        isDense: true, // Added this
                        contentPadding: EdgeInsets.symmetric(vertical: 22),
                        filled: true,

                        fillColor: Color.fromRGBO(238, 247, 246, 1),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(12.0)),
                          borderSide: BorderSide(color: Colors.white, width: 2),
                        ),

                        hintText: '',
                      ),
                    ),
                  ),
                  Container(
                    alignment: Alignment.topLeft,
                    padding: EdgeInsets.only(left: 29),
                    child: Text(
                      "Phone Number",
                      style: TextStyle(fontSize: 18, color: Colors.black),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: 25, vertical: 15),
                    child: TextFormField(
                      keyboardType: TextInputType.number,
                      controller: phone,
                      onFieldSubmitted: (value) {},
                      validator: (value) {
                        if (value!.isEmpty) {
                          return 'Enter a valid phone number!';
                        }
                        return null;
                      },
                      decoration: InputDecoration(
                        isDense: true, // Added this
                        contentPadding: EdgeInsets.symmetric(vertical: 22),
                        filled: true,

                        fillColor: Color.fromRGBO(238, 247, 246, 1),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(12.0)),
                          borderSide: BorderSide(color: Colors.white, width: 2),
                        ),
                        hintText: '',
                      ),
                    ),
                  ),
                  Expanded(child: Text("")),
                  FlatButton(
                    height: 50,
                    minWidth: 300,
                    onPressed: () {
                      if (_formKey.currentState!.validate()) {
                        Navigator.push(context,
                            MaterialPageRoute(builder: (_) => homeScreen()));
                        // If the form is valid, display a snackbar. In the real world,
                        // you'd often call a server or save the information in a database.
                        ScaffoldMessenger.of(context).showSnackBar(
                          SnackBar(content: Text("")),
                        );
                      }
                    },
                    color: const Color.fromRGBO(0, 168, 165, 1),
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10)),
                    child: const Text(
                      "Continue",
                      style: TextStyle(color: Colors.white, fontSize: 19),
                    ),
                  ),
                  SizedBox(
                    height: 20,
                  )
                ],
              ),

              // Add TextFormFields and ElevatedButton here.
            )));
  }
}


Solution

  • I think you run application with emulator without Playstore. Google core needs google play installed on your virtual device to get ads maps and core functionality that include google play SDK.

    you just need to create an emulator with google play as shown in the image below one with the google play icon. I hope this answer will help you.enter image description here.