Fixed Android issues

This commit is contained in:
2024-09-10 16:16:04 +09:00
parent 8ed6a4e8bf
commit 7976f4c75b
5 changed files with 255 additions and 108 deletions

View File

@ -7,6 +7,7 @@ import 'package:gifunavi/model/event.dart';
import 'package:gifunavi/model/category.dart';
import 'package:gifunavi/model/team.dart';
import 'package:intl/intl.dart';
import 'package:gifunavi/widgets/error_widget.dart';
import 'package:timezone/timezone.dart' as tz;
@ -31,36 +32,72 @@ class EntryDetailPage extends GetView<EntryController> {
if (controller.isLoading.value) {
return const Center(child: CircularProgressIndicator());
}
return Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildDropdown<Event>(
label: 'イベント',
items: controller.activeEvents,
selectedId: controller.selectedEvent.value?.id,
if (controller.hasError.value) {
return CustomErrorWidget(
errorMessage: controller.errorMessage.value,
onRetry: () => controller.loadInitialData(),
);
}
try {
return Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildDropdown<Event>(
label: 'イベント',
items: controller.activeEvents,
selectedId: controller.selectedEvent.value?.id,
onChanged: (eventId) {
final event = controller.activeEvents.firstWhereOrNull((
e) => e.id == eventId);
if (event != null) {
controller.updateEvent(event);
} else {
print('Event with id $eventId not found');
// 必要に応じてエラー処理を追加
}
},
/*
onChanged: (eventId) => controller.updateEvent(
controller.activeEvents.firstWhere((e) => e.id == eventId)
),
getDisplayName: (event) => event.eventName,
getId: (event) => event.id,
),
const SizedBox(height: 16),
_buildDropdown<Team>(
label: 'チーム',
items: controller.teams,
selectedId: controller.selectedTeam.value?.id,
*/
getDisplayName: (event) => event.eventName,
getId: (event) => event.id,
),
const SizedBox(height: 16),
_buildDropdown<Team>(
label: 'チーム',
items: controller.teams,
selectedId: controller.selectedTeam.value?.id,
onChanged: (teamId) {
final team = controller.teams.firstWhereOrNull((t) =>
t.id == teamId);
if (team != null) {
controller.updateTeam(team);
} else {
print('Team with id $teamId not found');
// 必要に応じてエラー処理を追加
}
},
/*
onChanged: (teamId) => controller.updateTeam(
controller.teams.firstWhere((t) => t.id == teamId)
),
getDisplayName: (team) => team.teamName,
getId: (team) => team.id,
),
const SizedBox(height: 16),
_buildCategoryDropdown(),
/*
*/
getDisplayName: (team) => team.teamName,
getId: (team) => team.id,
),
const SizedBox(height: 16),
_buildCategoryDropdown(),
/*
_buildDropdown<NewCategory>()
label: 'カテゴリ',
items: controller.categories,
@ -73,84 +110,104 @@ class EntryDetailPage extends GetView<EntryController> {
),
*/
const SizedBox(height: 16),
ListTile(
title: const Text('日付'),
subtitle: Text(
controller.selectedDate.value != null
? DateFormat('yyyy-MM-dd').format(tz.TZDateTime.from(controller.selectedDate.value!, tz.getLocation('Asia/Tokyo')))
: '日付を選択してください',
),
onTap: () async {
if (controller.selectedEvent.value == null) {
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 tz.TZDateTime firstDate = now.isAfter(eventStart) ? now : eventStart;
final DateTime? picked = await showDatePicker(
context: context,
initialDate: initialDate.isAfter(firstDate) ? initialDate : firstDate,
firstDate: firstDate,
lastDate: eventEnd,
);
if (picked != null) {
controller.updateDate(tz.TZDateTime.from(picked, tz.getLocation('Asia/Tokyo')));
}
},
),
const SizedBox(height: 32),
if (mode == 'new')
ElevatedButton(
onPressed: () => controller.createEntry(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
minimumSize: const Size(double.infinity, 50),
const SizedBox(height: 16),
ListTile(
title: const Text('日付'),
subtitle: Text(
controller.selectedDate.value != null
? DateFormat('yyyy-MM-dd').format(tz.TZDateTime.from(
controller.selectedDate.value!,
tz.getLocation('Asia/Tokyo')))
: '日付を選択してください',
),
child: const Text('エントリーを作成'),
)
else
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () => controller.deleteEntry(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
minimumSize: const Size(0, 50),
),
child: const Text('エントリーを削除'),
),
),
const SizedBox(width: 16),
Expanded(
child: ElevatedButton(
onPressed: () => controller.updateEntry(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.lightBlue,
foregroundColor: Colors.white,
minimumSize: const Size(0, 50),
),
child: const Text('エントリーを更新'),
),
),
],
onTap: () async {
if (controller.selectedEvent.value == null) {
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 tz.TZDateTime firstDate = now.isAfter(eventStart)
? now
: eventStart;
final DateTime? picked = await showDatePicker(
context: context,
initialDate: initialDate.isAfter(firstDate)
? initialDate
: firstDate,
firstDate: firstDate,
lastDate: eventEnd,
);
if (picked != null) {
controller.updateDate(tz.TZDateTime.from(
picked, tz.getLocation('Asia/Tokyo')));
}
},
),
],
const SizedBox(height: 32),
if (mode == 'new')
ElevatedButton(
onPressed: () => controller.createEntry(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
minimumSize: const Size(double.infinity, 50),
),
child: const Text('エントリーを作成'),
)
else
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () => controller.deleteEntry(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
minimumSize: const Size(0, 50),
),
child: const Text('エントリーを削除'),
),
),
const SizedBox(width: 16),
Expanded(
child: ElevatedButton(
onPressed: () => controller.updateEntry(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.lightBlue,
foregroundColor: Colors.white,
minimumSize: const Size(0, 50),
),
child: const Text('エントリーを更新'),
),
),
],
),
],
),
),
),
);
);
} catch (e) {
print('Error in EntryDetailPage: $e');
return const Center(
child: Text('エラーが発生しました。もう一度お試しください。'),
);
}
}),
);
}
@ -166,11 +223,17 @@ class EntryDetailPage extends GetView<EntryController> {
return DropdownButtonFormField<int>(
decoration: InputDecoration(labelText: label),
value: selectedId,
items: items.map((item) => DropdownMenuItem<int>(
items: items.isNotEmpty ? items.map((item) => DropdownMenuItem<int>(
//items: items.map((item) => DropdownMenuItem<int>(
value: getId(item),
child: Text(getDisplayName(item)),
)).toList(),
onChanged: onChanged,
)).toList() : null,
onChanged: (value) {
if (value != null) {
onChanged(value);
}
},
//onChanged: onChanged,
);
}
@ -180,11 +243,18 @@ class EntryDetailPage extends GetView<EntryController> {
return DropdownButtonFormField<NewCategory>(
decoration: InputDecoration(labelText: 'カテゴリ'),
value: controller.selectedCategory.value,
items: eligibleCategories.map((category) => DropdownMenuItem<NewCategory>(
items: eligibleCategories.isNotEmpty ? eligibleCategories.map((category) => DropdownMenuItem<NewCategory>(
//items: eligibleCategories.map((category) => DropdownMenuItem<NewCategory>(
value: category,
child: Text(category.categoryName),
)).toList(),
onChanged: (value) => controller.updateCategory(value),
)).toList() : null,
onChanged: (value) {
if (value != null) {
controller.updateCategory(value);
}
},
//onChanged: (value) => controller.updateCategory(value),
);
}