50

I was using the google maps api and location pub,dev package in my android flutter app, and tried to bring up an image using the url from the api. This was the url with some code:

class LocationHelper{
  static String mapviewpointer({double latitude, double longitude}){
    return "https://maps.googleapis.com/maps/api/staticmap?center=$latitude,$longitude&zoom=13&size=600x300&maptype=roadmap&markers=color:pink%7Clabel:C%7C$latitude,$longitude&key=$GOOGLE_API_KEY";
  }
}

it threw the following error message:

Plugin project :location_web not found. Please update settings.gradle;

I'm not sure how to fix this error.

This was the other error I received in my terminal:

I/flutter (21880): Invalid argument(s): No host specified in URI file:///Instance%20of%20'Future%3CString%3E'

The Area in which I get the error message above is here in my code:

Future <String> _getUserLocation() async{
  final locData = await Location().getLocation();
  final staticMapUrl = LocationHelper.mapviewpointer(
    latitude: locData.latitude, 
    longitude: locData.longitude,
    );
    return staticMapUrl;
}

final mapview = _getUserLocation();


class NearbyScreen extends StatelessWidget {
  @override
  //LocationHelper.mapviewpointer(latitude: )
  
  Widget build(BuildContext context) {
    return  Column(
            children: <Widget>[
              Container(height:170, width: double.infinity,
              child:Image.network(mapview.toString())
              ),
              Text("hello"),
            ],
          );
  }
}

Does it have something to do with the fact that I am returning a Future<String> instead of just a string in my _getUserlocation function? How could I fix this?

Tugay
  • 2,057
  • 5
  • 17
  • 32
casualcoder
  • 541
  • 1
  • 4
  • 13

5 Answers5

91

Use the following settings.gradle:

include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory
}

This will create a .flutter-plugin file which will have the plugin and its path.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • 1
    Thank you very much! I still however get this error message when trying to display the map image: "I/flutter (10600): The following ArgumentError was thrown resolving an image codec: I/flutter (10600): Invalid argument(s): No host specified in URI file:///Instance%20of%20'Future%3CString%3E'" What would the issue be here? – casualcoder Jun 13 '20 at 14:05
  • 2
    Where do you get this error on which line in your code? Or after doing what? – Peter Haddad Jun 13 '20 at 14:06
  • I have updated the question with more info, I hope this helps! Thank you again – casualcoder Jun 13 '20 at 14:15
  • 2
    `getUserLocation()` returns a `Future` while `Image.network` needs a url.. Therefore the best thing is to use `FutureBuilder` and inside it call `Image.network` image – Peter Haddad Jun 13 '20 at 14:16
  • 2
    Why does this error happen ? What does this script does ? – Ced Oct 29 '20 at 19:03
  • I havent tried this plugin in a while, try and use the latest version it shouldnt happen anymore, as to why it happens check this one here https://stackoverflow.com/questions/61732409/plugin-project-firebase-core-web-not-found/61732682#61732682 @Ced – Peter Haddad Oct 29 '20 at 19:04
  • This was the old settings.gradle when you create a flutter application, then flutter changed the settings.gradle and some plugins needed the old script to function correctly its why you get this error.. – Peter Haddad Oct 29 '20 at 19:08
  • 2
    Btw I checked my `.flutter-plugins` file, which is created by a recent flutter version, and it includes the location_web path. Probably as @PeterHaddad said some plugins are not supporting the new settings definitions – funder7 Dec 22 '20 at 21:38
5

I had the same issue and following @Peter Haddad answer, I copy and replaced the code in settings.gradle (all of it) and I had errors resolving symbol for properties and file.

TO FIX IT: go to Tools -> Flutter -> Open for editing in Android Studio

In the Android Studio window go to File -> Invalidate Cache and Restart

This seemed to fix it for me.

2

add in your flutter app -> android -> settings.gradle

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    include ":$name"
    project(":$name").projectDir = pluginDirectory
}

as seen here

more info about the issue here

Paulo Belo
  • 3,759
  • 1
  • 22
  • 20
0

Delete ProjectName/Build folder it has resolved issue for me.

Muhammad Adil
  • 4,358
  • 3
  • 32
  • 36
0

Fix for users having facebook flipper installed

I would have added this as a comment, but let me post it as an answer to have proper code formatting.

If you have facebook's flipper installed, with the relative flutter_flipperkit plugin, then your settings.gradle should be already modified.

To use the fix suggested by @Peter Haddad & @Paulo Belo, you will need to keep flipper's plugin loading and add the other condition:

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    if (name == 'flutter_flipperkit') {
        // flipper loading
        include ':flipper-no-op'
        project(':flipper-no-op').projectDir = new File(pluginDirectory, 'flipper-no-op')
    }
    else {
        // location_web not found fix
        include ":$name"
        project(":$name").projectDir = pluginDirectory
    }
}

Hope this helps somebody.

funder7
  • 1,622
  • 17
  • 30