From 4c3c27942625809d3e224d874ad1781aa3d9c020 Mon Sep 17 00:00:00 2001 From: komekh Date: Tue, 27 Aug 2024 14:55:15 +0500 Subject: [PATCH] added location --- lib/core/constants/strings.dart | 3 + lib/presentation/screens/order_details.dart | 2 +- lib/presentation/widgets/map/clustering.dart | 257 ++---------------- .../map/clustering_many_markers_page.dart | 96 ------- pubspec.lock | 24 -- pubspec.yaml | 2 +- 6 files changed, 35 insertions(+), 349 deletions(-) delete mode 100644 lib/presentation/widgets/map/clustering_many_markers_page.dart diff --git a/lib/core/constants/strings.dart b/lib/core/constants/strings.dart index 64c90a8..2b91568 100644 --- a/lib/core/constants/strings.dart +++ b/lib/core/constants/strings.dart @@ -1,6 +1,9 @@ // App const String appTitle = 'Durnukly ýol'; +// empty guid +const String emptyGUID = '00000000-0000-0000-0000-000000000000'; + // Storage and Databases const String articlesTableName = ''; const String databaseName = ''; diff --git a/lib/presentation/screens/order_details.dart b/lib/presentation/screens/order_details.dart index f09a73e..e5ed015 100644 --- a/lib/presentation/screens/order_details.dart +++ b/lib/presentation/screens/order_details.dart @@ -33,7 +33,7 @@ class _OrderDetailsScreenState extends State { void _checkLocationStatus() { setState(() { debugPrint('NAME: ${GoodsState.Reserved.name}'); - _showLocation = widget.order.state != GoodsState.Reserved.name; + _showLocation = widget.order.cargoId != emptyGUID; }); } diff --git a/lib/presentation/widgets/map/clustering.dart b/lib/presentation/widgets/map/clustering.dart index aa72743..bec91e8 100644 --- a/lib/presentation/widgets/map/clustering.dart +++ b/lib/presentation/widgets/map/clustering.dart @@ -1,7 +1,7 @@ +import 'package:cargo/core/constants/colors.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_map/flutter_map.dart'; -import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart'; import 'package:latlong2/latlong.dart'; import '../../../application/order_detail_bloc/order_detail_bloc.dart'; @@ -21,8 +21,6 @@ class ClusteringPage extends StatefulWidget { } class _ClusteringPageState extends State { - final PopupController _popupController = PopupController(); - late List markers; late List polylines; @@ -48,10 +46,15 @@ class _ClusteringPageState extends State { markers = state.routes.map((route) { return Marker( alignment: Alignment.center, - height: 30, - width: 30, + height: 35, + width: 35, point: LatLng(route.lat, route.long), - child: const Icon(Icons.pin_drop), + child: Icon( + Icons.pin_drop_rounded, + color: route.isCurrent ? AppColors.primary : Colors.red, + size: 40, + ), + rotate: true, ); }).toList(); @@ -61,81 +64,33 @@ class _ClusteringPageState extends State { points: state.routes.map((route) { return LatLng(route.lat, route.long); }).toList(), - borderStrokeWidth: 6.6, + borderStrokeWidth: 3.5, color: Colors.blue, borderColor: Colors.green, ), ]; - return PopupScope( - popupController: _popupController, - child: FlutterMap( - options: MapOptions( - initialCenter: - markers.isNotEmpty ? markers.first.point : const LatLng(0, 0), // Default to (0, 0) if no markers - initialZoom: 4.5, - maxZoom: 45, - onTap: (_, __) => _popupController.hideAllPopups(), - ), - children: [ - TileLayer( - urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', - subdomains: const ['a', 'b', 'c'], - ), - MarkerClusterLayerWidget( - options: MarkerClusterLayerOptions( - spiderfyCircleRadius: 80, - spiderfySpiralDistanceMultiplier: 2, - circleSpiralSwitchover: 12, - maxClusterRadius: 120, - rotate: true, - size: const Size(40, 40), - alignment: Alignment.center, - padding: const EdgeInsets.all(50), - maxZoom: 15, - markers: markers, - polygonOptions: const PolygonOptions( - borderColor: Colors.blueAccent, - color: Colors.black12, - borderStrokeWidth: 3, - ), - popupOptions: PopupOptions( - popupSnap: PopupSnap.markerTop, - popupController: _popupController, - popupBuilder: (_, marker) => Container( - width: 200, - height: 100, - color: Colors.white, - child: GestureDetector( - onTap: () => debugPrint('Popup tap!'), - child: const Text( - 'Container popup for marker', - ), - ), - ), - ), - builder: (context, markers) { - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20), - color: Colors.blue, - ), - child: Center( - child: Text( - markers.length.toString(), - style: const TextStyle(color: Colors.white), - ), - ), - ); - }, - ), - ), - PolylineLayer( - polylineCulling: true, - polylines: polylines, - ), - ], + return FlutterMap( + options: MapOptions( + initialCenter: markers.isNotEmpty ? markers.first.point : const LatLng(0, 0), + initialZoom: 4.5, + maxZoom: 45, + // onTap: (_, __) => _popupController.hideAllPopups(), ), + children: [ + TileLayer( + urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', + subdomains: const ['a', 'b', 'c'], + ), + PolylineLayer( + polylineCulling: true, + polylines: polylines, + ), + MarkerLayer( + alignment: Alignment.topCenter, + markers: markers, + ), + ], ); } else if (state is RoutesError) { return Center( @@ -149,155 +104,3 @@ class _ClusteringPageState extends State { ); } } - -/* class ClusteringPage extends StatefulWidget { - static const String route = 'clusteringPage'; - - const ClusteringPage({super.key}); - - @override - State createState() => _ClusteringPageState(); -} - -class _ClusteringPageState extends State { - final PopupController _popupController = PopupController(); - - late List markers; - late int pointIndex; - List points = [ - const LatLng(37.90970, 58.39795), - const LatLng(37.90491, 58.39742), - ]; - - @override - void initState() { - pointIndex = 0; - markers = [ - Marker( - alignment: Alignment.center, - height: 30, - width: 30, - point: points[pointIndex], - child: const Icon(Icons.pin_drop), - ), - const Marker( - alignment: Alignment.center, - height: 30, - width: 30, - point: LatLng(49.8566, 3.3522), - child: Icon(Icons.pin_drop), - ), - const Marker( - alignment: Alignment.center, - height: 30, - width: 30, - point: LatLng(49.8566, 3.3522), - child: Icon(Icons.pin_drop), - ), - ]; - - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - pointIndex++; - if (pointIndex >= points.length) { - pointIndex = 0; - } - setState(() { - markers[0] = Marker( - point: points[pointIndex], - alignment: Alignment.center, - height: 30, - width: 30, - child: const Icon(Icons.pin_drop), - ); - markers = List.from(markers); - }); - }, - child: const Icon(Icons.refresh), - ), - body: PopupScope( - popupController: _popupController, - child: FlutterMap( - options: MapOptions( - initialCenter: points[0], - initialZoom: 4.5, - maxZoom: 45, - onTap: (_, __) => _popupController.hideAllPopups(), // Hide popup when the map is tapped. - ), - children: [ - TileLayer( - urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', - subdomains: const ['a', 'b', 'c'], - ), - MarkerClusterLayerWidget( - options: MarkerClusterLayerOptions( - spiderfyCircleRadius: 80, - spiderfySpiralDistanceMultiplier: 2, - circleSpiralSwitchover: 12, - maxClusterRadius: 120, - rotate: true, - size: const Size(40, 40), - alignment: Alignment.center, - padding: const EdgeInsets.all(50), - maxZoom: 15, - markers: markers, - polygonOptions: const PolygonOptions( - borderColor: Colors.blueAccent, - color: Colors.black12, - borderStrokeWidth: 3, - ), - popupOptions: PopupOptions( - popupSnap: PopupSnap.markerTop, - popupController: _popupController, - popupBuilder: (_, marker) => Container( - width: 200, - height: 100, - color: Colors.white, - child: GestureDetector( - onTap: () => debugPrint('Popup tap!'), - child: const Text( - 'Container popup for marker', - ), - ), - ), - ), - builder: (context, markers) { - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20), - color: Colors.blue, - ), - child: Center( - child: Text( - markers.length.toString(), - style: const TextStyle(color: Colors.white), - ), - ), - ); - }, - ), - ), - PolylineLayer( - polylineCulling: true, - polylines: [ - Polyline( - points: [const LatLng(37.90970, 58.39795), const LatLng(37.90491, 58.39742)], - borderStrokeWidth: 6.6, - color: Colors.red, - borderColor: Colors.green, - ), - ], - ), - ], - ), - ), - ); - } -} - */ \ No newline at end of file diff --git a/lib/presentation/widgets/map/clustering_many_markers_page.dart b/lib/presentation/widgets/map/clustering_many_markers_page.dart deleted file mode 100644 index 439b111..0000000 --- a/lib/presentation/widgets/map/clustering_many_markers_page.dart +++ /dev/null @@ -1,96 +0,0 @@ -import 'dart:math'; - -import 'package:flutter/material.dart'; -import 'package:flutter_map/flutter_map.dart'; -import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart'; -import 'package:latlong2/latlong.dart'; - -class ClusteringManyMarkersPage extends StatefulWidget { - static const String route = 'clusteringManyMarkersPage'; - - const ClusteringManyMarkersPage({super.key}); - - @override - State createState() => _ClusteringManyMarkersPageState(); -} - -class _ClusteringManyMarkersPageState extends State { - static const totalMarkers = 2000.0; - final minLatLng = const LatLng(49.8566, 1.3522); - final maxLatLng = const LatLng(58.3498, -10.2603); - - late List markers; - - @override - void initState() { - final latitudeRange = maxLatLng.latitude - minLatLng.latitude; - final longitudeRange = maxLatLng.longitude - minLatLng.longitude; - - final stepsInEachDirection = sqrt(totalMarkers).floor(); - final latStep = latitudeRange / stepsInEachDirection; - final lonStep = longitudeRange / stepsInEachDirection; - - markers = []; - for (var i = 0; i < stepsInEachDirection; i++) { - for (var j = 0; j < stepsInEachDirection; j++) { - final latLng = LatLng( - minLatLng.latitude + i * latStep, - minLatLng.longitude + j * lonStep, - ); - - markers.add( - Marker( - height: 30, - width: 30, - point: latLng, - child: const Icon(Icons.pin_drop), - ), - ); - } - } - - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: const Text('Clustering Many Markers Page')), - body: FlutterMap( - options: MapOptions( - initialCenter: - LatLng((maxLatLng.latitude + minLatLng.latitude) / 2, (maxLatLng.longitude + minLatLng.longitude) / 2), - initialZoom: 6, - maxZoom: 15, - ), - children: [ - TileLayer( - urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', - subdomains: const ['a', 'b', 'c'], - ), - MarkerClusterLayerWidget( - options: MarkerClusterLayerOptions( - maxClusterRadius: 45, - size: const Size(40, 40), - alignment: Alignment.center, - padding: const EdgeInsets.all(50), - maxZoom: 15, - markers: markers, - builder: (context, markers) { - return Container( - decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), color: Colors.blue), - child: Center( - child: Text( - markers.length.toString(), - style: const TextStyle(color: Colors.white), - ), - ), - ); - }, - ), - ), - ], - ), - ); - } -} diff --git a/pubspec.lock b/pubspec.lock index e98e655..9a4ef0e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,14 +1,6 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - animated_stack_widget: - dependency: transitive - description: - name: animated_stack_widget - sha256: ce4788dd158768c9d4388354b6fb72600b78e041a37afc4c279c63ecafcb9408 - url: "https://pub.dev" - source: hosted - version: "0.0.4" args: dependency: transitive description: @@ -163,22 +155,6 @@ packages: url: "https://pub.dev" source: hosted version: "6.2.1" - flutter_map_marker_cluster: - dependency: "direct main" - description: - name: flutter_map_marker_cluster - sha256: a324f48da5ee83a3f29fd8d08b4b1e6e3114ff5c6cab910124d6a2e1f06f08cc - url: "https://pub.dev" - source: hosted - version: "1.3.6" - flutter_map_marker_popup: - dependency: transitive - description: - name: flutter_map_marker_popup - sha256: ec563bcbae24a18ac16815fb75ac5ab33ccba609e14db70e252a67de19c6639c - url: "https://pub.dev" - source: hosted - version: "6.1.2" flutter_phoenix: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 279fe2d..ee6ba8d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,7 +24,7 @@ dependencies: flutter_svg: ^2.0.10+1 flutter_map: ">=6.0.0 <7.0.0" latlong2: ^0.9.0 - flutter_map_marker_cluster: ^1.3.6 + # flutter_map_marker_cluster: ^1.3.6 easy_localization: ^3.0.7 intl: ^0.19.0