fixed state
This commit is contained in:
@ -9,6 +9,21 @@ import 'package:rogapp/utils/string_values.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
// import 'package:is_lock_screen/is_lock_screen.dart';
|
||||
|
||||
void saveGameState() async {
|
||||
DestinationController destinationController = Get.find<DestinationController>();
|
||||
SharedPreferences pref = await SharedPreferences.getInstance();
|
||||
pref.setBool("is_in_rog", destinationController.is_in_rog.value);
|
||||
pref.setBool("rogaining_counted", destinationController.rogaining_counted.value);
|
||||
}
|
||||
|
||||
void restoreGame() async{
|
||||
SharedPreferences pref = await SharedPreferences.getInstance();
|
||||
DestinationController destinationController = Get.find<DestinationController>();
|
||||
destinationController.skip_gps = false;
|
||||
destinationController.is_in_rog.value = pref.getBool("is_in_rog") ?? false;
|
||||
destinationController.rogaining_counted.value = pref.getBool("rogaining_counted") ?? false;
|
||||
}
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@ -27,7 +42,6 @@ void main() async {
|
||||
key: 'behaviour',
|
||||
value: 'cacheFirst',
|
||||
);
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
@ -55,20 +69,13 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void saveGameState() async {
|
||||
DestinationController destinationController = Get.find<DestinationController>();
|
||||
SharedPreferences pref = await SharedPreferences.getInstance();
|
||||
pref.setBool("is_in_rog", destinationController.is_in_rog.value);
|
||||
pref.setBool("rogaining_counted", destinationController.rogaining_counted.value);
|
||||
}
|
||||
// void saveGameState() async {
|
||||
// DestinationController destinationController = Get.find<DestinationController>();
|
||||
// SharedPreferences pref = await SharedPreferences.getInstance();
|
||||
// pref.setBool("is_in_rog", destinationController.is_in_rog.value);
|
||||
// pref.setBool("rogaining_counted", destinationController.rogaining_counted.value);
|
||||
// }
|
||||
|
||||
void restoreGame() async{
|
||||
SharedPreferences pref = await SharedPreferences.getInstance();
|
||||
DestinationController destinationController = Get.find<DestinationController>();
|
||||
destinationController.skip_gps = false;
|
||||
destinationController.is_in_rog.value = pref.getBool("is_in_rog") ?? false;
|
||||
destinationController.rogaining_counted.value = pref.getBool("rogaining_counted") ?? false;
|
||||
}
|
||||
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
DestinationController destinationController = Get.find<DestinationController>();
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rogapp/main.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
|
||||
class DestinationBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.put<DestinationController>(DestinationController());
|
||||
restoreGame();
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:rogapp/main.dart';
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
import 'package:rogapp/pages/camera/camera_page.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
@ -109,9 +110,10 @@ class DestinationController extends GetxController {
|
||||
|
||||
void startTimerLocation(GeoJsonFeature fs, double distance) {
|
||||
print("---- in startTimer ----");
|
||||
print("---- is in rog is ${is_in_rog} ----");
|
||||
//skip_gps = true;
|
||||
double checkinRadious = fs.properties!['checkin_radius'] ?? double.infinity;
|
||||
if (checkinRadious >= distance) {
|
||||
//if (checkinRadious >= distance) {
|
||||
indexController.currentFeature.clear();
|
||||
Destination d = festuretoDestination(fs);
|
||||
print("----- destination lenght is ${destinations.length} -----");
|
||||
@ -124,7 +126,7 @@ class DestinationController extends GetxController {
|
||||
indexController.currentFeature.add(fs);
|
||||
print("---- before calling startTimer ----");
|
||||
startTimer(d, distance);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
void startTimer(Destination d, double distance) async {
|
||||
@ -337,6 +339,8 @@ class DestinationController extends GetxController {
|
||||
is_gps_selected.value = true;
|
||||
skip_gps = false;
|
||||
|
||||
saveGameState();
|
||||
|
||||
_start = 0;
|
||||
chekcs = 0;
|
||||
rogaining_counted.value = false;
|
||||
@ -365,13 +369,16 @@ class DestinationController extends GetxController {
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => CameraCamera(
|
||||
resolutionPreset: ResolutionPreset.medium,
|
||||
onFile: (file) {
|
||||
photos.add(file);
|
||||
Navigator.pop(context);
|
||||
print("----image file is : $file----");
|
||||
//setState(() {});
|
||||
},
|
||||
)));
|
||||
)
|
||||
|
||||
));
|
||||
}
|
||||
|
||||
void getRoutePoints() {
|
||||
@ -408,6 +415,7 @@ class DestinationController extends GetxController {
|
||||
} else {
|
||||
print("--- hidden loc ${d.hidden_location} ----");
|
||||
// ask for checkin
|
||||
print("is rog ---- ${is_in_rog.value} ----");
|
||||
if (d.hidden_location != null &&
|
||||
d.hidden_location == 0 &&
|
||||
is_in_rog.value == true &&
|
||||
@ -425,7 +433,7 @@ class DestinationController extends GetxController {
|
||||
destination: d,
|
||||
))).whenComplete(() {
|
||||
skip_gps = false;
|
||||
rogaining_counted.value = true;
|
||||
//rogaining_counted.value = true;
|
||||
chekcs = 0;
|
||||
is_in_checkin.value = false;
|
||||
});
|
||||
@ -497,6 +505,8 @@ class DestinationController extends GetxController {
|
||||
makeCheckin(df, true, "");
|
||||
}
|
||||
is_in_rog.value = true;
|
||||
|
||||
saveGameState();
|
||||
}
|
||||
|
||||
void makeCheckin(
|
||||
@ -514,7 +524,7 @@ class DestinationController extends GetxController {
|
||||
|
||||
await GallerySaver.saveImage(imageurl);
|
||||
|
||||
PopulateDestinations();
|
||||
//PopulateDestinations();
|
||||
|
||||
/// post to NATNAT
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
@ -622,6 +632,8 @@ class DestinationController extends GetxController {
|
||||
// Start a new timer that fires every 3 seconds
|
||||
_timer = Timer.periodic(Duration(seconds: 3), (timer) async {
|
||||
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
|
||||
current_lat = position.latitude;
|
||||
current_lon = position.longitude;
|
||||
|
||||
if (is_gps_selected.value) {
|
||||
double czoom = indexController.rogMapController.zoom;
|
||||
|
||||
@ -65,8 +65,14 @@ class IndexPage extends GetView<IndexController> {
|
||||
),
|
||||
bottomNavigationBar: BottomAppBar(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Obx(() =>
|
||||
destinationController.is_in_rog.value == true ?
|
||||
IconButton(onPressed: (){}, icon: Icon(Icons.run_circle, size: 44, color: Colors.green,))
|
||||
:
|
||||
IconButton(onPressed: (){}, icon: Icon(Icons.run_circle, size: 44, color: Colors.black12,)),
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0),
|
||||
|
||||
@ -3,6 +3,8 @@ import 'package:geojson/geojson.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:rogapp/main.dart';
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
@ -242,6 +244,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
||||
destinationController.current_lon,
|
||||
indexController
|
||||
.currentDestinationFeature[0].location_id!);
|
||||
saveGameState();
|
||||
ExternalService()
|
||||
.StartRogaining()
|
||||
.then((value) => Get.back());
|
||||
@ -368,6 +371,13 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
||||
|
||||
// show add location details
|
||||
SingleChildScrollView detailsSheet(BuildContext context) {
|
||||
|
||||
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!));
|
||||
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
@ -445,6 +455,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
||||
indexController
|
||||
.currentDestinationFeature[0]
|
||||
.location_id!);
|
||||
saveGameState();
|
||||
ExternalService()
|
||||
.StartRogaining()
|
||||
.then((value) => Get.back());
|
||||
@ -535,6 +546,10 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
|
||||
|
||||
// forced start / checkin
|
||||
_distance_to_dest <= 100 ?
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor:
|
||||
@ -550,6 +565,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
||||
destinationController.current_lat,
|
||||
destinationController.current_lon,
|
||||
dd.location_id!);
|
||||
saveGameState();
|
||||
ExternalService()
|
||||
.StartRogaining()
|
||||
.then((value) => Get.back());
|
||||
@ -569,7 +585,10 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSecondary))),
|
||||
.onSecondary))):
|
||||
|
||||
Container()
|
||||
,
|
||||
],
|
||||
),
|
||||
Row(
|
||||
|
||||
@ -69,7 +69,7 @@ dependencies:
|
||||
flutter_launcher_icons: ^0.13.1
|
||||
rename: ^2.0.1
|
||||
circular_menu: ^2.0.1
|
||||
camera_camera: ^3.0.0-dev
|
||||
camera_camera: ^3.0.0
|
||||
intl: ^0.18.1
|
||||
modal_bottom_sheet: ^3.0.0-pre
|
||||
connectivity_plus: ^4.0.2
|
||||
@ -78,6 +78,7 @@ dependencies:
|
||||
gallery_saver: ^2.3.2
|
||||
flutter_riverpod: ^2.4.0
|
||||
|
||||
|
||||
|
||||
flutter_icons:
|
||||
android: true
|
||||
|
||||
Reference in New Issue
Block a user