From ed4f91ce98fd8b133a461b225c6759562aa6031d Mon Sep 17 00:00:00 2001 From: komekh Date: Mon, 19 Aug 2024 11:02:02 +0500 Subject: [PATCH] loaded map data --- lib/core/app/app.dart | 5 +- lib/core/enums/enums.dart | 8 + .../remote/order_remote_data_source.dart | 6 +- .../entities/order/filter_params_model.dart | 6 + .../screens/histories_screen.dart | 14 +- lib/presentation/screens/order_details.dart | 8 +- lib/presentation/widgets/map/clustering.dart | 258 ++++++++++-------- 7 files changed, 180 insertions(+), 125 deletions(-) diff --git a/lib/core/app/app.dart b/lib/core/app/app.dart index 77eb684..6f4bc5b 100644 --- a/lib/core/app/app.dart +++ b/lib/core/app/app.dart @@ -25,7 +25,10 @@ class MyApp extends StatelessWidget { create: (context) => di.sl(), //..add(CheckUser()), ), BlocProvider( - create: (context) => di.sl()..add(const GetOrders(FilterProductParams())), + create: (context) => di.sl() + ..add(const GetOrders( + FilterProductParams(state: GoodsState.Received), + )), ), BlocProvider( create: (context) => di.sl(), diff --git a/lib/core/enums/enums.dart b/lib/core/enums/enums.dart index 9643444..0bf7b7d 100644 --- a/lib/core/enums/enums.dart +++ b/lib/core/enums/enums.dart @@ -1 +1,9 @@ +// ignore_for_file: constant_identifier_names + enum NavigationTab { home, histories, profile } + +enum GoodsState { + Reserved, + Received, + Delivered, +} diff --git a/lib/data/data_sources/remote/order_remote_data_source.dart b/lib/data/data_sources/remote/order_remote_data_source.dart index 9041d7f..6f62971 100644 --- a/lib/data/data_sources/remote/order_remote_data_source.dart +++ b/lib/data/data_sources/remote/order_remote_data_source.dart @@ -16,8 +16,12 @@ class OrderRemoteDataSourceImpl implements OrderRemoteDataSource { @override Future getOrders(FilterProductParams params, String token) async { + Uri uri = Uri.parse( + '$baseUrl/Goods?pageNumber=${params.offset}&pageSize=${params.limit}${params.state != null ? '&state=${params.state!.name}' : ''}', + ); + final response = await client.get( - Uri.parse('$baseUrl/Goods?pageNumber=${params.offset}&pageSize=${params.limit}'), + uri, headers: { 'Content-Type': 'application/json', 'accept': '*/*', diff --git a/lib/domain/entities/order/filter_params_model.dart b/lib/domain/entities/order/filter_params_model.dart index 783217e..725e3f9 100644 --- a/lib/domain/entities/order/filter_params_model.dart +++ b/lib/domain/entities/order/filter_params_model.dart @@ -1,19 +1,25 @@ +import 'package:cargo/core/core.dart'; + class FilterProductParams { final int offset; final int limit; + final GoodsState? state; const FilterProductParams({ this.offset = 1, this.limit = 10, + this.state, }); FilterProductParams copyWith({ int? offset, int? limit, + GoodsState? state, }) { return FilterProductParams( offset: offset ?? this.offset, limit: limit ?? this.limit, + state: state ?? this.state, ); } } diff --git a/lib/presentation/screens/histories_screen.dart b/lib/presentation/screens/histories_screen.dart index c8d142c..912ce86 100644 --- a/lib/presentation/screens/histories_screen.dart +++ b/lib/presentation/screens/histories_screen.dart @@ -4,11 +4,23 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import '../../application/order_bloc/order_bloc.dart'; import '../../configs/configs.dart'; import '../../core/core.dart'; +import '../../domain/entities/order/filter_params_model.dart'; import '../widgets/widgets.dart'; -class HistoriesScreen extends StatelessWidget { +class HistoriesScreen extends StatefulWidget { const HistoriesScreen({super.key}); + @override + State createState() => _HistoriesScreenState(); +} + +class _HistoriesScreenState extends State { + @override + void initState() { + super.initState(); + context.read().add(const GetOrders(FilterProductParams())); + } + @override Widget build(BuildContext context) { App.init(context); diff --git a/lib/presentation/screens/order_details.dart b/lib/presentation/screens/order_details.dart index 182b398..e20170a 100644 --- a/lib/presentation/screens/order_details.dart +++ b/lib/presentation/screens/order_details.dart @@ -1,10 +1,10 @@ -import 'package:cargo/application/application.dart'; import 'package:cargo/configs/configs.dart'; -import 'package:cargo/domain/domain.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../application/order_detail_bloc/order_detail_bloc.dart'; import '../../core/core.dart'; +import '../../domain/entities/order/order.dart'; import '../widgets/map/clustering.dart'; import '../widgets/widgets.dart'; @@ -34,7 +34,7 @@ class _OrderDetailsScreenState extends State { ), backgroundColor: AppColors.primary, title: Text( - 'Sargyt №ABC456789', + 'Sargyt ${widget.order.name}', style: AppText.h2!.copyWith(color: Colors.white), ), ), @@ -43,7 +43,7 @@ class _OrderDetailsScreenState extends State { /// map SliverToBoxAdapter( child: SizedBox( - height: AppDimensions.normalize(120), + height: AppDimensions.normalize(130), child: const ClusteringPage(), ), ), diff --git a/lib/presentation/widgets/map/clustering.dart b/lib/presentation/widgets/map/clustering.dart index 0972dfb..3747731 100644 --- a/lib/presentation/widgets/map/clustering.dart +++ b/lib/presentation/widgets/map/clustering.dart @@ -1,8 +1,11 @@ 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'; + class ClusteringPage extends StatefulWidget { static const String route = 'clusteringPage'; @@ -12,6 +15,141 @@ class ClusteringPage extends StatefulWidget { State createState() => _ClusteringPageState(); } +class _ClusteringPageState extends State { + final PopupController _popupController = PopupController(); + + late List markers; + late List polylines; + + @override + void initState() { + super.initState(); + markers = []; + polylines = []; + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: BlocBuilder( + builder: (context, state) { + if (state is RoutesLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is RoutesLoaded) { + markers = state.routes.map((route) { + return Marker( + alignment: Alignment.center, + height: 30, + width: 30, + point: LatLng(route.lat, route.long), + child: const Icon(Icons.pin_drop), + ); + }).toList(); + + // Update polylines + polylines = [ + Polyline( + points: state.routes.map((route) { + return LatLng(route.lat, route.long); + }).toList(), + borderStrokeWidth: 6.6, + 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, + ), + ], + ), + ); + } else if (state is RoutesError) { + return Center( + child: Text('Error loading routes: ${state.failure}'), + ); + } else { + return const Center(child: Text('No data')); + } + }, + ), + ); + } +} + +/* 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(); @@ -47,111 +185,6 @@ class _ClusteringPageState extends State { 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), - ), - 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), - ), - 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), - ), - 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), - ), - 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), - ), - 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), - ), - 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), - ), - 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(); @@ -245,19 +278,7 @@ class _ClusteringPageState extends State { polylineCulling: true, polylines: [ Polyline( - points: [ - // const LatLng(51.5, -0.09), - // const LatLng(49.8566, 3.3522), - // const LatLng(49.8566, 1.3522), - // const LatLng(47.8566, 1.3522), - // const LatLng(47.8566, 5.3522), - // const LatLng(44.8566, 5.3522), - // const LatLng(49.8566, 12.3522), - // const LatLng(49.8864, 13.4522), - // const LatLng(49.8966, 13.6522), - const LatLng(37.90970, 58.39795), - const LatLng(37.90491, 58.39742) - ], + points: [const LatLng(37.90970, 58.39795), const LatLng(37.90491, 58.39742)], borderStrokeWidth: 6.6, color: Colors.red, borderColor: Colors.green, @@ -270,3 +291,4 @@ class _ClusteringPageState extends State { ); } } + */ \ No newline at end of file