From ea874c094c386e9a707ab8eb424c98c51381a526 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Thu, 24 Mar 2022 14:20:04 +0530 Subject: [PATCH] update --- lib/pages/home/home_controller.dart | 8 ++ lib/pages/home/home_page.dart | 9 +- lib/pages/map/map_page.dart | 181 +++++++++++++++----------- lib/services/location_service.dart | 2 +- lib/services/perfecture_service.dart | 24 ++++ lib/widgets/bottom_sheet_widget.dart | 185 ++++++++++++++++++--------- lib/widgets/perfecture_widget.dart | 59 +++++++++ 7 files changed, 326 insertions(+), 142 deletions(-) create mode 100644 lib/services/perfecture_service.dart create mode 100644 lib/widgets/perfecture_widget.dart diff --git a/lib/pages/home/home_controller.dart b/lib/pages/home/home_controller.dart index 6e2545c..1b7a2ec 100644 --- a/lib/pages/home/home_controller.dart +++ b/lib/pages/home/home_controller.dart @@ -3,11 +3,13 @@ import 'package:geojson/geojson.dart'; import 'package:get/get.dart'; import 'package:rogapp/services/location_service.dart'; +import 'package:rogapp/services/perfecture_service.dart'; class HomeController extends GetxController { List locations = [].obs; List currentFeature = [].obs; + List perfectures = [].obs; @override @@ -16,6 +18,12 @@ class HomeController extends GetxController { LocationService.loadLocations().then((value){ locations.add(value!); }); + + PerfectureService.loadPerfectures().then((value){ + perfectures.add(value); + print(perfectures); + }); + } GeoJsonFeature? getFeatureForLatLong(double lat, double long){ diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index c6dabf4..2b22e39 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -7,6 +7,7 @@ import 'package:get/get.dart'; import 'package:rogapp/pages/drawer/drawer_page.dart'; import 'package:rogapp/pages/home/home_controller.dart'; import 'package:rogapp/routes/app_pages.dart'; +import 'package:rogapp/services/perfecture_service.dart'; import 'package:rogapp/widgets/bottom_sheet_widget.dart'; import 'package:flutter_breadcrumb/flutter_breadcrumb.dart'; @@ -14,6 +15,7 @@ class HomePage extends GetView { final HomeController homeController = Get.find(); + void changeCurrentFeature(GeoJsonFeature fs){ if(homeController.currentFeature.length > 0){ homeController.currentFeature.clear(); @@ -74,7 +76,12 @@ class HomePage extends GetView { height: 50.0, child: BreadCrumb( items: [ - BreadCrumbItem(content: Text('Item1', style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),)), + BreadCrumbItem( + content: ElevatedButton(child: Text("Press"), onPressed: (){ + print("-----"); + print(homeController.perfectures[0][0]); + },) + ), BreadCrumbItem(content: Text('Item2', style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),)), ], divider: Icon(Icons.chevron_right), diff --git a/lib/pages/map/map_page.dart b/lib/pages/map/map_page.dart index a2ddc54..8c02435 100644 --- a/lib/pages/map/map_page.dart +++ b/lib/pages/map/map_page.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_breadcrumb/flutter_breadcrumb.dart'; import 'package:flutter_map/plugin_api.dart'; import 'package:flutter_map_location_marker/flutter_map_location_marker.dart'; import 'package:geojson/geojson.dart'; @@ -11,6 +13,7 @@ import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart'; import 'package:rogapp/routes/app_pages.dart'; import 'package:rogapp/widgets/base_layer_widget.dart'; import 'package:rogapp/widgets/bottom_sheet_widget.dart'; +import 'package:rogapp/widgets/perfecture_widget.dart'; class MapPage extends StatelessWidget { @@ -57,88 +60,110 @@ class MapPage extends StatelessWidget { ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, body: SafeArea( - child: Obx(() => - Stack( - children: [ - FlutterMap( - mapController: mapController, - options: MapOptions( - center: LatLng(37.15319600454702, 139.58765950528198), - zoom: 6, - maxZoom: 20, - plugins: [ - MarkerClusterPlugin(), - ], - onTap: (_, __) => - _popupController - .hideAllPopups(), // Hide popup when the map is tapped. - ), - children: [ - BaseLayer(), - LocationMarkerLayerWidget(), - homeController.locations.length > 0 ? - MarkerClusterLayerWidget( - options: MarkerClusterLayerOptions( - spiderfyCircleRadius: 80, - spiderfySpiralDistanceMultiplier: 2, - circleSpiralSwitchover: 12, - maxClusterRadius: 20, - rotate: true, - onMarkerTap: (marker){ - GeoJsonFeature? fs = homeController.getFeatureForLatLong(marker.point.latitude, marker.point.longitude); - print(fs); - if(fs != null){ - if(homeController.currentFeature.length > 0) { - homeController.currentFeature.clear(); - } - homeController.currentFeature.add(fs); - - showModalBottomSheet(context: context, isScrollControlled: true, - builder:((context) => BottomSheetWidget()) - ); - } - }, - - size: Size(40, 40), - anchor: AnchorPos.align(AnchorAlign.center), - fitBoundsOptions: const FitBoundsOptions( - padding: EdgeInsets.all(50), - maxZoom: 15, - ), - markers:homeController.locations[0].collection.map((i) { - GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint; - return Marker( - anchorPos: AnchorPos.align(AnchorAlign.center), - height: 70.0, - width: 70.0, - point: LatLng(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude), - builder: (ctx) => Icon(Icons.pin_drop), - ); - }).toList(), - builder: (context, markers) { - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20.0), - color: Colors.blue), - child: Center( - child: Text( - markers.length.toString(), - style: TextStyle(color: Colors.white), - ), - ), - ); - }, - ), - ): Container(height:0,width: 0), + child: Column( + children: [ + Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerLeft, + height: 50.0, + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: BreadCrumb( + items: [ + BreadCrumbItem(content: + //Text('Item1', style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),) + PerfectureWidget(), + ), + BreadCrumbItem(content: Text('Item2', style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),)), ], - ) - ], - ) + divider: Icon(Icons.chevron_right), + ), + ), + ), + Expanded( + child: Obx(() => + Stack( + children: [ + FlutterMap( + mapController: mapController, + options: MapOptions( + center: LatLng(37.15319600454702, 139.58765950528198), + zoom: 6, + maxZoom: 20, + plugins: [ + MarkerClusterPlugin(), + ], + onTap: (_, __) => + _popupController + .hideAllPopups(), // Hide popup when the map is tapped. + ), + children: [ + BaseLayer(), + LocationMarkerLayerWidget(), + homeController.locations.length > 0 ? + MarkerClusterLayerWidget( + options: MarkerClusterLayerOptions( + spiderfyCircleRadius: 80, + spiderfySpiralDistanceMultiplier: 2, + circleSpiralSwitchover: 12, + maxClusterRadius: 20, + rotate: true, + onMarkerTap: (marker){ + GeoJsonFeature? fs = homeController.getFeatureForLatLong(marker.point.latitude, marker.point.longitude); + print(fs); + if(fs != null){ + if(homeController.currentFeature.length > 0) { + homeController.currentFeature.clear(); + } + homeController.currentFeature.add(fs); + + showModalBottomSheet(context: context, isScrollControlled: true, + builder:((context) => BottomSheetWidget()) + ); + } + }, + + size: Size(40, 40), + anchor: AnchorPos.align(AnchorAlign.center), + fitBoundsOptions: const FitBoundsOptions( + padding: EdgeInsets.all(50), + maxZoom: 15, + ), + markers:homeController.locations[0].collection.map((i) { + GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint; + return Marker( + anchorPos: AnchorPos.align(AnchorAlign.center), + height: 70.0, + width: 70.0, + point: LatLng(p.geoSerie!.geoPoints[0].latitude, p.geoSerie!.geoPoints[0].longitude), + builder: (ctx) => Icon(Icons.pin_drop), + ); + }).toList(), + builder: (context, markers) { + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20.0), + color: Colors.blue), + child: Center( + child: Text( + markers.length.toString(), + style: TextStyle(color: Colors.white), + ), + ), + ); + }, + ), + ): Container(height:0,width: 0), + ], + ) + ], + ) + ), + ), + ], ), ), ); } - - } diff --git a/lib/services/location_service.dart b/lib/services/location_service.dart index 4f1be0c..debad07 100644 --- a/lib/services/location_service.dart +++ b/lib/services/location_service.dart @@ -9,7 +9,7 @@ class LocationService{ final geo = GeoJson(); GeoJsonFeatureCollection? fs; print("#### feature collection ####"); - String url = 'http://container.intranet.sumasen.net:8100/api/location/'; + String url = 'http://localhost:8100/api/location/'; final response = await http.get(Uri.parse(url), headers: { 'Content-Type': 'application/json; charset=UTF-8', diff --git a/lib/services/perfecture_service.dart b/lib/services/perfecture_service.dart new file mode 100644 index 0000000..8bf0dfa --- /dev/null +++ b/lib/services/perfecture_service.dart @@ -0,0 +1,24 @@ +import 'dart:convert'; +import 'package:http/http.dart' as http; + + +class PerfectureService{ + + static Future?> loadPerfectures() async { + List perfs = []; + String url = 'http://localhost:8100/api/perf/'; + final response = await http.get(Uri.parse(url), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + ); + + if (response.statusCode == 200) { + + perfs = json.decode(response.body); + } + return perfs; + } + +} + diff --git a/lib/widgets/bottom_sheet_widget.dart b/lib/widgets/bottom_sheet_widget.dart index eebb366..7b99b0f 100644 --- a/lib/widgets/bottom_sheet_widget.dart +++ b/lib/widgets/bottom_sheet_widget.dart @@ -22,6 +22,20 @@ class BottomSheetWidget extends StatelessWidget { if (!await launch(url)) throw 'Could not launch $url'; } + // Widget getAttrib(String name){ + // print("calling ..."); + // if(homeController.currentFeature[0].properties!["phone"] == null || homeController.currentFeature[0].properties!["phone"] == ""){ + // return Container(height: 0, width: 0,); + // } + // else { + // return Obx(() => + // Text(homeController.currentFeature[0].properties!["phone"] ?? '', + // style: TextStyle(color: Colors.blue,), + // overflow: TextOverflow.ellipsis,) + // ); + // } + // } + @override Widget build(BuildContext context) { return SingleChildScrollView( @@ -84,69 +98,116 @@ class BottomSheetWidget extends StatelessWidget { Row( children: [ Expanded( - child: Column( - children: [ - homeController.currentFeature[0].properties!["address"] != null ? - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("address".tr, style: TextStyle(fontWeight: FontWeight.bold),), - SizedBox(width: 12.0,), - Obx(() => Text(homeController.currentFeature[0].properties!["address"], - style: TextStyle(color: Colors.blue,), - )) - ], - ): Container(width: 0.0, height: 0,), - homeController.currentFeature[0].properties!["phone"] != null ? - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("telephone".tr, style: TextStyle(fontWeight: FontWeight.bold),), - SizedBox(width: 12.0,), - Obx(() => Text(homeController.currentFeature[0].properties!["phone"], - style: TextStyle(color: Colors.blue,), - )) - ], - ): Container(width: 0, height: 0,), - homeController.currentFeature[0].properties!["email"] != null ? - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("email".tr, style: TextStyle(fontWeight: FontWeight.bold),), - SizedBox(width: 12.0,), - Obx(() => Text(homeController.currentFeature[0].properties!["email"], - style: TextStyle(color: Colors.blue,), - )) - ], - ): Container(width: 0, height: 0,), - homeController.currentFeature[0].properties!["webcontents"] != null ? - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("web".tr, style: TextStyle(fontWeight: FontWeight.bold)), - SizedBox(width: 12.0,), - Obx(() => InkWell( - onTap: (){ - _launchURL(homeController.currentFeature[0].properties!["webcontents"]); - }, - child: Text(homeController.currentFeature[0].properties!["webcontents"], - style: TextStyle(color: Colors.blue,), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 24.0), + child: Column( + children: [ + homeController.currentFeature[0].properties!["address"] != null ? + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: Container( + alignment: Alignment.topRight, + child: Text("address".tr, style: TextStyle(fontWeight: FontWeight.bold),)), ), - )) - ], - ): Container(width: 0.0, height: 0.0,), - homeController.currentFeature[0].properties!["videos"] != null ? - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("video".tr, style: TextStyle(fontWeight: FontWeight.bold)), - SizedBox(width: 12.0,), - Obx(() => Text(homeController.currentFeature[0].properties!["videos"], - style: TextStyle(color: Colors.blue,), - )) - ], - ): Container(width: 0.0, height: 0.0,), - ], + SizedBox(width: 12.0,), + Expanded( + child: Container( + alignment: Alignment.topLeft, + child: Obx(() => Text(homeController.currentFeature[0].properties!["address"] ?? '', + style: TextStyle(color: Colors.blue,), + softWrap: true, + overflow: TextOverflow.ellipsis,) + ), + ), + ) + ], + ): Container(width: 0.0, height: 0,), + homeController.currentFeature[0].properties!["phone"] != null ? + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded(child: Container( + alignment: Alignment.topRight, + child: Text("telephone".tr, style: TextStyle(fontWeight: FontWeight.bold),))), + SizedBox(width: 12.0,), + Expanded( + child: Container( + alignment: Alignment.topLeft, + child: Obx(() => Text(homeController.currentFeature[0].properties!["phone"] ?? '', + style: TextStyle(color: Colors.blue,), + overflow: TextOverflow.ellipsis,) + ), + ), + ) + ], + ): Container(width: 0, height: 0,), + homeController.currentFeature[0].properties!["email"] != null ? + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded(child: Container( + alignment: Alignment.topRight, + child: Text("email".tr, style: TextStyle(fontWeight: FontWeight.bold),))), + SizedBox(width: 12.0,), + Expanded( + child: Container( + alignment: Alignment.topLeft, + child: Obx(() => Text(homeController.currentFeature[0].properties!["email"] ?? '', + style: TextStyle(color: Colors.blue,), + overflow: TextOverflow.ellipsis,) + ), + ), + ) + ], + ): Container(width: 0, height: 0,), + homeController.currentFeature[0].properties!["webcontents"] != null ? + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded(child: Container( + alignment: Alignment.topRight, + child: Text( + "web".tr, style: TextStyle(fontWeight: FontWeight.bold)))), + SizedBox(width: 12.0,), + Expanded( + child: Container( + alignment: Alignment.topLeft, + child: Obx(() => InkWell( + onTap: (){ + _launchURL(homeController.currentFeature[0].properties!["webcontents"]); + }, + child: Text(homeController.currentFeature[0].properties!["webcontents"] ?? '', + style: TextStyle(color: Colors.blue,), + softWrap: false, + overflow: TextOverflow.fade,), + )), + ), + ) + ], + ): Container(width: 0.0, height: 0.0,), + homeController.currentFeature[0].properties!["videos"] != null ? + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded(child: Container( + alignment: Alignment.topRight, + child: Text("video".tr, style: TextStyle(fontWeight: FontWeight.bold)))), + SizedBox(width: 12.0,), + Expanded( + child: Container( + alignment: Alignment.topLeft, + child: Obx(() => Text(homeController.currentFeature[0].properties!["videos"] ?? '', + style: TextStyle(color: Colors.blue,), + overflow: TextOverflow.ellipsis,) + ), + ), + ) + ], + ): Container(width: 0.0, height: 0.0,), + ], + ), ), ), ], diff --git a/lib/widgets/perfecture_widget.dart b/lib/widgets/perfecture_widget.dart new file mode 100644 index 0000000..68bd466 --- /dev/null +++ b/lib/widgets/perfecture_widget.dart @@ -0,0 +1,59 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:rogapp/pages/home/home_controller.dart'; + + + +class PerfectureWidget extends StatefulWidget { + PerfectureWidget({Key? key}) : super(key: key); + + final HomeController homeController = Get.find(); + + @override + State createState() => _PerfectureWidgetState(); +} + +class _PerfectureWidgetState extends State { + String dropdownValue = 'One'; + + + + List> getDropdownItems() { + List> dropDownItems = []; + + print("---------"); + print(widget.homeController.perfectures); + + for (List currency in widget.homeController.perfectures[0]) { + var newDropdown = DropdownMenuItem( + child: Text("dddd"), + value: "qqqq", + ); + + dropDownItems.add(newDropdown); + } + return dropDownItems; + } + + + + @override + Widget build(BuildContext context) { + return DropdownButton( + value: dropdownValue, + icon: const Icon(Icons.arrow_downward), + elevation: 16, + style: const TextStyle(color: Colors.deepPurple), + underline: Container( + height: 2, + color: Colors.deepPurpleAccent, + ), + onChanged: (String? newValue) { + setState(() { + dropdownValue = newValue!; + }); + }, + items:getDropdownItems()); + } +} +