fixed popup buttons added location stream and center button
This commit is contained in:
@ -3,6 +3,7 @@ import 'dart:typed_data';
|
|||||||
import 'package:camera_camera/camera_camera.dart';
|
import 'package:camera_camera/camera_camera.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_map/flutter_map.dart';
|
import 'package:flutter_map/flutter_map.dart';
|
||||||
|
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
|
||||||
import 'package:geojson_vi/geojson_vi.dart';
|
import 'package:geojson_vi/geojson_vi.dart';
|
||||||
import 'package:geolocator/geolocator.dart';
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@ -756,9 +757,17 @@ class DestinationController extends GetxController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() async {
|
void onInit() async {
|
||||||
ever(locationController.currentPosition, handleLocationUpdate);
|
|
||||||
startGame();
|
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
locationController.locationMarkerPositionStream.listen(
|
||||||
|
(locationMarkerPosition) {
|
||||||
|
if (locationMarkerPosition != null) {
|
||||||
|
handleLocationUpdate(locationMarkerPosition);
|
||||||
|
}
|
||||||
|
}, onError: (err) {
|
||||||
|
print("Error: $err");
|
||||||
|
});
|
||||||
|
|
||||||
|
startGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -766,7 +775,7 @@ class DestinationController extends GetxController {
|
|||||||
locationController.stopPositionStream();
|
locationController.stopPositionStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleLocationUpdate(Position? position) async {
|
void handleLocationUpdate(LocationMarkerPosition? position) async {
|
||||||
try {
|
try {
|
||||||
if (position != null) {
|
if (position != null) {
|
||||||
if (distanceToStart() >= 1000) {
|
if (distanceToStart() >= 1000) {
|
||||||
@ -795,7 +804,7 @@ class DestinationController extends GetxController {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (position != null &&
|
if (position != null &&
|
||||||
(position.latitude != 0 || position.longitude != 0)) {
|
(position.latitude != 0 && position.longitude != 0)) {
|
||||||
currentLat = position.latitude;
|
currentLat = position.latitude;
|
||||||
currentLon = position.longitude;
|
currentLon = position.longitude;
|
||||||
}
|
}
|
||||||
@ -912,13 +921,13 @@ class DestinationController extends GetxController {
|
|||||||
indexController.currentBound.clear();
|
indexController.currentBound.clear();
|
||||||
indexController.currentBound.add(bnds);
|
indexController.currentBound.add(bnds);
|
||||||
indexController.loadLocationsBound();
|
indexController.loadLocationsBound();
|
||||||
|
centerMapToCurrentLocation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
centerMapToCurrentLocation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void centerMapToCurrentLocation() {
|
void centerMapToCurrentLocation() {
|
||||||
print("center is ${currentLat}, ${currentLon}");
|
print("center is ${currentLon}, ${currentLon}");
|
||||||
if (currentLat != 0 || currentLon != 0) {
|
if (currentLat != 0 || currentLon != 0) {
|
||||||
indexController.mapController.move(LatLng(currentLat, currentLon), 17.0);
|
indexController.mapController.move(LatLng(currentLat, currentLon), 17.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class MatrixService {
|
|||||||
|
|
||||||
Map<String, dynamic> cats = {};
|
Map<String, dynamic> cats = {};
|
||||||
String url =
|
String url =
|
||||||
"https://maps.googleapis.com/maps/api/directions/json?destination=$destination&mode=$mode&waypoints=$locs&origin=$origin&key=AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE";
|
"https://maps.googleapis.com/maps/api/directions/json?destination=$destination&mode=$mode&waypoints=$locs&origin=$origin&key=AIzaSyCN2xFsqFyadWwpjiFxymrxzS6G1tNzraI";
|
||||||
//print('++++++++$url');
|
//print('++++++++$url');
|
||||||
final http.Response response =
|
final http.Response response =
|
||||||
await http.get(Uri.parse(url), headers: <String, String>{
|
await http.get(Uri.parse(url), headers: <String, String>{
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:geolocator/geolocator.dart';
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:rogapp/widgets/debug_widget.dart';
|
import 'package:rogapp/widgets/debug_widget.dart';
|
||||||
|
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
|
||||||
|
|
||||||
class LocationController extends GetxController {
|
class LocationController extends GetxController {
|
||||||
// Reactive variable to hold the current position
|
// Reactive variable to hold the current position
|
||||||
@ -10,8 +11,15 @@ class LocationController extends GetxController {
|
|||||||
|
|
||||||
// Subscription to the position stream
|
// Subscription to the position stream
|
||||||
StreamSubscription<Position>? positionStream;
|
StreamSubscription<Position>? positionStream;
|
||||||
|
|
||||||
|
final locationMarkerPositionStreamController =
|
||||||
|
StreamController<LocationMarkerPosition?>.broadcast();
|
||||||
|
|
||||||
bool isStreamPaused = false;
|
bool isStreamPaused = false;
|
||||||
|
|
||||||
|
Stream<LocationMarkerPosition?> get locationMarkerPositionStream =>
|
||||||
|
locationMarkerPositionStreamController.stream;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
@ -99,36 +107,33 @@ class LocationController extends GetxController {
|
|||||||
|
|
||||||
// Set up the location options
|
// Set up the location options
|
||||||
const locationOptions =
|
const locationOptions =
|
||||||
LocationSettings(accuracy: LocationAccuracy.high, distanceFilter: 10);
|
LocationSettings(accuracy: LocationAccuracy.high, distanceFilter: 0);
|
||||||
|
|
||||||
// Start listening to the position stream
|
await positionStream?.cancel();
|
||||||
// positionStream =
|
|
||||||
// Geolocator.getPositionStream(locationSettings: locationOptions).listen(
|
|
||||||
// (Position position) {
|
|
||||||
// currentPosition.value = position;
|
|
||||||
// }, onError: (e) {
|
|
||||||
// // Handle errors or exceptions in the stream
|
|
||||||
// // You might want to log this error or use a state to show error messages
|
|
||||||
// });
|
|
||||||
|
|
||||||
StreamSubscription<Position> positionStream =
|
positionStream =
|
||||||
Geolocator.getPositionStream(locationSettings: locationOptions)
|
Geolocator.getPositionStream(locationSettings: locationOptions).listen(
|
||||||
.listen((Position? position) {
|
(Position? position) {
|
||||||
// print(position == null
|
if (position != null) {
|
||||||
// ? 'Unknown'
|
final LocationMarkerPosition locationMarkerPosition =
|
||||||
// : '${position.latitude.toString()}, ${position.longitude.toString()}');
|
LocationMarkerPosition(
|
||||||
if (position?.accuracy != null && position!.accuracy <= 15) {
|
latitude: position.latitude,
|
||||||
currentPosition.value = position;
|
longitude: position.longitude,
|
||||||
}
|
accuracy: position.accuracy);
|
||||||
|
locationMarkerPositionStreamController.add(locationMarkerPosition);
|
||||||
// LogManager().addLog(
|
} else {
|
||||||
// "GPS : ${position!.latitude.toString()}, ${position.longitude.toString()} - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}");
|
locationMarkerPositionStreamController.add(null);
|
||||||
});
|
}
|
||||||
|
},
|
||||||
|
onError: (e) {
|
||||||
|
locationMarkerPositionStreamController.addError(e);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Resume stream if it was paused previously
|
// Resume stream if it was paused previously
|
||||||
if (isStreamPaused) {
|
if (isStreamPaused) {
|
||||||
isStreamPaused = false;
|
isStreamPaused = false;
|
||||||
positionStream.resume();
|
positionStream!.resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -111,6 +111,11 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget getActionButton(BuildContext context, Destination destination) {
|
Widget getActionButton(BuildContext context, Destination destination) {
|
||||||
|
print("getActionButton ${destinationController.rogainingCounted.value}");
|
||||||
|
print("getActionButton ${destinationController.distanceToStart()}");
|
||||||
|
print("getActionButton ${destination.cp}");
|
||||||
|
print("getActionButton ${DestinationController.ready_for_goal}");
|
||||||
|
|
||||||
Destination cdest = destinationController
|
Destination cdest = destinationController
|
||||||
.festuretoDestination(indexController.currentFeature[0]);
|
.festuretoDestination(indexController.currentFeature[0]);
|
||||||
var distance = const Distance();
|
var distance = const Distance();
|
||||||
@ -121,8 +126,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
|||||||
LatLng(cdest.lat!, cdest.lon!));
|
LatLng(cdest.lat!, cdest.lon!));
|
||||||
|
|
||||||
if (destinationController.rogainingCounted.value == true &&
|
if (destinationController.rogainingCounted.value == true &&
|
||||||
destinationController.distanceToStart() <= 500 //destination.cp == -1
|
destinationController.distanceToStart() <= 500 &&
|
||||||
&&
|
destination.cp == -1 &&
|
||||||
DestinationController.ready_for_goal == true) {
|
DestinationController.ready_for_goal == true) {
|
||||||
//goal
|
//goal
|
||||||
return ElevatedButton(
|
return ElevatedButton(
|
||||||
@ -161,9 +166,12 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
|||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// Check conditions to show confirmation dialog
|
// Check conditions to show confirmation dialog
|
||||||
if (destination.cp == -1 &&
|
if (destinationController.isInRog.value == false &&
|
||||||
destinationController.isInRog.value == false &&
|
destination.cp == -1 &&
|
||||||
|
DestinationController.ready_for_goal &&
|
||||||
destinationController.rogainingCounted.value == false) {
|
destinationController.rogainingCounted.value == false) {
|
||||||
|
print("counted ${destinationController.rogainingCounted.value}");
|
||||||
|
|
||||||
// Show confirmation dialog
|
// Show confirmation dialog
|
||||||
Get.dialog(
|
Get.dialog(
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
@ -182,8 +190,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// Clear data and start game logic here
|
// Clear data and start game logic here
|
||||||
destinationController.isInRog.value = true;
|
destinationController.isInRog.value = true;
|
||||||
destinationController
|
destinationController.resetRogaining();
|
||||||
.resetRogaining(); // Assuming you have a method to clear data
|
|
||||||
destinationController.addToRogaining(
|
destinationController.addToRogaining(
|
||||||
destinationController.currentLat,
|
destinationController.currentLat,
|
||||||
destinationController.currentLon,
|
destinationController.currentLon,
|
||||||
@ -199,13 +206,16 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
|||||||
barrierDismissible:
|
barrierDismissible:
|
||||||
false, // User must tap a button to close the dialog
|
false, // User must tap a button to close the dialog
|
||||||
);
|
);
|
||||||
} else {
|
} else if (destinationController.isInRog.value == true) {
|
||||||
|
//print("counted ${destinationController.rogainingCounted.value}");
|
||||||
// Existing logic for other conditions
|
// Existing logic for other conditions
|
||||||
if (destination.cp == -1) {
|
if (destination.cp == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Get.back();
|
Get.back();
|
||||||
await destinationController.callforCheckin(destination);
|
await destinationController.callforCheckin(destination);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -218,7 +228,9 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
|||||||
? "ゲーム中"
|
? "ゲーム中"
|
||||||
: isAlreadyCheckedIn == true
|
: isAlreadyCheckedIn == true
|
||||||
? "ゲーム中"
|
? "ゲーム中"
|
||||||
: "チェックイン",
|
: destinationController.isInRog.value == true
|
||||||
|
? "チェックイン"
|
||||||
|
: "始まっていない",
|
||||||
style: TextStyle(color: Theme.of(context).colorScheme.onSecondary),
|
style: TextStyle(color: Theme.of(context).colorScheme.onSecondary),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
34
lib/widgets/current_position_widget.dart
Normal file
34
lib/widgets/current_position_widget.dart
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||||
|
|
||||||
|
class CurrentPosition extends StatefulWidget {
|
||||||
|
const CurrentPosition({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CurrentPosition> createState() => _CurrentPositionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CurrentPositionState extends State<CurrentPosition> {
|
||||||
|
final DestinationController destinationController =
|
||||||
|
Get.find<DestinationController>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey, borderRadius: BorderRadius.circular(20.0)),
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
destinationController.centerMapToCurrentLocation();
|
||||||
|
},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.location_searching,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,9 +11,11 @@ import 'package:rogapp/model/destination.dart';
|
|||||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||||
import 'package:rogapp/pages/index/index_controller.dart';
|
import 'package:rogapp/pages/index/index_controller.dart';
|
||||||
import 'package:rogapp/utils/database_helper.dart';
|
import 'package:rogapp/utils/database_helper.dart';
|
||||||
|
import 'package:rogapp/utils/location_controller.dart';
|
||||||
import 'package:rogapp/utils/text_util.dart';
|
import 'package:rogapp/utils/text_util.dart';
|
||||||
import 'package:rogapp/widgets/base_layer_widget.dart';
|
import 'package:rogapp/widgets/base_layer_widget.dart';
|
||||||
import 'package:rogapp/widgets/bottom_sheet_new.dart';
|
import 'package:rogapp/widgets/bottom_sheet_new.dart';
|
||||||
|
import 'package:rogapp/widgets/current_position_widget.dart';
|
||||||
import 'package:rogapp/widgets/game_state_view.dart';
|
import 'package:rogapp/widgets/game_state_view.dart';
|
||||||
|
|
||||||
class MapWidget extends StatefulWidget {
|
class MapWidget extends StatefulWidget {
|
||||||
@ -28,6 +30,7 @@ class _MapWidgetState extends State<MapWidget> {
|
|||||||
|
|
||||||
final DestinationController destinationController =
|
final DestinationController destinationController =
|
||||||
Get.find<DestinationController>();
|
Get.find<DestinationController>();
|
||||||
|
final LocationController locationController = Get.find<LocationController>();
|
||||||
|
|
||||||
StreamSubscription? subscription;
|
StreamSubscription? subscription;
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
@ -50,6 +53,7 @@ class _MapWidgetState extends State<MapWidget> {
|
|||||||
|
|
||||||
DatabaseHelper db = DatabaseHelper.instance;
|
DatabaseHelper db = DatabaseHelper.instance;
|
||||||
db.getDestinationByLatLon(des.lat!, des.lon!).then((value) {
|
db.getDestinationByLatLon(des.lat!, des.lon!).then((value) {
|
||||||
|
destinationController.shouldShowBottomSheet = false;
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
constraints:
|
constraints:
|
||||||
BoxConstraints.loose(Size(Get.width, Get.height * 0.85)),
|
BoxConstraints.loose(Size(Get.width, Get.height * 0.85)),
|
||||||
@ -60,6 +64,7 @@ class _MapWidgetState extends State<MapWidget> {
|
|||||||
destination: des, isAlreadyCheckedIn: value.isNotEmpty))
|
destination: des, isAlreadyCheckedIn: value.isNotEmpty))
|
||||||
//builder:((context) => BottomSheetWidget())
|
//builder:((context) => BottomSheetWidget())
|
||||||
).whenComplete(() {
|
).whenComplete(() {
|
||||||
|
destinationController.shouldShowBottomSheet = true;
|
||||||
destinationController.skipGps = false;
|
destinationController.skipGps = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -176,10 +181,10 @@ class _MapWidgetState extends State<MapWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _centerMapOnUser() {
|
void _centerMapOnUser() {
|
||||||
//print("showBottomSheet ${destinationController.shouldShowBottomSheet}");
|
print("showBottomSheet ${destinationController.shouldShowBottomSheet}");
|
||||||
if (destinationController.shouldShowBottomSheet) {
|
//if (destinationController.shouldShowBottomSheet) {
|
||||||
destinationController.centerMapToCurrentLocation();
|
destinationController.centerMapToCurrentLocation();
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -246,7 +251,9 @@ class _MapWidgetState extends State<MapWidget> {
|
|||||||
: Container(),
|
: Container(),
|
||||||
),
|
),
|
||||||
CurrentLocationLayer(
|
CurrentLocationLayer(
|
||||||
followOnLocationUpdate: FollowOnLocationUpdate.never,
|
positionStream: locationController
|
||||||
|
.locationMarkerPositionStreamController.stream,
|
||||||
|
alignDirectionOnUpdate: AlignOnUpdate.never,
|
||||||
turnOnHeadingUpdate: TurnOnHeadingUpdate.never,
|
turnOnHeadingUpdate: TurnOnHeadingUpdate.never,
|
||||||
style: const LocationMarkerStyle(
|
style: const LocationMarkerStyle(
|
||||||
marker: DefaultLocationMarker(
|
marker: DefaultLocationMarker(
|
||||||
@ -284,6 +291,7 @@ class _MapWidgetState extends State<MapWidget> {
|
|||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
const Positioned(top: 0, left: 0, child: GameStateWidget()),
|
const Positioned(top: 0, left: 0, child: GameStateWidget()),
|
||||||
|
const Positioned(bottom: 10, right: 10, child: CurrentPosition())
|
||||||
// const Positioned(
|
// const Positioned(
|
||||||
// bottom: 10,
|
// bottom: 10,
|
||||||
// left: 0,
|
// left: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user