This commit is contained in:
Mohamed Nouffer
2022-05-18 19:09:26 +05:30
parent 80a976baa0
commit ee0440e6b6
26 changed files with 411 additions and 59 deletions

View File

@ -5,11 +5,13 @@ import 'package:get/get.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/destination_service.dart';
import 'package:rogapp/services/maxtrix_service.dart';
class DestinationController extends GetxController {
List<dynamic> destinations = <dynamic>[].obs;
Map<String, dynamic> matrix = {};
final IndexController indexController = Get.find<IndexController>();
@ -24,8 +26,16 @@ class DestinationController extends GetxController {
int user_id = indexController.currentUser[0]["user"]["id"] as int;
//print(user_id);
DestinationService.getDestinations(user_id).then((value){
destinations.clear();
destinations = value;
MatrixService.getDestinations(value).then((mat){
print(mat);
matrix = mat;
destinations.clear();
destinations = value;
});
//var val = value[2]["location"]["id"];
//print("-----current destinations ----- ${val}");
});

View File

@ -110,8 +110,8 @@ class _DestinationPageState extends State<DestinationPage> {
startChild: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text("12:30"),
Text("01:20"),
Text(destinationController.matrix["rows"][0]["elements"][index]["distance"]["text"].toString()),
Text(destinationController.matrix["rows"][0]["elements"][index]["duration"]["text"].toString())
],
),
);

View File

@ -1,5 +1,8 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:geojson/geojson.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
@ -22,7 +25,6 @@ class IndexController extends GetxController {
List<Map<String, dynamic>> currentUser = <Map<String, dynamic>>[].obs;
List<dynamic> currentAction = <dynamic>[].obs;
var is_loading = false.obs;
@ -47,20 +49,19 @@ class IndexController extends GetxController {
void onInit() {
super.onInit();
if(locations.length == 0){
LocationService.loadLocations().then((value){
locations.add(value!);
//print(value);
});
}
// 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");
});
}
loadCats();
}
//loadCats();
}
void login(String email, String password, BuildContext context){
@ -112,25 +113,51 @@ class IndexController extends GetxController {
}
void loadCats(){
// void loadCats(){
// dynamic initVal = {'category':'---'};
// CatService.loadCats().then((value) {
// //value!.add(initVal);
// print("###########");
// print(value);
// cats.add(value);
// });
// }
void loadCatsv2(){
dynamic initVal = {'category':'---'};
CatService.loadCats().then((value) {
//value!.add(initVal);
print("###########");
print(value);
cats.add(value);
});
LatLngBounds bounds = mapController!.bounds!;
if(bounds.southEast != null && bounds.southWest != null && bounds.northEast != null && bounds.southEast != null ){
cats.clear();
CatService.loadCats(bounds.southWest!.latitude, bounds.southWest!.longitude, bounds.northWest.latitude, bounds.northWest.longitude, bounds.northEast!.latitude, bounds.northEast!.longitude, bounds.southEast.latitude, bounds.southEast.longitude).then((value) {
print("###########");
print(value);
cats.add(value);
});
}
}
void refreshLocationForCat(){
if(subDropdownValue == "-1"){
LocationService.loadLocationsFor(dropdownValue, currentCat[0]);
print("loading main------");
}
else{
LocationService.loadLocationsSubFor(subDropdownValue, currentCat[0]);
print("loading sub------");
}
loadLocationsBound();
// if(subDropdownValue == "-1"){
// LocationService.loadLocationsFor(dropdownValue, currentCat[0]).then((value){
// locations.clear();
// locations.add(value!);
// is_loading.value = false;
// });
// print("loading main------");
// }
// else{
// LocationService.loadLocationsSubFor(subDropdownValue, currentCat[0]).then((value){
// locations.clear();
// locations.add(value!);
// is_loading.value = false;
// });
// print("loading sub------");
// }
}
void loadSubPerfFor(String perf){
@ -158,18 +185,48 @@ class IndexController extends GetxController {
}
void loadLocationforPerf(String perf, MapController mapController) async {
String cat = currentCat.isNotEmpty == true ? currentCat[0] : "";
print(currentCat);
// LocationService.loadLocationsFor(perf, cat).then((value){
// locations.clear();
// locations.add(value!);
// mapController.fitBounds(currentBound[0]);
// });
locations.clear();
LocationService.loadLocationsFor(perf, currentCat[0]).then((value){
mapController.fitBounds(currentBound[0]);
}
void loadLocationforSubPerf(String subperf, MapController mapController) async {
String cat = currentCat.isNotEmpty == true ? currentCat[0] : "";
print(currentCat);
LocationService.loadLocationsSubFor(subperf, cat).then((value){
locations.clear();
locations.add(value!);
mapController.fitBounds(currentBound[0]);
});
}
void loadLocationforSubPerf(String subperf, MapController mapController) async {
locations.clear();
LocationService.loadLocationsSubFor(subperf, currentCat[0]).then((value){
locations.add(value!);
});
void loadLocationsBound(){
String cat = currentCat.isNotEmpty ? currentCat[0] : "";
LatLngBounds bounds = mapController!.bounds!;
print(currentCat);
if(bounds.southEast != null && bounds.southWest != null && bounds.northEast != null && bounds.southEast != null ){
LocationService.loadLocationsBound(bounds.southWest!.latitude, bounds.southWest!.longitude, bounds.northWest.latitude, bounds.northWest.longitude, bounds.northEast!.latitude, bounds.northEast!.longitude, bounds.southEast.latitude, bounds.southEast.longitude, cat).then((value){
print("---value length ------ ${value!.collection.length}");
if(value == null){
return;
}
if(value != null && value.collection.isEmpty){
Get.showSnackbar(GetSnackBar(message: "Too many points, please zoom in",));
}
if(value != null && value.collection.isNotEmpty){
print("---- added---");
locations.clear();
locations.add(value);
loadCatsv2();
}
});
}
}
void setBound(LatLngBounds bounds){
@ -206,12 +263,14 @@ class IndexController extends GetxController {
loadSubPerfFor(perf);
loadLocationforPerf(perf, mapController);
zoomtoMainPerf(perf);
is_loading.value = false;
}
void populateForSubPerf(String subperf, MapController mapController){
subDropdownValue = subperf;
loadLocationforSubPerf(subperf, mapController);
zoomtoSubPerf(subperf);
is_loading.value = false;
}

View File

@ -5,6 +5,7 @@ import 'package:get/get.dart';
import 'package:rogapp/pages/drawer/drawer_page.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/maxtrix_service.dart';
import 'package:rogapp/widgets/bread_crum_widget.dart';
import 'package:rogapp/widgets/cat_widget.dart';
import 'package:rogapp/widgets/list_widget.dart';
@ -72,7 +73,20 @@ class IndexPage extends GetView<IndexController> {
BreadCrumbWidget(),
Container(width: 24.0,),
Obx(()=>
indexController.currentCat.isNotEmpty ? Text(indexController.currentCat[0].toString()): Text("")
Row(
children: [
indexController.currentCat.isNotEmpty ? Text(indexController.currentCat[0].toString()): Text(""),
indexController.currentCat.isNotEmpty ?
IconButton(
onPressed: (){
indexController.currentCat.clear();
indexController.loadLocationsBound();
},
icon: Icon(Icons.cancel, color: Colors.red,)
) :
Container(width: 0, height: 0,)
],
)
),
],
),

View File

@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
class LoadingPage extends StatelessWidget {
const LoadingPage({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.topCenter,
margin: EdgeInsets.only(top: 20),
child: CircularProgressIndicator(
value: 0.8,
)
);
}
}