Files
rog_app/lib/widgets/map_widget.dart

296 lines
11 KiB
Dart
Raw Normal View History

2022-05-18 19:09:26 +05:30
import 'dart:async';
2022-03-14 12:28:57 +05:30
import 'package:flutter/material.dart';
2023-12-06 11:16:17 +05:30
import 'package:flutter_map/flutter_map.dart';
2022-03-14 12:28:57 +05:30
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
2022-04-17 11:45:21 +05:30
import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart';
2023-06-11 21:03:30 +05:30
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
2023-12-06 11:16:17 +05:30
import 'package:geojson_vi/geojson_vi.dart';
2022-03-14 12:28:57 +05:30
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
2023-09-14 22:53:51 +05:30
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
2022-05-12 02:17:08 +05:30
import 'package:rogapp/pages/index/index_controller.dart';
2023-11-21 22:43:28 +05:30
import 'package:rogapp/utils/database_helper.dart';
2023-01-22 18:05:15 +05:30
import 'package:rogapp/utils/text_util.dart';
2022-03-14 12:28:57 +05:30
import 'package:rogapp/widgets/base_layer_widget.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/widgets/bottom_sheet_new.dart';
2024-02-04 19:14:41 +05:30
import 'package:rogapp/widgets/game_state_view.dart';
2022-03-14 12:28:57 +05:30
2024-03-02 11:11:46 +05:30
class MapWidget extends StatefulWidget {
MapWidget({Key? key}) : super(key: key);
@override
State<MapWidget> createState() => _MapWidgetState();
}
class _MapWidgetState extends State<MapWidget> {
2022-04-17 11:45:21 +05:30
final IndexController indexController = Get.find<IndexController>();
2024-03-02 11:11:46 +05:30
2023-09-06 21:36:11 +05:30
final DestinationController destinationController =
Get.find<DestinationController>();
2022-03-30 16:19:18 +05:30
2022-05-18 19:09:26 +05:30
StreamSubscription? subscription;
2024-03-02 11:11:46 +05:30
Timer? _timer;
2022-05-18 19:09:26 +05:30
2023-12-06 11:16:17 +05:30
Widget getMarkerShape(GeoJSONFeature i, BuildContext context) {
GeoJSONMultiPoint p = i.geometry as GeoJSONMultiPoint;
2023-03-17 11:54:12 +05:30
//print("lat is ${p.geoSerie!.geoPoints[0].latitude} and lon is ${p.geoSerie!.geoPoints[0].longitude}");
2023-10-06 16:25:21 +05:30
//RegExp regex = RegExp(r'([.]*0)(?!.*\d)');
2024-01-17 16:08:41 +05:30
return InkWell(
onTap: () {
GeoJSONFeature? fs = indexController.getFeatureForLatLong(
p.coordinates[0][1], p.coordinates[0][0]);
//print("------- fs $fs------");
if (fs != null) {
indexController.currentFeature.clear();
indexController.currentFeature.add(fs);
//print("----- fs is ${fs.properties!['photos']}");
2023-03-17 11:54:12 +05:30
2024-01-17 16:08:41 +05:30
Destination des = destinationController.festuretoDestination(fs);
2023-09-14 22:53:51 +05:30
2024-01-17 16:08:41 +05:30
DatabaseHelper db = DatabaseHelper.instance;
db.getDestinationByLatLon(des.lat!, des.lon!).then((value) {
showModalBottomSheet(
constraints:
BoxConstraints.loose(Size(Get.width, Get.height * 0.85)),
context: context,
isScrollControlled: true,
isDismissible: true,
builder: ((context) => BottomSheetNew(
destination: des, isAlreadyCheckedIn: value.isNotEmpty))
//builder:((context) => BottomSheetWidget())
).whenComplete(() {
destinationController.skipGps = false;
});
});
}
},
child: Stack(
fit: StackFit.expand,
//mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
2023-09-06 21:36:11 +05:30
height: 32,
width: 32,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.transparent,
border: Border.all(
color: i.properties!['buy_point'] > 0
? Colors.blue
: Colors.red,
width: 3,
style: BorderStyle.solid)),
child: Stack(
alignment: Alignment.center,
children: [
const Icon(
Icons.circle,
size: 6.0,
),
i.properties!['cp'] == -1
2023-12-12 16:16:17 +05:30
? Transform.translate(
offset: Offset(18, 0),
child: Transform.rotate(
alignment: Alignment.centerLeft,
origin: Offset.fromDirection(1, 26),
angle: 270 * pi / 180,
child: const Icon(
Icons.play_arrow_outlined,
color: Colors.red,
size: 70,
)),
)
2023-09-06 21:36:11 +05:30
: Container(
color: Colors.transparent,
),
],
)),
2024-01-17 16:08:41 +05:30
Transform.translate(
offset: Offset(45, 0),
child: Align(
alignment: Alignment.center,
child: Container(
color: Colors.purple.withOpacity(0.2),
// child: Text(TextUtils.getDisplayTextFeture(i),
// style: const TextStyle(
// fontSize: 16,
// fontWeight: FontWeight.bold,
// color: Colors.red,
// ))),
child: Stack(
children: <Widget>[
// Text with white outline
Text(
TextUtils.getDisplayTextFeture(i),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1
..color = Colors.white,
),
2024-01-08 15:14:44 +05:30
),
2024-01-17 16:08:41 +05:30
// Text with black fill
Text(
TextUtils.getDisplayTextFeture(i),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: Colors.black,
),
2024-01-08 15:14:44 +05:30
),
2024-01-17 16:08:41 +05:30
],
)),
),
)
],
),
2023-09-06 21:36:11 +05:30
);
2022-09-27 17:52:54 +05:30
}
2023-09-06 21:36:11 +05:30
List<LatLng>? getPoints() {
2023-10-06 16:25:21 +05:30
//print("##### --- route point ${indexController.routePoints.length}");
2023-09-06 21:36:11 +05:30
List<LatLng> pts = [];
for (PointLatLng p in indexController.routePoints) {
LatLng l = LatLng(p.latitude, p.longitude);
pts.add(l);
2023-06-11 21:03:30 +05:30
}
2023-09-06 21:36:11 +05:30
return pts;
}
2023-06-11 21:03:30 +05:30
2024-03-02 11:11:46 +05:30
@override
void initState() {
super.initState();
_startIdleTimer();
}
void _startIdleTimer() {
_timer = Timer(const Duration(milliseconds: (1000 * 10)), _centerMapOnUser);
2024-03-02 11:11:46 +05:30
}
void _resetTimer() {
_timer?.cancel();
_startIdleTimer();
}
void _centerMapOnUser() {
print("showBottomSheet ${destinationController.shouldShowBottomSheet}");
if (destinationController.shouldShowBottomSheet) {
destinationController.centerMapToCurrentLocation();
}
2024-03-02 11:11:46 +05:30
}
2022-03-14 12:28:57 +05:30
@override
Widget build(BuildContext context) {
2023-10-06 16:25:21 +05:30
// print(
// "---------- rog mode is ${indexController.rog_mode.value.toString()}----------");
2022-07-09 22:51:34 +05:30
2023-10-06 16:25:21 +05:30
final PopupController popupController = PopupController();
2022-04-17 11:45:21 +05:30
return Stack(
2023-09-06 21:36:11 +05:30
children: [
2023-10-06 16:25:21 +05:30
Obx(() => indexController.isLoading.value == true
2023-09-06 21:36:11 +05:30
? const Padding(
padding: EdgeInsets.only(top: 60.0),
child: CircularProgressIndicator(),
)
: FlutterMap(
mapController: indexController.mapController,
options: MapOptions(
maxZoom: 18.4,
onMapReady: () {
subscription = indexController.mapController.mapEventStream
.listen((MapEvent mapEvent) {
if (mapEvent is MapEventMoveStart) {
2024-03-02 11:11:46 +05:30
// print(DateTime.now().toString() +
// ' [MapEventMoveStart] START');
2023-09-06 21:36:11 +05:30
// do something
}
2023-10-06 16:25:21 +05:30
if (mapEvent is MapEventMoveEnd) {}
2023-09-06 21:36:11 +05:30
});
},
//center: LatLng(37.15319600454702, 139.58765950528198),
bounds: indexController.currentBound.isNotEmpty
? indexController.currentBound[0]
: LatLngBounds.fromPoints([
LatLng(35.03999881162295, 136.40587119778962),
LatLng(36.642756778706904, 137.95226720406063)
]),
zoom: 1,
interactiveFlags:
InteractiveFlag.pinchZoom | InteractiveFlag.drag,
2022-05-18 19:09:26 +05:30
2024-03-02 11:11:46 +05:30
onPositionChanged: (MapPosition pos, hasGesture) {
//print("map position changed ${pos.center!.latitude}");
if (hasGesture) {
_resetTimer();
}
2023-09-11 18:04:29 +05:30
indexController.currentBound = [pos.bounds!];
},
2023-10-06 16:25:21 +05:30
onTap: (_, __) => popupController
2023-09-06 21:36:11 +05:30
.hideAllPopups(), // Hide popup when the map is tapped.
),
children: [
const BaseLayer(),
Obx(
() => indexController.routePointLenght > 0
? PolylineLayer(
polylines: [
Polyline(
points: getPoints()!,
strokeWidth: 6.0,
color: Colors.indigo),
],
2023-03-17 11:54:12 +05:30
)
2023-09-06 21:36:11 +05:30
: Container(),
),
2023-09-15 12:05:05 +05:30
CurrentLocationLayer(
2023-10-06 16:25:21 +05:30
followOnLocationUpdate: FollowOnLocationUpdate.never,
2023-09-15 12:05:05 +05:30
turnOnHeadingUpdate: TurnOnHeadingUpdate.never,
style: const LocationMarkerStyle(
marker: DefaultLocationMarker(
child: Icon(
Icons.navigation,
color: Colors.yellowAccent,
),
),
markerSize: Size(27, 27),
markerDirection: MarkerDirection.heading,
),
),
2023-09-06 21:36:11 +05:30
indexController.locations.isNotEmpty &&
2023-12-06 11:16:17 +05:30
indexController.locations[0].features.isNotEmpty
2023-09-06 21:36:11 +05:30
? MarkerLayer(
markers:
2023-12-06 11:16:17 +05:30
indexController.locations[0].features.map((i) {
2023-10-06 16:25:21 +05:30
//print("i si ${i.properties!['location_id']}");
2023-09-06 21:36:11 +05:30
RegExp regex = RegExp(r'([.]*0)(?!.*\d)');
2023-12-06 11:16:17 +05:30
GeoJSONMultiPoint p =
i!.geometry as GeoJSONMultiPoint;
2023-10-06 16:25:21 +05:30
//print(
// "lat is ${p.geoSerie!.geoPoints[0].latitude} and lon is ${p.geoSerie!.geoPoints[0].longitude}");
2023-09-06 21:36:11 +05:30
return Marker(
2023-12-07 10:20:44 +05:30
alignment: Alignment.center,
2023-12-12 16:16:17 +05:30
height: 27.0,
width: 127.0,
2023-12-06 11:16:17 +05:30
point: LatLng(
p.coordinates[0][1], p.coordinates[0][0]),
child: getMarkerShape(i, context));
2023-09-06 21:36:11 +05:30
}).toList(),
)
: const Center(child: CircularProgressIndicator()),
],
2023-11-28 15:58:37 +05:30
)),
2024-02-04 19:14:41 +05:30
const Positioned(top: 0, left: 0, child: GameStateWidget()),
// const Positioned(
// bottom: 10,
// left: 0,
// child: DebugWidget(),
// )
2023-09-06 21:36:11 +05:30
],
);
2022-03-14 12:28:57 +05:30
}
2023-09-06 21:36:11 +05:30
}