I am trying to use mapsforge plugin to use my own compiled map. I am not an experienced flutter developer and don't know so much about loading assets therefore can't figure out what the problem is.
File structure;
pubspec.yaml;
flutter:
uses-material-design: true
assets:
- assets/login/
- assets/maps/render_themes/
- assets/maps/icons
Code;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mapsforge_flutter/core.dart';
import 'package:mapsforge_flutter/maps.dart';
class MapShow extends StatefulWidget {
@override
_MapShowState createState() => _MapShowState();
}
class _MapShowState extends State<MapShow> {
late MapFile mapFile;
late SymbolCache symbolCache;
GraphicFactory graphicFactory = const FlutterGraphicFactory();
DisplayModel displayModel = DisplayModel();
late RenderThemeBuilder renderThemeBuilder;
late String content;
late RenderTheme renderTheme;
late MapDataStoreRenderer jobRenderer;
late MapModel mapModel;
late ViewModel viewModel;
void assignSymbolCache() async {}
@override
void initState() {
super.initState();
rootBundle
.loadString("assets/maps/render_themes/defaultrender.xml")
.then((String s) {
content = s;
});
MapFile.from("assets/maps/akuzem.map", null, null).then((MapFile mf) {
mapFile = mf;
});
symbolCache = FileSymbolCache(rootBundle);
renderThemeBuilder =
RenderThemeBuilder(graphicFactory, symbolCache, displayModel);
renderThemeBuilder.parseXml(content);
renderTheme = renderThemeBuilder.build();
jobRenderer =
MapDataStoreRenderer(mapFile, renderTheme, graphicFactory, true);
mapModel = MapModel(
displayModel: displayModel,
renderer: jobRenderer,
);
viewModel = ViewModel(displayModel: displayModel);
}
@override
Widget build(BuildContext context) {
setState(() {});
return FlutterMapView(
mapModel: mapModel,
viewModel: viewModel,
graphicFactory: graphicFactory);
}
}
Also i saw WidgetsFlutterBinding.ensureInitialized(); in an answer and added my void main() but didnt solved.
Error Showing;
Error in debug console;
Restarted application in 161ms.
Error: Unsupported operation: _Namespace
at Object.throw_ [as throw] (http://localhost:60585/dart_sdk.js:5067:11)
at Function.get _namespacePointer [as _namespacePointer] (http://localhost:60585/dart_sdk.js:56707:17)
at Function._namespacePointer (http://localhost:60585/dart_sdk.js:54523:28)
at Function._dispatchWithNamespace (http://localhost:60585/dart_sdk.js:54526:31)
at io._File.new.exists (http://localhost:60585/dart_sdk.js:54530:23)
at readbufferfile.ReadbufferFile.new._openRaf (http://localhost:60585/packages/mapsforge_flutter/src/mapfile/readbufferfile.dart.lib.js:82:30)
at _openRaf.next (<anonymous>)
at runBody (http://localhost:60585/dart_sdk.js:40590:34)
at Object._async [as async] (http://localhost:60585/dart_sdk.js:40621:7)
at readbufferfile.ReadbufferFile.new.[_openRaf] (http://localhost:60585/packages/mapsforge_flutter/src/mapfile/readbufferfile.dart.lib.js:77:20)
at readbufferfile.ReadbufferFile.new.length (http://localhost:60585/packages/mapsforge_flutter/src/mapfile/readbufferfile.dart.lib.js:93:29)
at length.next (<anonymous>)
at runBody (http://localhost:60585/dart_sdk.js:40590:34)
at Object._async [as async] (http://localhost:60585/dart_sdk.js:40621:7)
at readbufferfile.ReadbufferFile.new.length (http://localhost:60585/packages/mapsforge_flutter/src/mapfile/readbufferfile.dart.lib.js:91:20)
at mapfile.MapFile.__._init (http://localhost:60585/packages/mapsforge_flutter/src/cache/memorytilebitmapcache.dart.lib.js:15605:75)
at _init.next (<anonymous>)
at runBody (http://localhost:60585/dart_sdk.js:40590:34)
at Object._async [as async] (http://localhost:60585/dart_sdk.js:40621:7)
at mapfile.MapFile.__.[_init] (http://localhost:60585/packages/mapsforge_flutter/src/cache/memorytilebitmapcache.dart.lib.js:15602:20)
at from (http://localhost:60585/packages/mapsforge_flutter/src/cache/memorytilebitmapcache.dart.lib.js:15586:34)
at from.next (<anonymous>)
at runBody (http://localhost:60585/dart_sdk.js:40590:34)
at Object._async [as async] (http://localhost:60585/dart_sdk.js:40621:7)
at Function.from (http://localhost:60585/packages/mapsforge_flutter/src/cache/memorytilebitmapcache.dart.lib.js:15584:20)
at map_show._MapShowState.new.initState (http://localhost:60585/packages/mapping_tool/pages/map/map_show.dart.lib.js:166:23)


in your
initStatemethod, you used then, It breaks your order of code.Try this code :