woosmap_flutter 0.0.3 woosmap_flutter: ^0.0.3 copied to clipboard
Get started with the Woosmap Indoor API. View simple examples, learn the concepts, and create custom indoor maps for your site.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:woosmap_flutter/woosmap_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
WoosmapIndoorController? _controller;
@override
void initState() {
super.initState();
if (_controller != null) {
print("info ===> Indoor controller not initialize");
}
}
Future<void> reloadMenu() async {
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Woosmap Indoor app'),
actions: <Widget>[
SampleMenu(webViewController: _controller),
],
),
body: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: Align(
alignment: const AlignmentDirectional(-1, -1),
child: IndoorMapViewWidget(
wooskey: "<<Woosmap key>>",
widget: true,
indoorRendererConfiguration: const {
"centerMap": true,
"defaultFloor": 3
},
indoorWidgetConfiguration: const {
"units": "metric",
"ui": {
"primaryColor": "#318276",
"secondaryColor": "#004651",
"tertiaryColor": "#E20813"
},
},
onRef: (p0) async {
_controller = p0;
await Future.delayed(
Duration(milliseconds: 1)); // use await
reloadMenu();
},
indoor_venue_loaded: (message) {
debugPrint(jsonEncode(message));
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(content: Text(jsonEncode(message))),
// );
},
indoor_feature_selected: (message) {
debugPrint(jsonEncode(message));
},
indoor_level_changed: (message) {
debugPrint("$message");
},
indoor_user_location: (message) {
debugPrint(jsonEncode(message));
},
indoor_directions: (message) {
_controller?.setDirections(message);
debugPrint(jsonEncode(message));
},
)))
],
),
),
),
);
}
}
enum MenuOptions {
showVenue,
showWorldMap,
changeFloor,
showUserPosition,
highlightFeatureByRef,
directions,
directionsMode,
clearDirections,
}
class SampleMenu extends StatelessWidget {
const SampleMenu({
super.key,
required this.webViewController,
});
final WoosmapIndoorController? webViewController;
@override
Widget build(BuildContext context) {
return PopupMenuButton<MenuOptions>(
key: const ValueKey<String>('ShowPopupMenu'),
onSelected: (MenuOptions value) {
switch (value) {
case MenuOptions.showVenue:
_onShowVenue();
break;
case MenuOptions.showUserPosition:
_onShowUserPosition();
break;
case MenuOptions.changeFloor:
_onChangeFloor();
break;
case MenuOptions.showWorldMap:
_onShowWorldMap();
break;
case MenuOptions.highlightFeatureByRef:
_onHighlightFeatureByRef();
break;
case MenuOptions.directionsMode:
_onDirectionsMode();
break;
case MenuOptions.directions:
_onDirections();
break;
case MenuOptions.clearDirections:
_onClearDirections();
break;
}
},
itemBuilder: (BuildContext context) => <PopupMenuItem<MenuOptions>>[
const PopupMenuItem<MenuOptions>(
value: MenuOptions.showWorldMap,
child: Text('Show World Map'),
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.showVenue,
child: Text('Show Indoor venue(MTP)'),
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.changeFloor,
child: Text('Change floor to 3'),
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.highlightFeatureByRef,
child: Text('Highlight feature'),
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.showUserPosition,
child: Text('User Position'),
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.directionsMode,
child: Text('Directions Mode (wheelchair)'),
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.directions,
child: Text('Directions'),
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.clearDirections,
child: Text('Remove Path'),
),
],
);
}
Future<void>? _onShowVenue() {
// Send a message with the user agent string to the Toaster JavaScript channel we registered
// with the WebView.
return webViewController?.setVenue('mtp');
}
Future<void>? _onShowWorldMap() {
// Send a message with the user agent string to the Toaster JavaScript channel we registered
// with the WebView.
return webViewController?.loadIndoorMap('');
}
Future<void>? _onChangeFloor() {
// Send a message with the user agent string to the Toaster JavaScript channel we registered
// with the WebView.
return webViewController?.setFloor(3);
}
Future<void>? _onShowUserPosition() {
return webViewController?.setLocation(
43.606573820824764, 3.92177514731884, 3, 0, true);
}
Future<void>? _onHighlightFeatureByRef() {
return webViewController?.highlightFeatureByRef('tropiques');
}
Future<void>? _onDirectionsMode() {
return webViewController?.setDirectionsMode('wheelchair');
}
Future<void>? _onDirections() {
webViewController
?.directions(DirectionParameter.fromJson({
"venueId": 'mtp',
"origin": {"lat": 43.60664187325, "lng": 3.921814671575},
"originLevel": 3,
"destination": {"lat": 43.60665215333, "lng": 3.921680093435},
"destinationLevel": 3,
"language": "en",
"units": "metric",
"mode": "wheelchair"
}))
.then((route) => {webViewController?.setDirections(route)});
return null;
}
Future<void>? _onClearDirections() {
return webViewController?.clearDirections();
}
}