Snackbar の色を変更。ロゲ開始時のエラーを回避。

This commit is contained in:
2024-04-27 10:48:21 +09:00
parent 72267f29bb
commit aada6262fe
21 changed files with 253 additions and 742 deletions

View File

@ -1,4 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:intl/intl.dart';
@ -32,6 +33,8 @@ class ExternalService {
Future<Map<String, dynamic>> startRogaining() async {
final IndexController indexController = Get.find<IndexController>();
debugPrint("== startRogaining ==");
Map<String, dynamic> res = {};
int userId = indexController.currentUser[0]["user"]["id"];
@ -42,6 +45,7 @@ class ExternalService {
if (indexController.connectionStatusName.value != "wifi" &&
indexController.connectionStatusName.value != "mobile") {
debugPrint("== No network ==");
DatabaseHelper db = DatabaseHelper.instance;
Rog rog = Rog(
id: 1,
@ -54,6 +58,8 @@ class ExternalService {
rog_action_type: 0);
db.insertRogaining(rog);
} else {
debugPrint("== startRogaining processing==");
String url = 'https://rogaining.sumasen.net/gifuroge/start_from_rogapp';
//print('++++++++$url');
final http.Response response = await http.post(
@ -94,6 +100,8 @@ class ExternalService {
if (imageurl != null) {
if (indexController.connectionStatusName.value != "wifi" &&
indexController.connectionStatusName.value != "mobile") {
debugPrint("== checkin without network ==");
DatabaseHelper db = DatabaseHelper.instance;
Rog rog = Rog(
id: 1,
@ -107,6 +115,7 @@ class ExternalService {
);
db.insertRogaining(rog);
} else {
debugPrint("== Normal Check in ===");
String serverUrl = ConstValues.currentServer();
String url1 = "$serverUrl/api/checkinimage/";
final im1Bytes = File(imageurl).readAsBytesSync();
@ -167,16 +176,26 @@ class ExternalService {
if (response2.statusCode == 200) {
res = json.decode(utf8.decode(response2.bodyBytes));
//print('----checkin res _res : $res ----');
if (res["status"] == "ERROR") {
Get.snackbar("エラーがおきました", res["detail"]);
if (res["status"] == "ERROR" && cp>0 ) {
// スタート・ゴールはエラー除外。
Get.snackbar("エラーがおきました", res["detail"],
backgroundColor: Colors.red,
colorText: Colors.white
);
}
}
} else {
Get.snackbar("サーバーエラーがおきました", "サーバーと通信できませんでした");
Get.snackbar("サーバーエラーがおきました", "サーバーと通信できませんでした",
backgroundColor: Colors.red,
colorText: Colors.white
);
}
} catch( e ) {
print('Error in makeCheckpoint: $e');
Get.snackbar("通信エラーがおきました", "サーバーと通信できませんでした");
Get.snackbar("通信エラーがおきました", "サーバーと通信できませんでした",
backgroundColor: Colors.red,
colorText: Colors.white
);
}
}
} else {
@ -234,6 +253,8 @@ class ExternalService {
final DestinationController destinationController =
Get.find<DestinationController>();
debugPrint("== goal Rogaining ==");
//if(indexController.connectionStatusName != "wifi" && indexController.connectionStatusName != "mobile"){
DatabaseHelper db = DatabaseHelper.instance;
Rog rog = Rog(