ほぼ完成:QRcodeトライ
This commit is contained in:
@ -69,6 +69,7 @@ class EntryController extends GetxController {
|
||||
|
||||
|
||||
void initializeEditMode(Entry entry) {
|
||||
currentEntry.value = entry;
|
||||
selectedEvent.value = entry.event;
|
||||
selectedTeam.value = entry.team;
|
||||
selectedCategory.value = entry.category;
|
||||
@ -169,10 +170,14 @@ class EntryController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> updateEntry() async {
|
||||
if (currentEntry.value == null) return;
|
||||
if (currentEntry.value == null) {
|
||||
Get.snackbar('Error', 'No entry selected for update');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final updatedEntry = await _apiService.updateEntry(
|
||||
currentEntry.value!.id,
|
||||
currentEntry.value!.team.id,
|
||||
selectedEvent.value!.id,
|
||||
selectedCategory.value!.id,
|
||||
selectedDate.value!,
|
||||
@ -189,7 +194,10 @@ class EntryController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> deleteEntry() async {
|
||||
if (currentEntry.value == null) return;
|
||||
if (currentEntry.value == null) {
|
||||
Get.snackbar('Error', 'No entry selected for deletion');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await _apiService.deleteEntry(currentEntry.value!.id);
|
||||
entries.removeWhere((entry) => entry.id == currentEntry.value!.id);
|
||||
|
||||
@ -90,21 +90,40 @@ class EntryDetailPage extends GetView<EntryController> {
|
||||
},
|
||||
),
|
||||
SizedBox(height: 32),
|
||||
ElevatedButton(
|
||||
child: Text(mode == 'new' ? 'エントリーを作成' : 'エントリーを更新'),
|
||||
onPressed: () {
|
||||
if (mode == 'new') {
|
||||
controller.createEntry();
|
||||
} else {
|
||||
controller.updateEntry();
|
||||
}
|
||||
},
|
||||
),
|
||||
if (mode == 'edit' && controller.isOwner())
|
||||
if (mode == 'new')
|
||||
ElevatedButton(
|
||||
child: Text('エントリーを削除'),
|
||||
onPressed: () => controller.deleteEntry(),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
|
||||
child: Text('エントリーを作成'),
|
||||
onPressed: () => controller.createEntry(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,
|
||||
minimumSize: Size(double.infinity, 50),
|
||||
),
|
||||
)
|
||||
else
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
child: Text('エントリーを削除'),
|
||||
onPressed: () => controller.deleteEntry(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red,
|
||||
minimumSize: Size(0, 50),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
child: Text('エントリーを更新'),
|
||||
onPressed: () => controller.updateEntry(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.lightBlue,
|
||||
minimumSize: Size(0, 50),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -18,18 +18,30 @@ class EntryListPage extends GetView<EntryController> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Obx(() => ListView.builder(
|
||||
itemCount: controller.entries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final entry = controller.entries[index];
|
||||
return ListTile(
|
||||
title: Text(entry.event?.eventName ?? 'イベント未設定'),
|
||||
subtitle: Text('${entry.team?.teamName ?? 'チーム未設定'} - ${entry.category?.categoryName ?? 'カテゴリ未設定'}'),
|
||||
trailing: Text(entry.date?.toString().substring(0, 10) ?? '日付未設定'),
|
||||
onTap: () => Get.toNamed(AppPages.ENTRY_DETAIL, arguments: {'mode': 'edit', 'entry': entry}),
|
||||
);
|
||||
},
|
||||
)),
|
||||
body: Obx((){
|
||||
// エントリーを日付昇順にソート
|
||||
final sortedEntries = controller.entries.toList()
|
||||
..sort((a, b) => (a.date ?? DateTime(0)).compareTo(b.date ?? DateTime(0)));
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: sortedEntries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final entry = sortedEntries[index];
|
||||
return ListTile(
|
||||
title: Text(entry.event?.eventName ?? 'イベント未設定'),
|
||||
subtitle: Text(
|
||||
'${entry.team?.teamName ?? 'チーム未設定'} - ${entry.category
|
||||
?.categoryName ?? 'カテゴリ未設定'}'),
|
||||
trailing: Text(
|
||||
entry.date?.toString().substring(0, 10) ?? '日付未設定'),
|
||||
onTap: () =>
|
||||
Get.toNamed(AppPages.ENTRY_DETAIL,
|
||||
arguments: {'mode': 'edit', 'entry': entry}),
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user