Solian/lib/screens/realms/realm_detail.dart

150 lines
4.4 KiB
Dart
Raw Normal View History

2024-05-29 14:42:11 +00:00
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
2024-05-29 16:05:39 +00:00
import 'package:get/get.dart';
2024-05-29 14:42:11 +00:00
import 'package:solian/models/realm.dart';
2024-05-29 16:05:39 +00:00
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/realms/realm_organize.dart';
import 'package:solian/widgets/realms/realm_deletion.dart';
import 'package:solian/widgets/realms/realm_member.dart';
import 'package:solian/widgets/root_container.dart';
2024-05-29 14:42:11 +00:00
2024-05-29 16:05:39 +00:00
class RealmDetailScreen extends StatefulWidget {
2024-05-29 14:42:11 +00:00
final String alias;
final Realm realm;
const RealmDetailScreen({
super.key,
required this.alias,
required this.realm,
});
2024-05-29 16:05:39 +00:00
@override
State<RealmDetailScreen> createState() => _RealmDetailScreenState();
}
class _RealmDetailScreenState extends State<RealmDetailScreen> {
bool _isOwned = false;
void checkOwner() async {
final AuthProvider auth = Get.find();
setState(() {
2024-07-24 17:18:47 +00:00
_isOwned = auth.userProfile.value!['id'] == widget.realm.accountId;
2024-05-29 16:05:39 +00:00
});
}
void showMemberList() {
showModalBottomSheet(
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (context) => RealmMemberListPopup(
realm: widget.realm,
),
);
}
void promptLeaveChannel() async {
final did = await showDialog(
context: context,
builder: (context) => RealmDeletionDialog(
2024-05-29 16:05:39 +00:00
realm: widget.realm,
isOwned: _isOwned,
),
);
if (did == true && AppRouter.instance.canPop()) {
AppRouter.instance.pop(false);
}
}
@override
void initState() {
super.initState();
checkOwner();
}
2024-05-29 14:42:11 +00:00
@override
Widget build(BuildContext context) {
2024-05-29 16:05:39 +00:00
final ownerActions = [
ListTile(
2024-06-09 15:00:11 +00:00
leading: const Icon(Icons.settings),
2024-05-29 16:05:39 +00:00
trailing: const Icon(Icons.chevron_right),
2024-09-17 06:21:37 +00:00
title: Text('realmSettings'.tr),
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
2024-05-29 16:05:39 +00:00
onTap: () async {
AppRouter.instance
.pushNamed(
'realmOrganizing',
extra: RealmOrganizeArguments(edit: widget.realm),
)
.then((resp) {
if (resp != null) {
AppRouter.instance.pop(resp);
}
});
},
),
];
return RootContainer(
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: Row(
children: [
const CircleAvatar(
radius: 28,
backgroundColor: Colors.teal,
child: Icon(Icons.group, color: Colors.white),
2024-05-29 16:05:39 +00:00
),
const Gap(16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.realm.name,
style: Theme.of(context).textTheme.bodyLarge),
Text(widget.realm.description,
style: Theme.of(context).textTheme.bodySmall),
Text(
'#${widget.realm.id.toString().padLeft(8, '0')} · ${widget.realm.alias}',
style: const TextStyle(fontSize: 11),
),
],
),
)
],
),
2024-05-29 16:05:39 +00:00
),
const Divider(thickness: 0.3),
Expanded(
child: ListView(
children: [
ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
leading: const Icon(Icons.supervisor_account),
trailing: const Icon(Icons.chevron_right),
title: Text('realmMembers'.tr),
onTap: () => showMemberList(),
),
...(_isOwned ? ownerActions : List.empty()),
const Divider(thickness: 0.3),
ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
leading: _isOwned
? const Icon(Icons.delete)
: const Icon(Icons.exit_to_app),
title: Text(_isOwned ? 'delete'.tr : 'leave'.tr),
onTap: () => promptLeaveChannel(),
),
],
),
2024-05-29 16:05:39 +00:00
),
],
),
2024-05-29 16:05:39 +00:00
);
2024-05-29 14:42:11 +00:00
}
}