|
|
|
|
@ -5,9 +5,11 @@ import 'package:flutter_map/flutter_map.dart';
|
|
|
|
|
import 'package:flutter_map_geojson2/flutter_map_geojson2.dart';
|
|
|
|
|
import 'package:latlong2/latlong.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/helper/utils.dart';
|
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/item_views/info_text_widget.dart';
|
|
|
|
|
|
|
|
|
|
import 'asset_tracking_provider.dart';
|
|
|
|
|
import 'models/asset_tracking_model.dart';
|
|
|
|
|
@ -15,9 +17,8 @@ import 'models/floor_map_model.dart';
|
|
|
|
|
|
|
|
|
|
class MapTrackingPage extends StatefulWidget {
|
|
|
|
|
final AssetTrackingModel? assetTrackingData;
|
|
|
|
|
final bool inAppView;
|
|
|
|
|
|
|
|
|
|
MapTrackingPage({Key? key, this.inAppView = false, this.assetTrackingData}) : super(key: key);
|
|
|
|
|
MapTrackingPage({Key? key, this.assetTrackingData}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_MapTrackingPageState createState() {
|
|
|
|
|
@ -29,33 +30,38 @@ class _MapTrackingPageState extends State<MapTrackingPage> {
|
|
|
|
|
final MapController mapController = MapController();
|
|
|
|
|
late AssetTrackingProvider assetTrackingProvider;
|
|
|
|
|
|
|
|
|
|
late bool inAppView;
|
|
|
|
|
|
|
|
|
|
FloorMapModel? floorMapModel;
|
|
|
|
|
Map<String, dynamic>? _geojson;
|
|
|
|
|
List<Marker> markers = [];
|
|
|
|
|
LatLngBounds? _computedBounds;
|
|
|
|
|
final ExpansibleController expansibleController = ExpansibleController();
|
|
|
|
|
|
|
|
|
|
// Fallback shown only until the real floor plan bounds are computed.
|
|
|
|
|
static const LatLng _fallbackCenter = LatLng(24.81200245073082, 46.624273601310186);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
inAppView = widget.assetTrackingData == null;
|
|
|
|
|
assetTrackingProvider = Provider.of<AssetTrackingProvider>(context, listen: false);
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
if (widget.assetTrackingData != null) {
|
|
|
|
|
print('widget.assetTrackingData!.location!.floor!.id!: ${widget.assetTrackingData!.toJson()}');
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
assetTrackingProvider.getFloorMap(widget.assetTrackingData!.location!.floor!.id!).then((floorMap) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
_onFloorMapLoaded(floorMap);
|
|
|
|
|
}).catchError((error) {
|
|
|
|
|
print('Failed to load floor map: $error');
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
});
|
|
|
|
|
if (!inAppView) {
|
|
|
|
|
getFloorMap(widget.assetTrackingData!.location!.floor!.id!);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getFloorMap(int id) {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
assetTrackingProvider.getFloorMap(id).then((floorMap) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
_onFloorMapLoaded(floorMap);
|
|
|
|
|
}).catchError((error) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onFloorMapLoaded(FloorMapModel? loadedFloorMap) {
|
|
|
|
|
floorMapModel = loadedFloorMap;
|
|
|
|
|
|
|
|
|
|
@ -142,18 +148,44 @@ class _MapTrackingPageState extends State<MapTrackingPage> {
|
|
|
|
|
_geojson!,
|
|
|
|
|
styleDefaults: GeoJsonStyleDefaults.leaflet,
|
|
|
|
|
),
|
|
|
|
|
MarkerLayer(markers: markers),
|
|
|
|
|
if (!inAppView) MarkerLayer(markers: markers),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return widget.inAppView
|
|
|
|
|
? mapWidget
|
|
|
|
|
: Scaffold(
|
|
|
|
|
appBar: const DefaultAppBar(title: "Live Asset Tracking"),
|
|
|
|
|
body: Stack(
|
|
|
|
|
children: [mapWidget],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return inAppView
|
|
|
|
|
? Stack(
|
|
|
|
|
alignment: AlignmentDirectional.topCenter,
|
|
|
|
|
children: [
|
|
|
|
|
mapWidget,
|
|
|
|
|
Container(
|
|
|
|
|
margin: const EdgeInsets.all(16),
|
|
|
|
|
padding: const EdgeInsets.only(right: 16, left: 16),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColor.tabBarBackground(context),
|
|
|
|
|
border: Border.all(color: AppColor.tabBarBorder(context)),
|
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
|
),
|
|
|
|
|
child: Theme(
|
|
|
|
|
data: ThemeData(splashColor: Colors.transparent, hoverColor: Colors.transparent, highlightColor: Colors.transparent),
|
|
|
|
|
child: ExpansionTile(
|
|
|
|
|
shape: Border.all(color: Colors.transparent, width: 0),
|
|
|
|
|
collapsedShape: Border.all(color: Colors.transparent, width: 0),
|
|
|
|
|
controller: expansibleController,
|
|
|
|
|
title: const InfoTextLabelWidget(label: "Search Floor Map"),
|
|
|
|
|
iconColor: AppColor.icon2Color(context),
|
|
|
|
|
collapsedIconColor: AppColor.icon2Color(context),
|
|
|
|
|
dense: true,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
|
|
|
|
|
],
|
|
|
|
|
childrenPadding: EdgeInsets.all(0),
|
|
|
|
|
tilePadding: EdgeInsets.all(0),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
: Scaffold(appBar: const DefaultAppBar(title: "Live Asset Tracking"), body: mapWidget);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|