Semi Final 7th Aug 2024
This commit is contained in:
@ -9,6 +9,8 @@ import 'package:rogapp/model/category.dart';
|
||||
import 'package:rogapp/services/api_service.dart';
|
||||
|
||||
import '../index/index_controller.dart';
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
import 'package:timezone/data/latest.dart' as tz;
|
||||
|
||||
class EntryController extends GetxController {
|
||||
late ApiService _apiService;
|
||||
@ -92,8 +94,10 @@ class EntryController extends GetxController {
|
||||
|
||||
void updateTeam(Team? value) => selectedTeam.value = value;
|
||||
void updateCategory(NewCategory? value) => selectedCategory.value = value;
|
||||
void updateDate(DateTime value) => selectedDate.value = value;
|
||||
|
||||
//void updateDate(DateTime value) => selectedDate.value = value;
|
||||
void updateDate(DateTime value) {
|
||||
selectedDate.value = tz.TZDateTime.from(value, tz.getLocation('Asia/Tokyo'));
|
||||
}
|
||||
/*
|
||||
void updateDate(DateTime value){
|
||||
selectedDate.value = DateFormat('yyyy-MM-dd').format(value!) as DateTime?;
|
||||
@ -201,6 +205,7 @@ class EntryController extends GetxController {
|
||||
selectedEvent.value!.id,
|
||||
selectedCategory.value!.id,
|
||||
selectedDate.value!,
|
||||
currentEntry.value!.zekkenNumber,
|
||||
);
|
||||
final index = entries.indexWhere((entry) => entry.id == updatedEntry.id);
|
||||
if (index != -1) {
|
||||
|
||||
@ -8,6 +8,9 @@ import 'package:rogapp/model/category.dart';
|
||||
import 'package:rogapp/model/team.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
import 'package:timezone/data/latest.dart' as tz;
|
||||
|
||||
class EntryDetailPage extends GetView<EntryController> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -70,7 +73,7 @@ class EntryDetailPage extends GetView<EntryController> {
|
||||
title: Text('日付'),
|
||||
subtitle: Text(
|
||||
controller.selectedDate.value != null
|
||||
? DateFormat('yyyy-MM-dd').format(controller.selectedDate.value!)
|
||||
? DateFormat('yyyy-MM-dd').format(tz.TZDateTime.from(controller.selectedDate.value!, tz.getLocation('Asia/Tokyo')))
|
||||
: '日付を選択してください',
|
||||
),
|
||||
onTap: () async {
|
||||
@ -78,14 +81,22 @@ class EntryDetailPage extends GetView<EntryController> {
|
||||
Get.snackbar('Error', 'Please select an event first');
|
||||
return;
|
||||
}
|
||||
final tz.TZDateTime now = tz.TZDateTime.now(tz.getLocation('Asia/Tokyo'));
|
||||
final tz.TZDateTime eventStart = tz.TZDateTime.from(controller.selectedEvent.value!.startDatetime, tz.getLocation('Asia/Tokyo'));
|
||||
final tz.TZDateTime eventEnd = tz.TZDateTime.from(controller.selectedEvent.value!.endDatetime, tz.getLocation('Asia/Tokyo'));
|
||||
|
||||
final tz.TZDateTime initialDate = controller.selectedDate.value != null
|
||||
? tz.TZDateTime.from(controller.selectedDate.value!, tz.getLocation('Asia/Tokyo'))
|
||||
: (now.isAfter(eventStart) ? now : eventStart);
|
||||
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: controller.selectedDate.value ?? controller.selectedEvent.value!.startDatetime,
|
||||
firstDate: controller.selectedEvent.value!.startDatetime,
|
||||
lastDate: controller.selectedEvent.value!.endDatetime,
|
||||
initialDate: initialDate,
|
||||
firstDate: eventStart,
|
||||
lastDate: eventEnd,
|
||||
);
|
||||
if (picked != null) {
|
||||
controller.updateDate(picked);
|
||||
controller.updateDate(tz.TZDateTime.from(picked, tz.getLocation('Asia/Tokyo')));
|
||||
}
|
||||
},
|
||||
),
|
||||
@ -96,6 +107,7 @@ class EntryDetailPage extends GetView<EntryController> {
|
||||
onPressed: () => controller.createEntry(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: Size(double.infinity, 50),
|
||||
),
|
||||
)
|
||||
@ -108,6 +120,7 @@ class EntryDetailPage extends GetView<EntryController> {
|
||||
onPressed: () => controller.deleteEntry(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: Size(0, 50),
|
||||
),
|
||||
),
|
||||
@ -119,6 +132,7 @@ class EntryDetailPage extends GetView<EntryController> {
|
||||
onPressed: () => controller.updateEntry(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.lightBlue,
|
||||
foregroundColor: Colors.white,
|
||||
minimumSize: Size(0, 50),
|
||||
),
|
||||
),
|
||||
|
||||
@ -5,6 +5,7 @@ import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:rogapp/pages/entry/entry_controller.dart';
|
||||
import 'package:rogapp/routes/app_pages.dart';
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
|
||||
class EntryListPage extends GetView<EntryController> {
|
||||
@override
|
||||
@ -12,6 +13,12 @@ class EntryListPage extends GetView<EntryController> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('エントリー管理'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.add),
|
||||
onPressed: () => Get.toNamed(AppPages.ENTRY_DETAIL, arguments: {'mode': 'new'}),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Obx(() {
|
||||
if (controller.entries.isEmpty) {
|
||||
@ -54,7 +61,8 @@ class EntryListPage extends GetView<EntryController> {
|
||||
if (date == null) {
|
||||
return '日時未設定';
|
||||
}
|
||||
return DateFormat('yyyy-MM-dd').format(date);
|
||||
final jstDate = tz.TZDateTime.from(date, tz.getLocation('Asia/Tokyo'));
|
||||
return DateFormat('yyyy-MM-dd').format(jstDate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@ import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:rogapp/services/api_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
import 'package:timezone/data/latest.dart' as tz;
|
||||
|
||||
class EventEntriesController extends GetxController {
|
||||
final ApiService _apiService = Get.find<ApiService>();
|
||||
@ -14,9 +16,12 @@ class EventEntriesController extends GetxController {
|
||||
final filteredEntries = <Entry>[].obs;
|
||||
final showTodayEntries = true.obs;
|
||||
|
||||
static bool _timezoneInitialized = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_initializeTimezone();
|
||||
// DestinationControllerが登録されていない場合に備えて、lazyPutを使用
|
||||
Get.lazyPut<DestinationController>(() => DestinationController(), fenix: true);
|
||||
_destinationController = Get.find<DestinationController>();
|
||||
@ -24,6 +29,13 @@ class EventEntriesController extends GetxController {
|
||||
fetchEntries();
|
||||
}
|
||||
|
||||
void _initializeTimezone() {
|
||||
if (!_timezoneInitialized) {
|
||||
tz.initializeTimeZones();
|
||||
_timezoneInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchEntries() async {
|
||||
try {
|
||||
final fetchedEntries = await _apiService.getEntries();
|
||||
@ -44,6 +56,16 @@ class EventEntriesController extends GetxController {
|
||||
}
|
||||
|
||||
void filterEntriesForToday() {
|
||||
final now = tz.TZDateTime.now(tz.getLocation('Asia/Tokyo'));
|
||||
filteredEntries.assignAll(entries.where((entry) {
|
||||
final entryDate = tz.TZDateTime.from(entry.date!, tz.getLocation('Asia/Tokyo'));
|
||||
return entryDate.year == now.year &&
|
||||
entryDate.month == now.month &&
|
||||
entryDate.day == now.day;
|
||||
}));
|
||||
}
|
||||
|
||||
void filterEntriesForToday_old() {
|
||||
final now = DateTime.now();
|
||||
filteredEntries.assignAll(entries.where((entry) =>
|
||||
entry.date?.year == now.year &&
|
||||
@ -66,10 +88,12 @@ class EventEntriesController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> joinEvent(Entry entry) async {
|
||||
final now = DateTime.now();
|
||||
bool isToday = entry.date?.year == now.year &&
|
||||
entry.date?.month == now.month &&
|
||||
entry.date?.day == now.day;
|
||||
//final now = DateTime.now();
|
||||
final now = tz.TZDateTime.now(tz.getLocation('Asia/Tokyo'));
|
||||
final entryDate = tz.TZDateTime.from(entry.date!, tz.getLocation('Asia/Tokyo'));
|
||||
bool isToday = entryDate.year == now.year &&
|
||||
entryDate.month == now.month &&
|
||||
entryDate.day == now.day;
|
||||
|
||||
_indexController.setReferenceMode(!isToday);
|
||||
_indexController.setSelectedEventName(entry.event.eventName);
|
||||
|
||||
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:rogapp/pages/entry/event_entries_controller.dart';
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
|
||||
class EventEntriesPage_old extends GetView<EventEntriesController> {
|
||||
@override
|
||||
@ -96,7 +97,8 @@ class EventEntriesPage extends GetView<EventEntriesController> {
|
||||
if (date == null) {
|
||||
return '日時未設定';
|
||||
}
|
||||
return DateFormat('yyyy-MM-dd').format(date);
|
||||
final jstDate = tz.TZDateTime.from(date, tz.getLocation('Asia/Tokyo'));
|
||||
return DateFormat('yyyy-MM-dd').format(jstDate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user