temporary update
This commit is contained in:
@ -27,6 +27,8 @@ class EntryController extends GetxController {
|
||||
final currentEntry = Rx<Entry?>(null);
|
||||
final isLoading = true.obs;
|
||||
|
||||
final activeEvents = <Event>[].obs; //有効なイベントリスト
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
@ -52,14 +54,15 @@ class EntryController extends GetxController {
|
||||
fetchTeams(),
|
||||
fetchCategories(),
|
||||
]);
|
||||
updateActiveEvents(); // イベント取得後にアクティブなイベントを更新
|
||||
if (Get.arguments != null && Get.arguments['entry'] != null) {
|
||||
currentEntry.value = Get.arguments['entry'];
|
||||
initializeEditMode(currentEntry.value!);
|
||||
} else {
|
||||
// 新規作成モードの場合、最初のイベントを選択
|
||||
if (events.isNotEmpty) {
|
||||
selectedEvent.value = events.first;
|
||||
selectedDate.value = events.first.startDatetime;
|
||||
selectedEvent.value = activeEvents.first;
|
||||
selectedDate.value = activeEvents.first.startDatetime;
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
@ -70,6 +73,10 @@ class EntryController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void updateActiveEvents() {
|
||||
final now = tz.TZDateTime.now(tz.getLocation('Asia/Tokyo'));
|
||||
activeEvents.assignAll(events.where((event) => event.deadlineDateTime.isAfter(now)));
|
||||
}
|
||||
|
||||
void initializeEditMode(Entry entry) {
|
||||
currentEntry.value = entry;
|
||||
@ -143,6 +150,7 @@ class EntryController extends GetxController {
|
||||
deadlineDateTime: deadlineDateTime,
|
||||
);
|
||||
}).toList());
|
||||
updateActiveEvents();
|
||||
} catch (e) {
|
||||
print('Error fetching events: $e');
|
||||
Get.snackbar('Error', 'Failed to fetch events');
|
||||
|
||||
@ -39,10 +39,10 @@ class EntryDetailPage extends GetView<EntryController> {
|
||||
children: [
|
||||
_buildDropdown<Event>(
|
||||
label: 'イベント',
|
||||
items: controller.events,
|
||||
items: controller.activeEvents,
|
||||
selectedId: controller.selectedEvent.value?.id,
|
||||
onChanged: (eventId) => controller.updateEvent(
|
||||
controller.events.firstWhere((e) => e.id == eventId)
|
||||
controller.activeEvents.firstWhere((e) => e.id == eventId)
|
||||
),
|
||||
getDisplayName: (event) => event.eventName,
|
||||
getId: (event) => event.id,
|
||||
|
||||
@ -7,6 +7,8 @@ import 'package:gifunavi/pages/entry/entry_controller.dart';
|
||||
import 'package:gifunavi/routes/app_pages.dart';
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
|
||||
import '../../model/entry.dart';
|
||||
|
||||
class EntryListPage extends GetView<EntryController> {
|
||||
const EntryListPage({super.key});
|
||||
|
||||
@ -28,11 +30,35 @@ class EntryListPage extends GetView<EntryController> {
|
||||
child: Text('表示するエントリーがありません。'),
|
||||
);
|
||||
}
|
||||
|
||||
final sortedEntries = controller.entries.toList()
|
||||
..sort((b, a) => a.date!.compareTo(b.date!));
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: controller.entries.length,
|
||||
itemCount: sortedEntries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final entry = controller.entries[index];
|
||||
final entry = sortedEntries[index];
|
||||
final now = DateTime.now();
|
||||
final isEntryInFuture = _compareDatesOnly(entry.date!, now) >= 0;
|
||||
|
||||
//final isEntryInFuture = entry.date!.isAfter(now) || entry.date!.isAtSameMomentAs(now);
|
||||
|
||||
Widget? leadingIcon;
|
||||
if (!isEntryInFuture) {
|
||||
if (entry.hasParticipated) {
|
||||
if (entry.hasGoaled) {
|
||||
leadingIcon =
|
||||
const Icon(Icons.check_circle, color: Colors.green);
|
||||
} else {
|
||||
leadingIcon = const Icon(Icons.warning, color: Colors.yellow);
|
||||
}
|
||||
} else {
|
||||
leadingIcon = const Icon(Icons.cancel, color: Colors.red);
|
||||
}
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
leading: leadingIcon,
|
||||
title: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@ -49,9 +75,16 @@ class EntryListPage extends GetView<EntryController> {
|
||||
Text('ゼッケン: ${entry.zekkenNumber ?? "未設定"}'),
|
||||
],
|
||||
),
|
||||
onTap: () =>
|
||||
onTap: () {
|
||||
if (isEntryInFuture) {
|
||||
Get.toNamed(AppPages.ENTRY_DETAIL,
|
||||
arguments: {'mode': 'edit', 'entry': entry}),
|
||||
arguments: {'mode': 'edit', 'entry': entry});
|
||||
} else if (entry.hasParticipated) {
|
||||
Get.toNamed(AppPages.EVENT_RESULT, arguments: {'entry': entry});
|
||||
} else {
|
||||
_showNonParticipationDialog(context, entry);
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -59,6 +92,11 @@ class EntryListPage extends GetView<EntryController> {
|
||||
);
|
||||
}
|
||||
|
||||
// 新しく追加するメソッド
|
||||
int _compareDatesOnly(DateTime a, DateTime b) {
|
||||
return DateTime(a.year, a.month, a.day).compareTo(DateTime(b.year, b.month, b.day));
|
||||
}
|
||||
|
||||
String _formatDate(DateTime? date) {
|
||||
if (date == null) {
|
||||
return '日時未設定';
|
||||
@ -66,6 +104,26 @@ class EntryListPage extends GetView<EntryController> {
|
||||
final jstDate = tz.TZDateTime.from(date, tz.getLocation('Asia/Tokyo'));
|
||||
return DateFormat('yyyy-MM-dd').format(jstDate);
|
||||
}
|
||||
|
||||
void _showNonParticipationDialog(BuildContext context, Entry entry) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(entry.event.eventName),
|
||||
content: Text('${_formatDate(entry.date)}\n\n不参加でした'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('閉じる'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EntryListPage_old extends GetView<EntryController> {
|
||||
@ -85,7 +143,7 @@ class EntryListPage_old extends GetView<EntryController> {
|
||||
),
|
||||
body: Obx((){
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
return const Center(child: CircularProgressIndicator()); // EntryList
|
||||
}
|
||||
|
||||
// エントリーを日付昇順にソート
|
||||
|
||||
155
lib/pages/entry/event_result_page.dart
Normal file
155
lib/pages/entry/event_result_page.dart
Normal file
@ -0,0 +1,155 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:gifunavi/model/entry.dart';
|
||||
import 'package:gifunavi/pages/gps/gps_controller.dart';
|
||||
import 'package:gifunavi/pages/history/history_controller.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:gifunavi/pages/gps/gps_controller.dart';
|
||||
import 'package:gifunavi/pages/history/history_controller.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class EventResultPage extends StatefulWidget {
|
||||
final Entry entry;
|
||||
|
||||
const EventResultPage({super.key, required this.entry});
|
||||
|
||||
@override
|
||||
State<EventResultPage> createState() => _EventResultPageState();
|
||||
|
||||
}
|
||||
|
||||
class _EventResultPageState extends State<EventResultPage> {
|
||||
late GpsController gpsController;
|
||||
late HistoryController historyController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
gpsController = Get.put(GpsController());
|
||||
historyController = Get.put(HistoryController());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultTabController(
|
||||
length: 3,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('${widget.entry.event.eventName} 結果'),
|
||||
bottom: const TabBar(
|
||||
tabs: [
|
||||
Tab(text: 'ランキング'),
|
||||
Tab(text: '走行経路'),
|
||||
Tab(text: 'チェックポイント'),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: TabBarView(
|
||||
children: [
|
||||
_buildFutureTab(), //_buildRankingTab(),
|
||||
_buildFutureTab(), //_buildRouteTab(),
|
||||
_buildFutureTab(), //_buildCheckpointTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFutureTab() {
|
||||
// ランキングの表示ロジックを実装
|
||||
return const Center(child: Text('近日公開予定(当面、HPを参照ください。)'));
|
||||
}
|
||||
|
||||
|
||||
Widget _buildRankingTab() {
|
||||
// ランキングの表示ロジックを実装
|
||||
return const Center(child: Text('ランキング表示(実装が必要)'));
|
||||
}
|
||||
|
||||
Widget _buildRouteTab() {
|
||||
return Obx(() {
|
||||
if (gpsController.gpsData.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return FlutterMap(
|
||||
options: MapOptions(
|
||||
center: LatLng(gpsController.gpsData[0].lat, gpsController.gpsData[0].lon),
|
||||
zoom: 13.0,
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
subdomains: ['a', 'b', 'c'],
|
||||
),
|
||||
PolylineLayer(
|
||||
polylines: [
|
||||
Polyline(
|
||||
points: gpsController.gpsData
|
||||
.map((data) => LatLng(data.lat, data.lon))
|
||||
.toList(),
|
||||
color: Colors.red,
|
||||
strokeWidth: 3.0,
|
||||
),
|
||||
],
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: gpsController.gpsData
|
||||
.map((data) => Marker(
|
||||
width: 80.0,
|
||||
height: 80.0,
|
||||
point: LatLng(data.lat, data.lon),
|
||||
child: const Icon(Icons.location_on, color: Colors.red),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildCheckpointTab() {
|
||||
return Obx(() {
|
||||
if (historyController.checkpoints.isEmpty) {
|
||||
return const Center(child: Text('チェックポイント履歴がありません'));
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: historyController.checkpoints.length,
|
||||
itemBuilder: (context, index) {
|
||||
final checkpoint = historyController.checkpoints[index];
|
||||
return ListTile(
|
||||
title: Text('CP ${checkpoint.cp_number ?? 'Unknown'}'),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('通過時刻: ${_formatDateTime(checkpoint.checkintime)}'),
|
||||
Text('チーム: ${checkpoint.team_name ?? 'Unknown'}'),
|
||||
Text('イベント: ${checkpoint.event_code ?? 'Unknown'}'),
|
||||
],
|
||||
),
|
||||
leading: checkpoint.image != null
|
||||
? Image.file(
|
||||
File(checkpoint.image!),
|
||||
width: 50,
|
||||
height: 50,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
print('Error loading image: $error');
|
||||
return const Icon(Icons.error);
|
||||
},
|
||||
)
|
||||
: const Icon(Icons.image_not_supported),
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String _formatDateTime(int? microsecondsSinceEpoch) {
|
||||
if (microsecondsSinceEpoch == null) return 'Unknown';
|
||||
final dateTime = DateTime.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch);
|
||||
return DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
|
||||
}
|
||||
Reference in New Issue
Block a user