skip to Main Content

Not sure what I am doing wrong.
I specify my assets in pubspec.yml like so

assets:
  - assets/markers/station.png
  - assets/markers/other/
  - assets/markers/files/

and try loading it as a marker image with flutter map:

child: FlutterMap(
              options: MapOptions(
                center: const LatLng(32.8150, -117.2734), // Set initial map center
                zoom: 12.0, // Set initial zoom level
                maxZoom: 16
              ),
              children: [
                TileLayer(
                urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'),      
                MarkerLayer(
                  markers: [
                    Marker(
                      point: const LatLng(32.8150, -117.2734),
                      builder: (ctx) => Image.asset('assets/markers/station.png'),
                      rotate: false,
                    ),
                  ],
                  rotate: false,
                )
              ],

            ),

but on iOS all I see is a red box at the location where the marker image should be. Using this path ‘markers/station.png’ works with the Chrome debugger. So the file exists at least for the web debugging.

More, I browsed to the app bundle in the simulator and the Documents folder is empty. Per documentation I understand this is where my markers should end up

path/to/app/bundle/Documents/assets/...

but Documents is empty. I see no errors during app build regarding path conflicts.
Also, I did

$ flutter clean
$ flutter pub get

to rebuild the app bundle but still no assets copied? Can anyone please suggest what to do? Thank you!

2

Answers


  1. Chosen as BEST ANSWER

    My issue was that i had the asset directive outside of the flutter directive so assets were never copied.

    Found it in another post. Needs to be

    flutter:
      - assets:
        - assets/markers/station.png
    

  2. Here’s the code. You’ve mistakenly wrote marker instead of markers.

            Marker(
              point: const LatLng(32.8150, -117.2734),
              builder: (ctx) => Image.asset("assets/markers/station.png"),
              rotate: false,
            ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search