temporary update

This commit is contained in:
2024-09-08 18:16:51 +09:00
parent 2c0bb06e74
commit e37c4ceebd
32 changed files with 1235 additions and 1189 deletions

View File

@ -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
}
// エントリーを日付昇順にソート