Files
rog_app/lib/widgets/bottom_sheets/bottom_sheet_start.dart

102 lines
4.3 KiB
Dart
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/widgets/bottom_sheets/bottom_sheet_base.dart';
import 'package:rogapp/main.dart';
import 'package:rogapp/services/external_service.dart';
class BottomSheetStart extends BottomSheetBase {
BottomSheetStart({super.key, required super.destination});
final DestinationController destinationController = Get.find<DestinationController>();
@override
List<Widget> buildWidgets(BuildContext context) {
// super.buildWidgets(context) を継承して、追加のウィジェットをリストに組み込む
return [
...super.buildWidgets(context),
ElevatedButton(
onPressed: destinationController.distanceToStart() <= 100
? () async {
// ボタンがタップされた際の処理
// Check conditions to show confirmation dialog
if (destinationController.isInRog.value == false &&
(destinationController.distanceToStart() <= 500 || destinationController.isGpsSignalWeak() ) && //追加 Akira 2024-4-5
(destination.cp == -1 || destination.cp == 0 ) &&
destinationController.rogainingCounted.value == false) {
// ロゲがまだ開始されていない: destinationController.isInRog.value == false
// かつ (開始ポイントまでの距離が 500m 以内 destinationController.distanceToStart() <= 500
// または GPS信号強度が弱い場合 destinationController.isGpsSignalWeak()
// ) かつ
// そのポイントのCP番号が -1 または 0 の場合:
// かつ ポイントがカウントされていない場合 destinationController.rogainingCounted.value=false
// にロゲイニング開始ができる。
//
print("counted ${destinationController.rogainingCounted.value}");
// 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();
destinationController.addToRogaining(
destinationController.currentLat,
destinationController.currentLon,
destination.location_id!,
);
saveGameState(); // main.dart 参照 // ゲームの状態を保存する。
await ExternalService().startRogaining();
Get.back(); // Close the dialog and potentially navigate away
},
),
],
),
barrierDismissible:
false, // User must tap a button to close the dialog
);
} else if (destinationController.isInRog.value == true &&
destination.cp != -1 && destination.cp != 0 ) {
//print("counted ${destinationController.rogainingCounted.value}");
// Existing logic for other conditions
Get.back();
await destinationController.callforCheckin(destination);
} else {
return;
}
}
: null,
child: Obx(
() => Text(
destinationController.isInRog.value ? '競技中' : 'ロゲ開始',
),
),
),
];
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: buildWidgets(context),
),
);
}
}