optimized

This commit is contained in:
Mohamed Nouffer
2023-10-06 16:25:21 +05:30
parent 7fdb6c05ee
commit 0e2a8f89f3
101 changed files with 50948 additions and 4137 deletions

View File

@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:geojson/geojson.dart';
import 'package:geolocator/geolocator.dart';
@ -28,15 +26,15 @@ class BottomSheetNew extends GetView<BottomSheetController> {
Image getImage() {
String serverUrl = ConstValues.currentServer();
if (indexController.rog_mode == 1) {
if (indexController.rogMode == 1) {
//print("----- rogaining mode 1");
if (indexController.currentDestinationFeature.isEmpty ||
indexController.currentDestinationFeature[0].photos! == "") {
return const Image(image: AssetImage('assets/images/empty_image.png'));
} else {
//print("@@@@@@@@@@@@@ rog mode -------------------- ${indexController.currentDestinationFeature[0].photos} @@@@@@@@@@@");
String _photo = indexController.currentDestinationFeature[0].photos!;
if (_photo.contains('http')) {
String photo = indexController.currentDestinationFeature[0].photos!;
if (photo.contains('http')) {
return Image(
image: NetworkImage(
indexController.currentDestinationFeature[0].photos!,
@ -49,8 +47,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
} else {
return Image(
image: NetworkImage(
'$serverUrl/media/compressed/' +
indexController.currentDestinationFeature[0].photos!,
'$serverUrl/media/compressed/${indexController.currentDestinationFeature[0].photos!}',
),
errorBuilder: (BuildContext context, Object exception,
StackTrace? stackTrace) {
@ -64,8 +61,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
if (gf.properties!["photos"] == null || gf.properties!["photos"] == "") {
return const Image(image: AssetImage('assets/images/empty_image.png'));
} else {
String _photo = gf.properties!["photos"];
if (_photo.contains('http')) {
String photo = gf.properties!["photos"];
if (photo.contains('http')) {
return Image(
image: NetworkImage(
gf.properties!["photos"],
@ -78,7 +75,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
} else {
return Image(
image: NetworkImage(
'$serverUrl/media/compressed/' + gf.properties!["photos"],
'$serverUrl/media/compressed/${gf.properties!["photos"]}',
),
errorBuilder: (BuildContext context, Object exception,
StackTrace? stackTrace) {
@ -91,7 +88,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
}
void _launchURL(url) async {
if (!await launch(url)) throw 'Could not launch $url';
if (!await launchUrl(url)) throw 'Could not launch $url';
}
bool isInDestination(String locationid) {
@ -107,63 +104,60 @@ class BottomSheetNew extends GetView<BottomSheetController> {
@override
Widget build(BuildContext context) {
destinationController.skip_gps = true;
print('---- rog_mode ----- ${indexController.rog_mode} -----');
return indexController.rog_mode == 0
destinationController.skipGps = true;
//print('---- rog_mode ----- ${indexController.rog_mode} -----');
return indexController.rogMode.value == 0
? detailsSheet(context)
: destinationSheet(context);
}
// Show destination detais
SingleChildScrollView destinationSheet(BuildContext context) {
print(
'---- currentDestinationFeature ----- ${indexController.currentDestinationFeature[0].name} -----');
// print(
// '---- currentDestinationFeature ----- ${indexController.currentDestinationFeature[0].name} -----');
return SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Row(
children: [
MaterialButton(
onPressed: () {
Get.back();
//destinationController.makePrevious(indexController.currentDestinationFeature[0]);
},
color: Colors.blue,
textColor: Colors.white,
child: const Icon(
Icons.arrow_back_ios,
size: 14,
),
padding: const EdgeInsets.all(16),
shape: const CircleBorder(),
child: Row(
children: [
MaterialButton(
onPressed: () {
Get.back();
//destinationController.makePrevious(indexController.currentDestinationFeature[0]);
},
color: Colors.blue,
textColor: Colors.white,
padding: const EdgeInsets.all(16),
shape: const CircleBorder(),
child: const Icon(
Icons.arrow_back_ios,
size: 14,
),
Expanded(
child: Container(
alignment: Alignment.center,
child: Obx(() => indexController.currentUser.isNotEmpty
? Text(
"${TextUtils.getDisplayText(indexController.currentDestinationFeature[0])} : ${TextUtils.getDisplayText(indexController.currentDestinationFeature[0])} : ${indexController.currentDestinationFeature[0].name!}",
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)
: Text(
indexController
.currentDestinationFeature[0].name!,
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)),
),
),
Expanded(
child: Container(
alignment: Alignment.center,
child: Obx(() => indexController.currentUser.isNotEmpty
? Text(
"${TextUtils.getDisplayText(indexController.currentDestinationFeature[0])} : ${TextUtils.getDisplayText(indexController.currentDestinationFeature[0])} : ${indexController.currentDestinationFeature[0].name!}",
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)
: Text(
indexController.currentDestinationFeature[0].name!,
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)),
),
],
),
),
],
),
),
Row(
@ -180,8 +174,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
children: [
Obx(
() => indexController.currentDestinationFeature.isNotEmpty &&
destinationController.is_in_checkin.value == true &&
destinationController.is_at_start.value == false
destinationController.isInCheckin.value == true &&
destinationController.isAtStart.value == false
? Row(
children: [
ElevatedButton(
@ -196,8 +190,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
.currentDestinationFeature[0]
.hidden_location ==
0) {
destinationController.skip_gps = false;
destinationController.is_photo_shoot.value =
destinationController.skipGps = false;
destinationController.isPhotoShoot.value =
true;
Get.back();
} else {
@ -210,7 +204,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
.currentDestinationFeature[0].cp !=
-1) {
destinationController
.rogaining_counted.value = true;
.rogainingCounted.value = true;
}
}
} else {
@ -238,18 +232,18 @@ class BottomSheetNew extends GetView<BottomSheetController> {
: Container(),
),
Obx(
() => destinationController.is_at_start.value == true
() => destinationController.isAtStart.value == true
? ElevatedButton(
onPressed: () {
destinationController.is_in_rog.value = true;
destinationController.isInRog.value = true;
destinationController.addToRogaining(
destinationController.current_lat,
destinationController.current_lon,
destinationController.currentLat,
destinationController.currentLon,
indexController
.currentDestinationFeature[0].location_id!);
saveGameState();
saveGameState();
ExternalService()
.StartRogaining()
.startRogaining()
.then((value) => Get.back());
},
child: Text(
@ -265,8 +259,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
: Container(),
),
Obx(
() => destinationController.is_at_goal.value == true &&
destinationController.rogaining_counted == true
() => destinationController.isAtGoal.value == true &&
destinationController.rogainingCounted.value == true
? ElevatedButton(
onPressed: () {
Get.toNamed(AppPages.CAMERA_PAGE);
@ -374,51 +368,51 @@ class BottomSheetNew extends GetView<BottomSheetController> {
// show add location details
SingleChildScrollView detailsSheet(BuildContext context) {
Destination _cdest = destinationController.festuretoDestination(
indexController.currentFeature[0]);
Destination cdest = destinationController
.festuretoDestination(indexController.currentFeature[0]);
var distance = const Distance();
double _distance_to_dest = distance.as(LengthUnit.Meter, LatLng(destinationController.current_lat, destinationController.current_lon), LatLng(_cdest.lat!, _cdest.lon!));
double distanceToDest = distance.as(
LengthUnit.Meter,
LatLng(
destinationController.currentLat, destinationController.currentLon),
LatLng(cdest.lat!, cdest.lon!));
return SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Row(
children: [
MaterialButton(
onPressed: () {
Get.back();
//indexController.makePrevious(indexController.currentFeature[0]);
},
color: Colors.blue,
textColor: Colors.white,
child: const Icon(
Icons.arrow_back_ios,
//Icons.arrow_back_ios,
size: 14,
),
padding: const EdgeInsets.all(16),
shape: const CircleBorder(),
child: Row(
children: [
MaterialButton(
onPressed: () {
Get.back();
//indexController.makePrevious(indexController.currentFeature[0]);
},
color: Colors.blue,
textColor: Colors.white,
padding: const EdgeInsets.all(16),
shape: const CircleBorder(),
child: const Icon(
Icons.arrow_back_ios,
//Icons.arrow_back_ios,
size: 14,
),
Expanded(
child: Container(
alignment: Alignment.center,
child: Obx(() => Text(
indexController
.currentFeature[0].properties!["location_name"],
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)),
),
),
Expanded(
child: Container(
alignment: Alignment.center,
child: Obx(() => Text(
indexController
.currentFeature[0].properties!["location_name"],
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)),
),
],
),
),
],
),
),
Row(
@ -446,26 +440,25 @@ class BottomSheetNew extends GetView<BottomSheetController> {
indexController.currentDestinationFeature[0]
.checkedin ==
false &&
destinationController.is_at_start.value ==
true
destinationController.isAtStart.value == true
? ElevatedButton(
onPressed: () async {
await destinationController.resetRogaining();
print("~~~~ start button ~~~~");
destinationController.is_in_rog.value =
true;
await destinationController
.resetRogaining();
//print("~~~~ start button ~~~~");
destinationController.isInRog.value = true;
destinationController.addToRogaining(
destinationController.current_lat,
destinationController.current_lon,
destinationController.currentLat,
destinationController.currentLon,
indexController
.currentDestinationFeature[0]
.location_id!);
saveGameState();
saveGameState();
ExternalService()
.StartRogaining()
.then((value){
Get.back();
});
.startRogaining()
.then((value) {
Get.back();
});
},
child: Text(
// start
@ -484,9 +477,9 @@ class BottomSheetNew extends GetView<BottomSheetController> {
: Container(),
),
Obx(
() => destinationController.is_at_goal.value ==
true &&
destinationController.rogaining_counted ==
() => destinationController.isAtGoal.value == true &&
destinationController
.rogainingCounted.value ==
true
? ElevatedButton(
onPressed: () {
@ -521,7 +514,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
.onPrimaryContainer),
onPressed: () async {
Get.back();
print("---- go to ----");
//print("---- go to ----");
GeoJsonFeature<GeoJsonMultiPoint> mp =
indexController.currentFeature[0]
as GeoJsonFeature<GeoJsonMultiPoint>;
@ -530,7 +523,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
desiredAccuracy:
LocationAccuracy.bestForNavigation,
forceAndroidLocationManager: true);
print("------- position -------- $position");
//print("------- position -------- $position");
Destination ds = Destination(
lat: position.latitude,
lon: position.longitude);
@ -550,49 +543,48 @@ class BottomSheetNew extends GetView<BottomSheetController> {
color:
Theme.of(context).colorScheme.onPrimary),
)),
SizedBox(
const SizedBox(
width: 10,
),
// forced start / checkin
_distance_to_dest <= 100 ?
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.secondary),
onPressed: () async {
print("~~~~ manual checkin button ~~~~");
if (destination.cp == -1) {
destinationController.is_in_rog.value = true;
destinationController.addToRogaining(
destinationController.current_lat,
destinationController.current_lon,
destination.location_id!);
saveGameState();
ExternalService()
.StartRogaining()
.then((value) => Get.back());
} else {
await destinationController.CallforCheckin(destination);
}
},
child: Text(
destinationController
.festuretoDestination(
indexController
.currentFeature[0])
.cp ==
-1
? "ロゲ開始"
: "チェックイン",
style: TextStyle(
color: Theme.of(context)
distanceToDest <= 100
? ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context)
.colorScheme
.onSecondary))):
Container()
,
.secondary),
onPressed: () async {
//print("~~~~ manual checkin button ~~~~");
if (destination.cp == -1) {
destinationController.isInRog.value = true;
destinationController.addToRogaining(
destinationController.currentLat,
destinationController.currentLon,
destination.location_id!);
saveGameState();
ExternalService()
.startRogaining()
.then((value) => Get.back());
} else {
await destinationController
.callforCheckin(destination);
}
},
child: Text(
destinationController
.festuretoDestination(
indexController
.currentFeature[0])
.cp ==
-1
? "ロゲ開始"
: "チェックイン",
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onSecondary)))
: Container(),
],
),
Row(
@ -603,8 +595,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
children: [
indexController.currentDestinationFeature
.isNotEmpty &&
destinationController
.is_in_checkin.value ==
destinationController.isInCheckin.value ==
true
? Container()
: FutureBuilder<Widget>(
@ -787,14 +778,14 @@ class BottomSheetNew extends GetView<BottomSheetController> {
}
Future<Widget> wantToGo(BuildContext context) async {
bool _selected = false;
print(
'---target-- ${indexController.currentFeature[0].properties!["location_id"]}----');
bool selected = false;
// print(
// '---target-- ${indexController.currentFeature[0].properties!["location_id"]}----');
for (Destination d in destinationController.destinations) {
print('---- ${d.location_id.toString()} ----');
//print('---- ${d.location_id.toString()} ----');
if (d.location_id ==
indexController.currentFeature[0].properties!["location_id"]) {
_selected = true;
selected = true;
break;
}
}
@ -905,12 +896,12 @@ class BottomSheetNew extends GetView<BottomSheetController> {
const SizedBox(
width: 8.0,
),
Obx((() => indexController.rog_mode == 1
Obx((() => indexController.rogMode.value == 1
? ElevatedButton(
onPressed: () async {
Destination dest =
indexController.currentDestinationFeature[0];
print("~~~~ before checking button ~~~~");
//print("~~~~ before checking button ~~~~");
//print("------ curent destination is ${dest!.checkedIn}-------");
destinationController.makeCheckin(
dest, !dest.checkedin!, "");
@ -945,8 +936,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
ElevatedButton(
child: const Text("Image"),
onPressed: () {
final ImagePicker _picker = ImagePicker();
_picker
final ImagePicker picker = ImagePicker();
picker
.pickImage(source: ImageSource.camera)
.then((value) {
//print("----- image---- ${value!.path}");
@ -968,7 +959,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
//print("---temp---${temp}");
indexController.currentAction.add([temp]);
}
indexController.makeAction(context);
},
child: Text("checkin".tr))
],
@ -984,7 +974,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
//print("---temp---${temp}");
indexController.currentAction.add([temp]);
}
indexController.makeAction(context);
},
child: const Icon(Icons.favorite, color: Colors.red),
)
@ -1006,7 +995,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
InkWell(
onTap: () {
if (isurl) {
if (indexController.rog_mode == 0) {
if (indexController.rogMode.value == 0) {
_launchURL(indexController
.currentFeature[0].properties!["webcontents"]);
} else {
@ -1015,7 +1004,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
}
},
child: SizedBox(
width: MediaQuery.of(context).size.width - (MediaQuery.of(context).size.width * 0.28),
width: MediaQuery.of(context).size.width -
(MediaQuery.of(context).size.width * 0.28),
child: Text(
text,
textDirection: TextDirection.ltr,