Team,Member, Entryの登録まで完了
This commit is contained in:
@ -3,6 +3,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rogapp/pages/entry/entry_controller.dart';
|
||||
import 'package:rogapp/model/event.dart';
|
||||
import 'package:rogapp/model/category.dart';
|
||||
import 'package:rogapp/model/team.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class EntryDetailPage extends GetView<EntryController> {
|
||||
@override
|
||||
@ -11,52 +15,121 @@ class EntryDetailPage extends GetView<EntryController> {
|
||||
final mode = Get.arguments['mode'] as String? ?? 'new';
|
||||
final entry = Get.arguments['entry'];
|
||||
|
||||
if (mode == 'edit' && entry != null) {
|
||||
controller.initializeEditMode(entry);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(mode == 'new' ? 'エントリー登録' : 'エントリー詳細'),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Obx(() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DropdownButtonFormField(
|
||||
decoration: InputDecoration(labelText: 'イベント'),
|
||||
value: controller.selectedEvent.value,
|
||||
items: controller.events.map((event) => DropdownMenuItem(
|
||||
value: event,
|
||||
child: Text(event.eventName),
|
||||
)).toList(),
|
||||
onChanged: (value) => controller.updateEvent(value),
|
||||
body: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildDropdown<Event>(
|
||||
label: 'イベント',
|
||||
items: controller.events,
|
||||
selectedId: controller.selectedEvent.value?.id,
|
||||
onChanged: (eventId) => controller.updateEvent(
|
||||
controller.events.firstWhere((e) => e.id == eventId)
|
||||
),
|
||||
getDisplayName: (event) => event.eventName,
|
||||
getId: (event) => event.id,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
_buildDropdown<Team>(
|
||||
label: 'チーム',
|
||||
items: controller.teams,
|
||||
selectedId: controller.selectedTeam.value?.id,
|
||||
onChanged: (teamId) => controller.updateTeam(
|
||||
controller.teams.firstWhere((t) => t.id == teamId)
|
||||
),
|
||||
getDisplayName: (team) => team.teamName,
|
||||
getId: (team) => team.id,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
_buildDropdown<NewCategory>(
|
||||
label: 'カテゴリ',
|
||||
items: controller.categories,
|
||||
selectedId: controller.selectedCategory.value?.id,
|
||||
onChanged: (categoryId) => controller.updateCategory(
|
||||
controller.categories.firstWhere((c) => c.id == categoryId)
|
||||
),
|
||||
getDisplayName: (category) => category.categoryName,
|
||||
getId: (category) => category.id,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
ListTile(
|
||||
title: Text('日付'),
|
||||
subtitle: Text(
|
||||
controller.selectedDate.value != null
|
||||
? DateFormat('yyyy-MM-dd').format(controller.selectedDate.value!)
|
||||
: '日付を選択してください',
|
||||
),
|
||||
onTap: () async {
|
||||
if (controller.selectedEvent.value == null) {
|
||||
Get.snackbar('Error', 'Please select an event first');
|
||||
return;
|
||||
}
|
||||
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,
|
||||
);
|
||||
if (picked != null) {
|
||||
controller.updateDate(picked);
|
||||
}
|
||||
},
|
||||
),
|
||||
SizedBox(height: 32),
|
||||
ElevatedButton(
|
||||
child: Text(mode == 'new' ? 'エントリーを作成' : 'エントリーを更新'),
|
||||
onPressed: () {
|
||||
if (mode == 'new') {
|
||||
controller.createEntry();
|
||||
} else {
|
||||
controller.updateEntry();
|
||||
}
|
||||
},
|
||||
),
|
||||
if (mode == 'edit' && controller.isOwner())
|
||||
ElevatedButton(
|
||||
child: Text('エントリーを削除'),
|
||||
onPressed: () => controller.deleteEntry(),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
|
||||
),
|
||||
],
|
||||
),
|
||||
DropdownButtonFormField(
|
||||
decoration: InputDecoration(labelText: 'チーム'),
|
||||
value: controller.selectedTeam.value,
|
||||
items: controller.teams.map((team) => DropdownMenuItem(
|
||||
value: team,
|
||||
child: Text(team.teamName),
|
||||
)).toList(),
|
||||
onChanged: (value) => controller.updateTeam(value),
|
||||
),
|
||||
DropdownButtonFormField(
|
||||
decoration: InputDecoration(labelText: 'カテゴリ'),
|
||||
value: controller.selectedCategory.value,
|
||||
items: controller.categories.map((category) => DropdownMenuItem(
|
||||
value: category,
|
||||
child: Text(category.categoryName),
|
||||
)).toList(),
|
||||
onChanged: (value) => controller.updateCategory(value),
|
||||
),
|
||||
// 日付選択ウィジェットを追加
|
||||
if (mode == 'edit' && controller.isOwner())
|
||||
ElevatedButton(
|
||||
child: Text('エントリーを削除'),
|
||||
onPressed: () => controller.deleteEntry(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdown<T>({
|
||||
required String label,
|
||||
required List<T> items,
|
||||
required int? selectedId,
|
||||
required void Function(int?) onChanged,
|
||||
required String Function(T) getDisplayName,
|
||||
required int Function(T) getId,
|
||||
}) {
|
||||
return DropdownButtonFormField<int>(
|
||||
decoration: InputDecoration(labelText: label),
|
||||
value: selectedId,
|
||||
items: items.map((item) => DropdownMenuItem<int>(
|
||||
value: getId(item),
|
||||
child: Text(getDisplayName(item)),
|
||||
)).toList(),
|
||||
onChanged: onChanged,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user