update buttons

This commit is contained in:
2024-03-02 11:11:46 +05:30
parent 992f9f3414
commit d55ba7cfdb
5 changed files with 177 additions and 142 deletions

View File

@ -191,7 +191,7 @@ class CameraPage extends StatelessWidget {
Get.snackbar("目標が保存されました", "目標が正常に追加されました"); Get.snackbar("目標が保存されました", "目標が正常に追加されました");
destinationController.resetRogaining(); destinationController.resetRogaining();
} else { } else {
print("---- status ${value['status']} ---- "); //print("---- status ${value['status']} ---- ");
Get.snackbar("目標が追加されていません", "please_try_again"); Get.snackbar("目標が追加されていません", "please_try_again");
} }
}); });
@ -406,7 +406,7 @@ class BuyPointCamera extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print("in camera purchase 1 ${destinationController.isInRog.value}"); //print("in camera purchase 1 ${destinationController.isInRog.value}");
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -445,8 +445,8 @@ class BuyPointCamera extends StatelessWidget {
children: [ children: [
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
print( // print(
"in camera purchase 2 ${destinationController.isInRog.value}"); // "in camera purchase 2 ${destinationController.isInRog.value}");
destinationController.openCamera( destinationController.openCamera(
context, destination); context, destination);
}, },
@ -485,14 +485,14 @@ class BuyPointCamera extends StatelessWidget {
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.red), backgroundColor: Colors.red),
onPressed: () async { onPressed: () async {
print( // print(
"in camera purchase 3 ${destinationController.isInRog.value}"); // "in camera purchase 3 ${destinationController.isInRog.value}");
await destinationController.makeBuyPoint( await destinationController.makeBuyPoint(
destination, destination,
destinationController.photos[0].path); destinationController.photos[0].path);
Get.back(); Get.back();
print( // print(
"in camera purchase 4 ${destinationController.isInRog.value}"); // "in camera purchase 4 ${destinationController.isInRog.value}");
destinationController.rogainingCounted.value = destinationController.rogainingCounted.value =
true; true;
destinationController.skipGps = false; destinationController.skipGps = false;

View File

@ -648,7 +648,7 @@ class DestinationController extends GetxController {
// Save the image to the gallery // Save the image to the gallery
final result = await ImageGallerySaver.saveImage(imageBytes); final result = await ImageGallerySaver.saveImage(imageBytes);
print("--- save result --- ${result}"); //print("--- save result --- ${result}");
} }
Future<void> makeBuyPoint(Destination destination, String imageurl) async { Future<void> makeBuyPoint(Destination destination, String imageurl) async {

View File

@ -165,7 +165,7 @@ class ExternalService {
//print("--- checnin response ${response2.statusCode}----"); //print("--- checnin response ${response2.statusCode}----");
if (response2.statusCode == 200) { if (response2.statusCode == 200) {
res = json.decode(utf8.decode(response2.bodyBytes)); res = json.decode(utf8.decode(response2.bodyBytes));
print('----checkin res _res : $res ----'); //print('----checkin res _res : $res ----');
if (res["status"] == "ERROR") { if (res["status"] == "ERROR") {
Get.snackbar("エラーがおきました", res["detail"]); Get.snackbar("エラーがおきました", res["detail"]);
} }
@ -267,7 +267,7 @@ class ExternalService {
); );
String url = 'https://rogaining.sumasen.net/gifuroge/goal_from_rogapp'; String url = 'https://rogaining.sumasen.net/gifuroge/goal_from_rogapp';
print('++++++++$url'); //print('++++++++$url');
if (response.statusCode == 201) { if (response.statusCode == 201) {
Map<String, dynamic> res = json.decode(utf8.decode(response.bodyBytes)); Map<String, dynamic> res = json.decode(utf8.decode(response.bodyBytes));
// print('----_res : $res ----'); // print('----_res : $res ----');
@ -293,8 +293,8 @@ class ExternalService {
.toString() .toString()
.replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net') .replaceAll('http://localhost:8100', 'http://rogaining.sumasen.net')
}); });
print("-- json -- $rec"); //print("-- json -- $rec");
print('----- response2 is $response2 --------'); //print('----- response2 is $response2 --------');
if (response2.statusCode == 200) { if (response2.statusCode == 200) {
res2 = json.decode(utf8.decode(response2.bodyBytes)); res2 = json.decode(utf8.decode(response2.bodyBytes));
} }

View File

@ -110,9 +110,125 @@ class BottomSheetNew extends GetView<BottomSheetController> {
} }
} }
Widget getActionButton(BuildContext context, Destination destination) {
Destination cdest = destinationController
.festuretoDestination(indexController.currentFeature[0]);
var distance = const Distance();
double distanceToDest = distance.as(
LengthUnit.Meter,
LatLng(
destinationController.currentLat, destinationController.currentLon),
LatLng(cdest.lat!, cdest.lon!));
if (destinationController.rogainingCounted.value == true &&
destinationController.distanceToStart() <= 500 //destination.cp == -1
&&
DestinationController.ready_for_goal == true) {
//goal
return ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: destinationController.rogainingCounted.value == true &&
destinationController.distanceToStart() <= 500 &&
//destination.cp == -1 &&
DestinationController.ready_for_goal == true
? () async {
destinationController.isAtGoal.value = true;
destinationController.photos.clear();
await showModalBottomSheet(
constraints: BoxConstraints.loose(
ui.Size(Get.width, Get.height * 0.75)),
context: Get.context!,
isScrollControlled: true,
builder: ((context) => CameraPage(
destination: destination,
))).whenComplete(() {
destinationController.skipGps = false;
destinationController.chekcs = 0;
destinationController.isAtGoal.value = false;
});
}
: null,
child: const Text(
"ロゲイニングを終える",
style: TextStyle(color: Colors.white),
));
} else if (distanceToDest <=
destinationController.getForcedChckinDistance(destination)) {
//start
return ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.secondary,
),
onPressed: () async {
// Check conditions to show confirmation dialog
if (destination.cp == -1 &&
destinationController.isInRog.value == false &&
destinationController.rogainingCounted.value == false) {
// Show confirmation dialog
Get.dialog(
AlertDialog(
title: const Text("確認"), //confirm
content: const Text(
"ロゲを開始すると、今までのロゲデータが全てクリアされます。本当に開始しますか?"), //are you sure
actions: <Widget>[
TextButton(
child: const Text("いいえ"), //no
onPressed: () {
Get.back(); // Close the dialog
},
),
TextButton(
child: const Text("はい"), //yes
onPressed: () async {
// Clear data and start game logic here
destinationController.isInRog.value = true;
destinationController
.resetRogaining(); // Assuming you have a method to clear data
destinationController.addToRogaining(
destinationController.currentLat,
destinationController.currentLon,
destination.location_id!,
);
saveGameState();
await ExternalService().startRogaining();
Get.back(); // Close the dialog and potentially navigate away
},
),
],
),
barrierDismissible:
false, // User must tap a button to close the dialog
);
} else {
// Existing logic for other conditions
if (destination.cp == -1) {
return;
}
Get.back();
await destinationController.callforCheckin(destination);
}
},
child: Text(
destination.cp == -1 &&
destinationController.isInRog.value == false &&
destinationController.rogainingCounted.value == false
? "ロゲ開始"
: destinationController.isInRog.value == true &&
destination.cp == -1
? "ゲーム中"
: isAlreadyCheckedIn == true
? "ゲーム中"
: "チェックイン",
style: TextStyle(color: Theme.of(context).colorScheme.onSecondary),
),
);
}
return Container();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print("to start ${destinationController.distanceToStart()}"); //print("to start ${destinationController.distanceToStart()}");
destinationController.skipGps = true; destinationController.skipGps = true;
// print('--- c use --- ${indexController.currentUser[0].values}'); // print('--- c use --- ${indexController.currentUser[0].values}');
@ -207,37 +323,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
// Finish or Goal // Finish or Goal
ElevatedButton( getActionButton(context, destination),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red),
onPressed: destinationController
.rogainingCounted.value ==
true &&
destinationController.distanceToStart() <=
500 &&
//destination.cp == -1 &&
DestinationController.ready_for_goal == true
? () async {
destinationController.isAtGoal.value = true;
destinationController.photos.clear();
await showModalBottomSheet(
constraints: BoxConstraints.loose(
ui.Size(
Get.width, Get.height * 0.75)),
context: Get.context!,
isScrollControlled: true,
builder: ((context) => CameraPage(
destination: destination,
))).whenComplete(() {
destinationController.skipGps = false;
destinationController.chekcs = 0;
destinationController.isAtGoal.value =
false;
});
}
: null,
child: const Text("ロゲイニングを終える")) // goal
,
//remove checkin //remove checkin
isAlreadyCheckedIn == true && destination.cp != -1 isAlreadyCheckedIn == true && destination.cp != -1
? ElevatedButton( ? ElevatedButton(
@ -250,7 +336,10 @@ class BottomSheetNew extends GetView<BottomSheetController> {
.deleteDestination(destination); .deleteDestination(destination);
Get.back(); Get.back();
}, },
child: const Text("チェックイン取消")) //remove checkin child: const Text(
"チェックイン取消",
style: TextStyle(color: Colors.white),
)) //remove checkin
: Container(), : Container(),
], ],
), ),
@ -265,8 +354,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
onPressed: destinationController.distanceToStart() > onPressed: destinationController.distanceToStart() >
500 500
? () async { ? () async {
print( // print(
"dist to start ${destinationController.distanceToStart()}"); // "dist to start ${destinationController.distanceToStart()}");
Get.back(); Get.back();
//print("---- go to ----"); //print("---- go to ----");
GeoJSONMultiPoint mp = indexController GeoJSONMultiPoint mp = indexController
@ -302,95 +391,6 @@ class BottomSheetNew extends GetView<BottomSheetController> {
), ),
// forced start / checkin // forced start / checkin
distanceToDest <=
destinationController
.getForcedChckinDistance(destination)
? Obx(() => ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.secondary,
),
onPressed: () async {
// Check conditions to show confirmation dialog
if (destination.cp == -1 &&
destinationController.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
false) {
// Show confirmation dialog
Get.dialog(
AlertDialog(
title: const Text("確認"), //confirm
content: const Text(
"ロゲを開始すると、今までのロゲデータが全てクリアされます。本当に開始しますか?"), //are you sure
actions: <Widget>[
TextButton(
child: const Text("いいえ"), //no
onPressed: () {
Get.back(); // Close the dialog
},
),
TextButton(
child: const Text("はい"), //yes
onPressed: () async {
// Clear data and start game logic here
destinationController
.isInRog.value = true;
destinationController
.resetRogaining(); // Assuming you have a method to clear data
destinationController
.addToRogaining(
destinationController
.currentLat,
destinationController
.currentLon,
destination.location_id!,
);
saveGameState();
await ExternalService()
.startRogaining();
Get.back(); // Close the dialog and potentially navigate away
},
),
],
),
barrierDismissible:
false, // User must tap a button to close the dialog
);
} else {
// Existing logic for other conditions
if (destination.cp == -1) {
return;
}
Get.back();
await destinationController
.callforCheckin(destination);
}
},
child: Text(
destination.cp == -1 &&
destinationController
.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
false
? "ロゲ開始"
: destinationController.isInRog.value ==
true &&
destination.cp == -1
? "ゲーム中"
: isAlreadyCheckedIn == true
? "ゲーム中"
: "チェックイン",
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onSecondary),
),
))
: Container(),
], ],
), ),
Row( Row(

View File

@ -16,14 +16,21 @@ 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/game_state_view.dart'; import 'package:rogapp/widgets/game_state_view.dart';
class MapWidget extends StatelessWidget { class MapWidget extends StatefulWidget {
MapWidget({Key? key}) : super(key: key);
@override
State<MapWidget> createState() => _MapWidgetState();
}
class _MapWidgetState extends State<MapWidget> {
final IndexController indexController = Get.find<IndexController>(); final IndexController indexController = Get.find<IndexController>();
final DestinationController destinationController = final DestinationController destinationController =
Get.find<DestinationController>(); Get.find<DestinationController>();
MapWidget({Key? key}) : super(key: key);
StreamSubscription? subscription; StreamSubscription? subscription;
Timer? _timer;
Widget getMarkerShape(GeoJSONFeature i, BuildContext context) { Widget getMarkerShape(GeoJSONFeature i, BuildContext context) {
GeoJSONMultiPoint p = i.geometry as GeoJSONMultiPoint; GeoJSONMultiPoint p = i.geometry as GeoJSONMultiPoint;
@ -153,6 +160,29 @@ class MapWidget extends StatelessWidget {
return pts; return pts;
} }
@override
void initState() {
super.initState();
_startIdleTimer();
}
void _startIdleTimer() {
_timer =
Timer(const Duration(milliseconds: (1000 * 60 * 10)), _centerMapOnUser);
}
void _resetTimer() {
_timer?.cancel();
_startIdleTimer();
}
void _centerMapOnUser() {
indexController.mapController.move(
LatLng(
destinationController.currentLat, destinationController.currentLon),
15.0);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// print( // print(
@ -174,7 +204,8 @@ class MapWidget extends StatelessWidget {
subscription = indexController.mapController.mapEventStream subscription = indexController.mapController.mapEventStream
.listen((MapEvent mapEvent) { .listen((MapEvent mapEvent) {
if (mapEvent is MapEventMoveStart) { if (mapEvent is MapEventMoveStart) {
//print(DateTime.now().toString() + ' [MapEventMoveStart] START'); // print(DateTime.now().toString() +
// ' [MapEventMoveStart] START');
// do something // do something
} }
if (mapEvent is MapEventMoveEnd) {} if (mapEvent is MapEventMoveEnd) {}
@ -191,7 +222,11 @@ class MapWidget extends StatelessWidget {
interactiveFlags: interactiveFlags:
InteractiveFlag.pinchZoom | InteractiveFlag.drag, InteractiveFlag.pinchZoom | InteractiveFlag.drag,
onPositionChanged: (MapPosition pos, isvalue) { onPositionChanged: (MapPosition pos, hasGesture) {
//print("map position changed ${pos.center!.latitude}");
if (hasGesture) {
_resetTimer();
}
indexController.currentBound = [pos.bounds!]; indexController.currentBound = [pos.bounds!];
}, },
onTap: (_, __) => popupController onTap: (_, __) => popupController