-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.dart
163 lines (139 loc) · 4.59 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:situm_flutter_ar/ar.dart';
import 'package:situm_ar_example/config.dart';
import 'package:situm_flutter/sdk.dart';
import 'package:situm_flutter/wayfinding.dart';
void main() => runApp(const NavigationBarApp());
class NavigationBarApp extends StatelessWidget {
const NavigationBarApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const NavigationBase(),
);
}
}
class NavigationBase extends StatefulWidget {
const NavigationBase({super.key});
@override
State<NavigationBase> createState() => _NavigationBaseState();
}
class _NavigationBaseState extends State<NavigationBase> {
ARController arController = ARController();
@override
void initState() {
super.initState();
var sdk = SitumSdk();
sdk.init(null, situmApiKey);
// Location:
sdk.onLocationUpdate((location) {
// debugPrint("Situm> SDK> Received location.");
arController.setLocation(location);
});
sdk.onLocationError((error) {
debugPrint("Situm> SDK> ERROR: ${error.message}");
});
sdk.onLocationStatus((status) {
debugPrint("Situm> SDK> STATUS: $status");
});
// Navigation:
sdk.onNavigationCancellation(() {
debugPrint("Situm> SDK> CANCEL NAVIGATION");
arController.setNavigationCancelled();
});
sdk.onNavigationDestinationReached(() {
debugPrint("Situm> SDK> NAVIGATION DESTINATION REACHED");
arController.setNavigationDestinationReached();
});
sdk.onNavigationOutOfRoute(() {
debugPrint("Situm> SDK> NAVIGATION USER OUT OF ROUTE");
arController.setNavigationOutOfRoute();
});
sdk.onNavigationProgress((progress) {
debugPrint("Situm> SDK> NAVIGATION PROGRESS");
arController.setNavigationProgress(progress);
});
sdk.onNavigationStart((route) {
debugPrint("Situm> SDK> NAVIGATION START");
arController.setNavigationStart(route);
});
startPositioning();
}
void startPositioning() async {
await requestPermissions();
SitumSdk().requestLocationUpdates(LocationRequest(
// Copy config.dart.example if you haven't already.
buildingIdentifier: buildingIdentifier,
useDeadReckoning: false,
useForegroundService: true,
foregroundServiceNotificationOptions:
ForegroundServiceNotificationOptions(
showStopAction: true,
),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ARWidget(
buildingIdentifier: buildingIdentifier,
onCreated: onUnityViewCreated,
onPopulated: onUnityViewPopulated,
onDisposed: onUnityViewDisposed,
arHeightRatio: 0.999,
mapView: MapView(
key: const Key("situm_map"),
configuration: MapViewConfiguration(
// Your Situm credentials.
// Copy config.dart.example if you haven't already.
situmApiKey: situmApiKey,
// Set your building identifier:
buildingIdentifier: buildingIdentifier,
viewerDomain: "https://map-viewer.situm.com",
apiDomain: "https://dashboard.situm.com",
remoteIdentifier: remoteIdentifier,
persistUnderlyingWidget: true,
),
onLoad: onMapViewLoad,
),
),
);
}
void onMapViewLoad(MapViewController controller) {
// Notifies the AR module that the MapView has been loaded, ensuring
// seamless integration between both.
arController.onMapViewLoad(controller);
// UI callbacks:
controller.onPoiSelected((poiSelectedResult) {
arController.setSelectedPoi(poiSelectedResult.poi);
});
}
void onUnityViewCreated() {
debugPrint("Situm> AR> UNITY VIEW CREATED.");
}
void onUnityViewPopulated() {
debugPrint("Situm> AR> BUILDING INFO HAS BEEN SENT TO THE AR MODULE.");
}
void onUnityViewDisposed() {
debugPrint("Situm> AR> UNITY VIEW DISPOSED.");
}
/// Example of a function that request permissions and check the result:
Future<bool> requestPermissions() async {
var permissions = <Permission>[
Permission.locationWhenInUse,
Permission.camera,
];
if (Platform.isAndroid) {
permissions.addAll([
Permission.storage,
Permission.bluetoothConnect,
Permission.bluetoothScan,
]);
}
Map<Permission, PermissionStatus> statuses = await permissions.request();
return statuses.values.every((status) => status.isGranted);
}
}