update initial map loading

This commit is contained in:
Mohamed Nouffer
2022-12-27 18:52:37 +05:30
parent c1f7656044
commit f8a79842e3
5 changed files with 310 additions and 25 deletions

View File

@ -6,6 +6,7 @@ import 'dart:io';
import 'package:camera_camera/camera_camera.dart'; import 'package:camera_camera/camera_camera.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:geojson/geojson.dart'; import 'package:geojson/geojson.dart';
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@ -19,7 +20,10 @@ import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/action_service.dart'; import 'package:rogapp/services/action_service.dart';
import 'package:rogapp/services/destination_service.dart'; import 'package:rogapp/services/destination_service.dart';
import 'package:rogapp/services/external_service.dart'; import 'package:rogapp/services/external_service.dart';
import 'package:rogapp/services/location_line_service.dart';
import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/services/maxtrix_service.dart'; import 'package:rogapp/services/maxtrix_service.dart';
import 'package:rogapp/services/perfecture_service.dart';
import 'package:rogapp/services/reacking_service.dart'; import 'package:rogapp/services/reacking_service.dart';
import 'package:rogapp/utils/database_helper.dart'; import 'package:rogapp/utils/database_helper.dart';
import 'package:rogapp/widgets/bottom_sheet_new.dart'; import 'package:rogapp/widgets/bottom_sheet_new.dart';
@ -434,6 +438,7 @@ class DestinationController extends GetxController {
@override @override
void onInit() async { void onInit() async {
checkPermission(); checkPermission();
PopulateDestinations(); PopulateDestinations();
@ -505,6 +510,33 @@ class DestinationController extends GetxController {
} }
@override
void onReady() {
Get.toNamed(AppPages.LOGIN)!.then((value){
if(indexController.currentUser.length > 0) {
Get.toNamed(AppPages.INITIAL);
LocationService.getLocationsExt().then((value) {
if(value != null){
print("--- loc ext is - ${value} ----");
LatLngBounds bnds = LatLngBounds(LatLng(value[1], value[0]), LatLng(value[3], value[2]));
print("--- bnds is - ${bnds} ----");
indexController.mapController!.fitBounds(bnds); //.centerZoomFitBounds(bnds);
}
});
}
else {
Get.toNamed(AppPages.TRAVEL);
PerfectureService.getSubExt("9").then((value){
if(value != null){
LatLngBounds bnds = LatLngBounds(LatLng(value[1], value[0]), LatLng(value[3], value[2]));
indexController.mapController!.fitBounds(bnds); //.centerZoomFitBounds(bnds);
}
});
}
});
super.onReady();
}
void connectionChanged(String val) { void connectionChanged(String val) {
print('----- %%%%%%%%%%%%%%%%%%%%% ----- ${val}'); print('----- %%%%%%%%%%%%%%%%%%%%% ----- ${val}');
Map<String, dynamic> _res = {}; Map<String, dynamic> _res = {};

View File

@ -119,7 +119,6 @@ class IndexController extends GetxController {
@override @override
void onInit() { void onInit() {
_ever = ever(rog_mode, (_) => print("$_ has been changed (ever)")); _ever = ever(rog_mode, (_) => print("$_ has been changed (ever)"));
if(perfectures.length == 0){ if(perfectures.length == 0){
@ -194,23 +193,31 @@ void login(String email, String password, BuildContext context){
AuthService.login(email, password).then((value){ AuthService.login(email, password).then((value){
print("------- logged in user details ######## ${value} ###### --------"); print("------- logged in user details ######## ${value} ###### --------");
if(value.isNotEmpty){ if(value.isNotEmpty){
currentUser.clear(); currentUser.clear();
currentUser.add(value); currentUser.add(value);
is_loading.value = false; is_loading.value = false;
Navigator.pop(context); Navigator.pop(context);
loadUserDetails(); loadUserDetails();
loadLocationsBound(); loadLocationsBound();
cats.clear(); cats.clear();
if(currentFeature.isNotEmpty){ if(currentFeature.isNotEmpty){
getAction(); getAction();
} }
if(rog_mode.value == 1){
switchPage(AppPages.TRAVEL); if(currentUser.length > 0){
} rog_mode.value = 0 ;
else{ }
switchPage(AppPages.INITIAL); else{
} rog_mode.value = 1;
//Get.toNamed(AppPages.INITIAL); }
if(rog_mode.value == 1){
switchPage(AppPages.TRAVEL);
}
else{
switchPage(AppPages.INITIAL);
}
//Get.toNamed(AppPages.INITIAL);
}else{ }else{
is_loading.value = false; is_loading.value = false;
Get.snackbar( Get.snackbar(
@ -390,9 +397,11 @@ void login(String email, String password, BuildContext context){
int user_id = currentUser[0]["user"]["id"] as int; int user_id = currentUser[0]["user"]["id"] as int;
AuthService.UserDetails(user_id).then((value){ AuthService.UserDetails(user_id).then((value){
print("--------- user details ----- ${value}"); print("--------- user details ----- ${value}");
bool paid = value![0]["paid"] as bool; if(value != null && value.isNotEmpty){
if(paid){ bool paid = value![0]["paid"] as bool;
loadCustomAreas(); if(paid){
loadCustomAreas();
}
} }
}); });
} }

View File

@ -81,7 +81,7 @@ class LoginPage extends StatelessWidget {
children: [ children: [
MaterialButton( MaterialButton(
minWidth: double.infinity, minWidth: double.infinity,
height:60, height:40,
onPressed: (){ onPressed: (){
if(emailController.text.isEmpty || passwordController.text.isEmpty){ if(emailController.text.isEmpty || passwordController.text.isEmpty){
Get.snackbar( Get.snackbar(
@ -107,10 +107,10 @@ class LoginPage extends StatelessWidget {
), ),
), ),
), ),
SizedBox(height: 10.0,), SizedBox(height: 19.0,),
MaterialButton( MaterialButton(
minWidth: double.infinity, minWidth: double.infinity,
height:60, height:40,
onPressed: (){ onPressed: (){
Get.toNamed(AppPages.REGISTER); Get.toNamed(AppPages.REGISTER);
}, },
@ -122,7 +122,23 @@ class LoginPage extends StatelessWidget {
fontWeight: FontWeight.w600,fontSize: 16,color: Colors.white70 fontWeight: FontWeight.w600,fontSize: 16,color: Colors.white70
), ),
), ),
) ),
SizedBox(height: 19.0,),
MaterialButton(
minWidth: double.infinity,
height:40,
onPressed: (){
Get.back();
},
color: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40)
),
child: Text("cancel".tr,style: TextStyle(
fontWeight: FontWeight.w600,fontSize: 16,color: Colors.white70
),
),
),
], ],
) )
), ),

View File

@ -0,0 +1,210 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
class LoginPopupPage extends StatelessWidget {
LoginPopupPage({Key? key}) : super(key: key);
final IndexController indexController = Get.find<IndexController>();
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0,
brightness: Brightness.light,
backgroundColor: Colors.white,
leading:
IconButton( onPressed: (){
Navigator.pop(context);
},icon:Icon(Icons.arrow_back_ios,size: 20,color: Colors.black,)),
),
body:
indexController.currentUser.length == 0 ?
Container(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(
children: [
Column(
children: [
Container(
height: MediaQuery.of(context).size.height/5,
decoration: BoxDecoration(
image:DecorationImage(image: AssetImage('assets/images/login_image.jpg'))
),
),
SizedBox(height: 5,),
],
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: 40
),
child: Column(
children: [
makeInput(label: "email".tr, controller: emailController),
makeInput(label: "password".tr, controller: passwordController, obsureText: true),
],
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Container(
padding: EdgeInsets.only(top: 3,left: 3),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
),
child: Obx((() =>
indexController.is_loading == true ? MaterialButton(
minWidth: double.infinity,
height:60,
onPressed: (){
},
color: Colors.grey[400],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40)
),
child: CircularProgressIndicator(),
) :
Column(
children: [
MaterialButton(
minWidth: double.infinity,
height:60,
onPressed: (){
if(emailController.text.isEmpty || passwordController.text.isEmpty){
Get.snackbar(
"no_values".tr,
"email_and_password_required".tr,
icon: Icon(Icons.assistant_photo_outlined, size: 40.0, color: Colors.blue),
snackPosition: SnackPosition.TOP,
duration: Duration(milliseconds: 800),
backgroundColor: Colors.yellow,
//icon:Image(image:AssetImage("assets/images/dora.png"))
);
return;
}
indexController.is_loading.value = true;
indexController.login(emailController.text, passwordController.text, context);
},
color: Colors.indigoAccent[400],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40)
),
child: Text("ログイン",style: TextStyle(
fontWeight: FontWeight.w600,fontSize: 16,color: Colors.white70
),
),
),
SizedBox(height: 19.0,),
MaterialButton(
minWidth: double.infinity,
height:50,
onPressed: (){
Get.toNamed(AppPages.REGISTER);
},
color: Colors.redAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40)
),
child: Text("sign_up".tr,style: TextStyle(
fontWeight: FontWeight.w600,fontSize: 16,color: Colors.white70
),
),
),
SizedBox(height: 19.0,),
MaterialButton(
minWidth: double.infinity,
height:50,
onPressed: (){
Get.toNamed(AppPages.TRAVEL);
},
color: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40)
),
child: Text("cancel".tr,style: TextStyle(
fontWeight: FontWeight.w600,fontSize: 16,color: Colors.white70
),
),
)
],
)
),
),
)
),
SizedBox(height: 20,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("rogaining_user_need_tosign_up".tr, style: TextStyle(
overflow: TextOverflow.ellipsis,
),),
),
),
],
)
],
),
],
),
):
Container(
child: TextButton(
onPressed: (){
indexController.currentUser.clear();
},
child: Text("Already Logged in, Click to logout"),
),
)
,
);
}
}
Widget makeInput({label, required TextEditingController controller, obsureText = false}){
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label,style:TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
color: Colors.black87
),),
SizedBox(height: 5,),
TextField(
controller: controller,
obscureText: obsureText,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 0,horizontal: 10),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: (Colors.grey[400])!,
),
),
border: OutlineInputBorder(
borderSide: BorderSide(color: (Colors.grey[400])!
),
),
),
),
SizedBox(height: 30.0,)
],
);
}

View File

@ -76,6 +76,24 @@ class LocationService{
return null; return null;
} }
static Future<List<dynamic>?> getLocationsExt() async {
List<dynamic> ext = [];
String server_url = ConstValues.currentServer();
String url = '${server_url}/api/locsext/';
//String url = 'http://localhost:8100/api/perfext/?sub_perf=' + id;
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 200) {
ext = json.decode(utf8.decode(response.bodyBytes));
}
return ext;
}
static Future<GeoJsonFeatureCollection?> loadLocationsSubFor(String subperfecture, String cat) async { static Future<GeoJsonFeatureCollection?> loadLocationsSubFor(String subperfecture, String cat) async {
final IndexController indexController = Get.find<IndexController>(); final IndexController indexController = Get.find<IndexController>();