-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
133 lines (117 loc) · 3.78 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
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:situm_ar_example/config.dart';
import 'package:situm_flutter/sdk.dart';
import 'package:situm_flutter/wayfinding.dart';
import 'package:situm_flutter_ar/ar.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();
sdk.setDashboardURL(apiDomain);
sdk.setApiKey(situmApiKey);
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,
),
motionMode: MotionMode.byFootVisualOdometry,
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: ARWidget(
buildingIdentifier: buildingIdentifier,
apiDomain: apiDomain,
onCreated: onUnityViewCreated,
onPopulated: onUnityViewPopulated,
onDisposed: onUnityViewDisposed,
enable3DAmbiences: true,
debugMode: true,
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: viewerDomain,
apiDomain: apiDomain,
remoteIdentifier: remoteIdentifier,
persistUnderlyingWidget: true,
),
onLoad: onMapViewLoad,
onError: (error) {
debugPrint("Error loading Map View");
},
),
),
),
);
}
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);
}
}