This commit is contained in:
Mohamed Nouffer
2022-04-17 11:45:21 +05:30
parent ee3845681d
commit e6cf730ae2
30 changed files with 1260 additions and 534 deletions

View File

@ -1,12 +0,0 @@
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_instance/src/bindings_interface.dart';
import 'package:get/get_instance/src/extension_instance.dart';
import 'package:rogapp/pages/home/home_controller.dart';
class HomeBinding extends Bindings {
@override
void dependencies() {
Get.put<HomeController>(HomeController());
}
}

View File

@ -0,0 +1,13 @@
// import 'package:flutter_map/flutter_map.dart';
// import 'package:get/get_core/src/get_main.dart';
// import 'package:get/get_instance/src/bindings_interface.dart';
// import 'package:get/get_instance/src/extension_instance.dart';
// import 'package:rogapp/pages/home/home_controller.dart';
// class HomeBinding extends Bindings {
// @override
// void dependencies() {
// Get.put<HomeController>(HomeController());
// }
// }

View File

@ -1,155 +0,0 @@
import 'package:flutter_map/plugin_api.dart';
import 'package:geojson/geojson.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/pages/map/map_page.dart';
import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/services/perfecture_service.dart';
class HomeController extends GetxController {
List<GeoJsonFeatureCollection> locations = <GeoJsonFeatureCollection>[].obs;
List<GeoJsonFeature> currentFeature = <GeoJsonFeature>[].obs;
List<dynamic> perfectures = <dynamic>[].obs;
List<LatLngBounds> currentBound = <LatLngBounds>[].obs;
List<dynamic> subPerfs = <dynamic>[].obs;
@override
void onInit() {
LocationService.loadLocations().then((value){
locations.add(value!);
});
PerfectureService.loadPerfectures().then((value){
perfectures.add(value);
});
super.onInit();
}
void getBoundFromLatLng(List<LatLng> list) {
double? x0, x1, y0, y1;
for (LatLng latLng in list) {
if (x0 == null) {
x0 = x1 = latLng.latitude;
y0 = y1 = latLng.longitude;
} else {
if (latLng.latitude > x1!) x1 = latLng.latitude;
if (latLng.latitude < x0) x0 = latLng.latitude;
if (latLng.longitude > y1!) y1 = latLng.longitude;
if (latLng.longitude < y0!) y0 = latLng.longitude;
}
}
currentBound.clear();
currentBound.add(LatLngBounds(LatLng(x1!, y1!), LatLng(x0!, y0!)));
}
void setBounds(){
List<LatLng> lts = [];
if(locations.length > 0){
for(GeoJsonFeature i in locations[0].collection){
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
LatLng lt = LatLng(p.geoSerie!.geoPoints[0].latitude , p.geoSerie!.geoPoints[0].longitude) ;
lts.add(lt);
}
}
else{
LatLng lt = LatLng(37.15319600454702, 139.58765950528198);
lts.add(lt);
}
getBoundFromLatLng(lts);
}
void loadLocationforPerf(String perf){
locations.clear();
LocationService.loadLocationsFor(perf).then((value){
locations.add(value!);
setBounds();
MapPage.mapController.fitBounds(currentBound[0]);
});
}
String getSubInitialVal(){
int min = 0;
if(subPerfs.length > 0){
min = subPerfs[0][0]['id'] as int;
for(var sub in subPerfs[0]){
int x = sub['id'] as int;
if(x < min){
min = x;
}
}
}
return min.toString();
}
void loadSubPerfFor(String perf){
subPerfs.clear();
PerfectureService.loadSubPerfectures(perf).then((value){
subPerfs.add(value);
print(subPerfs);
});
}
GeoJsonFeature? getFeatureForLatLong(double lat, double long){
if(locations.length > 0){
for(GeoJsonFeature i in locations[0].collection){
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
if(p.geoSerie!.geoPoints[0].latitude == lat && p.geoSerie!.geoPoints[0].longitude == long){
return i;
}
}
}
}
void makeNext(GeoJsonFeature fs){
GeoJsonFeature<GeoJsonMultiPoint> pt = fs as GeoJsonFeature<GeoJsonMultiPoint>;
for(int i=0; i<= locations[0].collection.length - 1; i++){
GeoJsonMultiPoint p = locations[0].collection[i].geometry as GeoJsonMultiPoint;
if(p.geoSerie!.geoPoints[0].latitude == pt.geometry!.geoSerie!.geoPoints[0].latitude && p.geoSerie!.geoPoints[0].longitude == pt.geometry!.geoSerie!.geoPoints[0].longitude ){
if(currentFeature.length > 0){
currentFeature.clear();
}
if(i >= locations[0].collection.length - 1 ){
currentFeature.add(locations[0].collection[0] as GeoJsonFeature);
}
else{
currentFeature.add(locations[0].collection[i + 1] as GeoJsonFeature);
}
}
}
}
void makePrevious(GeoJsonFeature fs){
GeoJsonFeature<GeoJsonMultiPoint> pt = fs as GeoJsonFeature<GeoJsonMultiPoint>;
for(int i=0; i<= locations[0].collection.length - 1; i++){
GeoJsonMultiPoint p = locations[0].collection[i].geometry as GeoJsonMultiPoint;
if(p.geoSerie!.geoPoints[0].latitude == pt.geometry!.geoSerie!.geoPoints[0].latitude && p.geoSerie!.geoPoints[0].longitude == pt.geometry!.geoSerie!.geoPoints[0].longitude ){
if(currentFeature.length > 0){
currentFeature.clear();
}
if(i == 0 ){
currentFeature.add(locations[0].collection[locations[0].collection.length -1] as GeoJsonFeature);
}
else{
currentFeature.add(locations[0].collection[i - 1] as GeoJsonFeature);
}
}
}
}
}

View File

@ -0,0 +1,199 @@
// import 'package:flutter_map/plugin_api.dart';
// import 'package:geojson/geojson.dart';
// import 'package:get/get.dart';
// import 'package:latlong2/latlong.dart';
// import 'package:meta/meta.dart';
// import 'package:rogapp/pages/map/map_page.dart';
// import 'package:rogapp/services/location_service.dart';
// import 'package:rogapp/services/perfecture_service.dart';
// class HomeController extends GetxController {
// List<GeoJsonFeatureCollection> locations = <GeoJsonFeatureCollection>[].obs;
// List<GeoJsonFeature> currentFeature = <GeoJsonFeature>[].obs;
// List<dynamic> perfectures = <dynamic>[].obs;
// List<LatLngBounds> currentBound = <LatLngBounds>[].obs;
// List<dynamic> subPerfs = <dynamic>[].obs;
// String SubDropdownValue = "-1";
// @override
// void onInit() {
// super.onInit();
// if(locations.length == 0){
// LocationService.loadLocations().then((value){
// locations.add(value!);
// //print(value);
// });
// }
// if(perfectures.length == 0){
// PerfectureService.loadPerfectures().then((value){
// perfectures.add(value);
// loadSubPerfFor("9");
// });
// }
// }
// void getBoundFromLatLng(List<LatLng> list) {
// double? x0, x1, y0, y1;
// for (LatLng latLng in list) {
// if (x0 == null) {
// x0 = x1 = latLng.latitude;
// y0 = y1 = latLng.longitude;
// } else {
// if (latLng.latitude > x1!) x1 = latLng.latitude;
// if (latLng.latitude < x0) x0 = latLng.latitude;
// if (latLng.longitude > y1!) y1 = latLng.longitude;
// if (latLng.longitude < y0!) y0 = latLng.longitude;
// }
// }
// currentBound.clear();
// if(x0 != null && x1 != null && y0 != null && y1 != null ){
// currentBound.add(LatLngBounds(LatLng(x1, y1), LatLng(x0, y0)));
// }
// }
// void setBounds(){
// List<LatLng> lts = [];
// if(locations.length > 0){
// for(GeoJsonFeature i in locations[0].collection){
// GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
// LatLng lt = LatLng(p.geoSerie!.geoPoints[0].latitude , p.geoSerie!.geoPoints[0].longitude) ;
// lts.add(lt);
// }
// }
// else{
// LatLng lt = LatLng(37.15319600454702, 139.58765950528198);
// lts.add(lt);
// }
// getBoundFromLatLng(lts);
// }
// void zoomtoMainPerf(String id, MapController mapController){
// PerfectureService.getMainPerfExt(id).then((value){
// print(value);
// LatLng lat1 = LatLng(value![1], value[0]);
// LatLng lat2 = LatLng(value[3], value[2]);
// LatLngBounds bound = LatLngBounds(lat1, lat2);
// mapController.fitBounds(bound);
// });
// }
// void zoomtoSubPerf(String id, MapController mapController){
// PerfectureService.getSubExt(id).then((value){
// LatLng lat1 = LatLng(value![1], value[0]);
// LatLng lat2 = LatLng(value[3], value[2]);
// LatLngBounds bound = LatLngBounds(lat1, lat2);
// mapController.fitBounds(bound);
// });
// }
// void loadLocationforPerf(String perf, MapController mapController) async {
// locations.clear();
// LocationService.loadLocationsFor(perf).then((value){
// locations.add(value!);
// setBounds();
// mapController.fitBounds(currentBound[0]);
// });
// }
// void loadLocationforSubPerf(String subperf, MapController mapController) async {
// locations.clear();
// LocationService.loadLocationsSubFor(subperf).then((value){
// locations.add(value!);
// //setBounds();
// //mapController!.fitBounds(currentBound[0]);
// });
// }
// void loadSubPerfFor(String perf){
// subPerfs.clear();
// dynamic initVal = {'id':'-1', 'adm2_ja':'----'};
// PerfectureService.loadSubPerfectures(perf).then((value){
// value!.add(initVal);
// subPerfs.add(value);
// SubDropdownValue = getSubInitialVal();
// //print(subPerfs[0]);
// });
// }
// String getSubInitialVal(){
// int min = 0;
// if(subPerfs.length > 0){
// min = subPerfs[0][0]['id'] as int;
// for(var sub in subPerfs[0]){
// int x = int.parse(sub['id'].toString()); // as int;
// if(x < min){
// min = x;
// }
// }
// }
// return min.toString();
// }
// GeoJsonFeature? getFeatureForLatLong(double lat, double long){
// if(locations.length > 0){
// for(GeoJsonFeature i in locations[0].collection){
// GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
// if(p.geoSerie!.geoPoints[0].latitude == lat && p.geoSerie!.geoPoints[0].longitude == long){
// return i;
// }
// }
// }
// }
// void makeNext(GeoJsonFeature fs){
// GeoJsonFeature<GeoJsonMultiPoint> pt = fs as GeoJsonFeature<GeoJsonMultiPoint>;
// for(int i=0; i<= locations[0].collection.length - 1; i++){
// GeoJsonMultiPoint p = locations[0].collection[i].geometry as GeoJsonMultiPoint;
// if(p.geoSerie!.geoPoints[0].latitude == pt.geometry!.geoSerie!.geoPoints[0].latitude && p.geoSerie!.geoPoints[0].longitude == pt.geometry!.geoSerie!.geoPoints[0].longitude ){
// if(currentFeature.length > 0){
// currentFeature.clear();
// }
// if(i >= locations[0].collection.length - 1 ){
// currentFeature.add(locations[0].collection[0] as GeoJsonFeature);
// }
// else{
// currentFeature.add(locations[0].collection[i + 1] as GeoJsonFeature);
// }
// }
// }
// }
// void makePrevious(GeoJsonFeature fs){
// GeoJsonFeature<GeoJsonMultiPoint> pt = fs as GeoJsonFeature<GeoJsonMultiPoint>;
// for(int i=0; i<= locations[0].collection.length - 1; i++){
// GeoJsonMultiPoint p = locations[0].collection[i].geometry as GeoJsonMultiPoint;
// if(p.geoSerie!.geoPoints[0].latitude == pt.geometry!.geoSerie!.geoPoints[0].latitude && p.geoSerie!.geoPoints[0].longitude == pt.geometry!.geoSerie!.geoPoints[0].longitude ){
// if(currentFeature.length > 0){
// currentFeature.clear();
// }
// if(i == 0 ){
// currentFeature.add(locations[0].collection[locations[0].collection.length -1] as GeoJsonFeature);
// }
// else{
// currentFeature.add(locations[0].collection[i - 1] as GeoJsonFeature);
// }
// }
// }
// }
// }

View File

@ -1,122 +0,0 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:geojson/geojson.dart';
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';
class HomePage extends GetView<HomeController> {
final HomeController homeController = Get.find<HomeController>();
void changeCurrentFeature(GeoJsonFeature fs){
if(homeController.currentFeature.length > 0){
homeController.currentFeature.clear();
}
homeController.currentFeature.add(fs);
}
Image getImage(int index){
if(homeController.locations[0].collection[index].properties!["photos"] == null || homeController.locations[0].collection[index].properties!["photos"] == ""){
return Image(image: AssetImage('assets/images/empty_image.png'));
}
else{
return Image(image: NetworkImage(homeController.locations[0].collection[index].properties!["photos"]));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: DrawerPage(),
appBar: AppBar(
title: Text("app_title".tr),
centerTitle: true,
actions: [
IconButton(
icon: const Icon(Icons.map),
onPressed: (){
//print(homeController.locations.length);
},
)
],
),
floatingActionButton: new FloatingActionButton(
onPressed: (){
Get.toNamed(AppPages.MAP);
},
tooltip: 'Increment',
child: new Icon(Icons.document_scanner),
elevation: 4.0,
),
bottomNavigationBar: BottomAppBar(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(child: IconButton(icon: Icon(Icons.camera_enhance), onPressed: (){},),),
Expanded(child: new Text('')),
Expanded(child: IconButton(icon: Icon(Icons.travel_explore), onPressed: (){}),),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
body:Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Container(
alignment: Alignment.centerLeft,
height: 50.0,
child: BreadCrumb(
items: <BreadCrumbItem>[
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),
),
),
),
Expanded(
child: Obx(() =>
homeController.locations.length > 0 ?
ListView.builder(
itemCount: homeController.locations[0].collection.length,
shrinkWrap: true,
itemBuilder: (_, index){
return Card(
child: ListTile(
onTap: (){
GeoJsonFeature gf = homeController.locations[0].collection[index];
changeCurrentFeature(gf);
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) => BottomSheetWidget(),
);
},
leading: getImage(index),
title: Text(homeController.locations[0].collection[index].properties!['location_name'].toString()),
subtitle: Text(homeController.locations[0].collection[index].properties!['category']),
),
);
},
) : Container(width: 0, height: 0,),
)
)
],
)
);
}
}

View File

@ -0,0 +1,129 @@
// import 'dart:ui';
// import 'package:flutter/material.dart';
// import 'package:flutter_map/plugin_api.dart';
// import 'package:geojson/geojson.dart';
// 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';
// import 'package:rogapp/widgets/perfecture_widget.dart';
// class HomePage extends GetView<HomeController> {
// final HomeController homeController = Get.find<HomeController>();
// MapController mapController = Get.arguments[0];
// void changeCurrentFeature(GeoJsonFeature fs){
// if(homeController.currentFeature.length > 0){
// homeController.currentFeature.clear();
// }
// homeController.currentFeature.add(fs);
// }
// Image getImage(int index){
// if(homeController.locations[0].collection[index].properties!["photos"] == null || homeController.locations[0].collection[index].properties!["photos"] == ""){
// return Image(image: AssetImage('assets/images/empty_image.png'));
// }
// else{
// return Image(image: NetworkImage(homeController.locations[0].collection[index].properties!["photos"]));
// }
// }
// Widget getBreadCurms(){
// return Obx(() =>
// homeController.perfectures.length > 0 ?
// BreadCrumb.builder(
// itemCount: homeController.perfectures.length,
// builder: (index) {
// return BreadCrumbItem(
// content: PerfectureWidget(homeController: homeController, mapController: mapController) //Text('Item$index')
// );
// },
// divider: Icon(Icons.chevron_right),
// ) :
// Container(width: 0, height: 0,),
// );
// }
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// drawer: DrawerPage(),
// appBar: AppBar(
// title: Text("app_title".tr),
// centerTitle: true,
// actions: [
// IconButton(
// icon: const Icon(Icons.map),
// onPressed: (){
// //print(homeController.locations.length);
// },
// )
// ],
// ),
// floatingActionButton: new FloatingActionButton(
// onPressed: (){
// Get.toNamed(AppPages.MAP);
// },
// tooltip: 'Increment',
// child: new Icon(Icons.document_scanner),
// elevation: 4.0,
// ),
// bottomNavigationBar: BottomAppBar(
// child: new Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// Expanded(child: IconButton(icon: Icon(Icons.camera_enhance), onPressed: (){},),),
// Expanded(child: new Text('')),
// Expanded(child: IconButton(icon: Icon(Icons.travel_explore), onPressed: (){}),),
// ],
// ),
// ),
// floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
// body:Column(
// children: [
// Padding(
// padding: const EdgeInsets.symmetric(horizontal: 8.0),
// child: Container(
// alignment: Alignment.centerLeft,
// height: 50.0,
// child: getBreadCurms(),
// ),
// ),
// Expanded(
// child: Obx(() =>
// homeController.locations.length > 0 ?
// ListView.builder(
// itemCount: homeController.locations[0].collection.length,
// shrinkWrap: true,
// itemBuilder: (_, index){
// return Card(
// child: ListTile(
// onTap: (){
// GeoJsonFeature gf = homeController.locations[0].collection[index];
// changeCurrentFeature(gf);
// showModalBottomSheet(
// isScrollControlled: true,
// context: context,
// builder: (context) => BottomSheetWidget(),
// );
// },
// leading: getImage(index),
// title: Text(homeController.locations[0].collection[index].properties!['location_name'].toString()),
// subtitle: Text(homeController.locations[0].collection[index].properties!['category']),
// ),
// );
// },
// ) : Container(width: 0, height: 0,),
// )
// )
// ],
// )
// );
// }
// }