127 lines
4.6 KiB
Dart
127 lines
4.6 KiB
Dart
// lib/pages/team/team_detail_page.dart
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:rogapp/pages/team/team_controller.dart';
|
|
import 'package:rogapp/routes/app_pages.dart';
|
|
import 'package:rogapp/model/team.dart';
|
|
import 'package:rogapp/model/category.dart';
|
|
|
|
class TeamDetailPage extends GetView<TeamController> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final mode = Get.arguments['mode'] as String;
|
|
final team = Get.arguments['team'] as Team?;
|
|
|
|
if (mode == 'edit' && team != null) {
|
|
controller.setSelectedTeam(team);
|
|
} else {
|
|
controller.resetForm();
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(mode == 'new' ? '新規チーム作成' : 'チーム詳細'),
|
|
actions: [
|
|
IconButton(
|
|
icon: Icon(Icons.save),
|
|
onPressed: () async {
|
|
try {
|
|
await controller.saveTeam();
|
|
Get.back();
|
|
} catch (e) {
|
|
Get.snackbar('エラー', e.toString(), snackPosition: SnackPosition.BOTTOM);
|
|
}
|
|
},
|
|
),
|
|
if (mode == 'edit')
|
|
IconButton(
|
|
icon: Icon(Icons.delete),
|
|
onPressed: () async {
|
|
try {
|
|
await controller.deleteSelectedTeam();
|
|
Get.back();
|
|
} catch (e) {
|
|
Get.snackbar('エラー', e.toString(), snackPosition: SnackPosition.BOTTOM);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: GetBuilder<TeamController>(
|
|
builder: (controller) {
|
|
if (controller.isLoading.value) {
|
|
return Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
return SingleChildScrollView(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
TextFormField(
|
|
initialValue: controller.teamName.value,
|
|
decoration: InputDecoration(labelText: 'チーム名'),
|
|
onChanged: (value) => controller.updateTeamName(value),
|
|
),
|
|
SizedBox(height: 16),
|
|
DropdownButtonFormField<NewCategory>(
|
|
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')
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 16),
|
|
child: Text('ゼッケン番号: ${controller.selectedTeam.value?.zekkenNumber ?? ""}'),
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 16),
|
|
child: Text('所有者: ${controller.currentUser.value?.email ?? "未設定"}'),
|
|
),
|
|
SizedBox(height: 24),
|
|
Text('メンバーリスト', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
|
SizedBox(height: 8),
|
|
ListView.builder(
|
|
shrinkWrap: true,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
itemCount: controller.teamMembers.length,
|
|
itemBuilder: (context, index) {
|
|
final member = controller.teamMembers[index];
|
|
return ListTile(
|
|
title: Text('${member.lastname}, ${member.firstname}'),
|
|
onTap: () => Get.toNamed(
|
|
AppPages.MEMBER_DETAIL,
|
|
arguments: {'mode': 'edit', 'member': member, 'teamId': controller.selectedTeam.value?.id},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
SizedBox(height: 16),
|
|
ElevatedButton(
|
|
child: Text('新しいメンバーを追加'),
|
|
onPressed: () => Get.toNamed(
|
|
AppPages.MEMBER_DETAIL,
|
|
arguments: {'mode': 'new', 'teamId': controller.selectedTeam.value?.id},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|