2024-05-29 14:42:11 +00:00
|
|
|
import 'package:flutter/material.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';
|
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();
|
|
|
|
final prof = await auth.getProfile();
|
|
|
|
setState(() {
|
|
|
|
_isOwned = prof.body['id'] == widget.realm.accountId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void showMemberList() {
|
|
|
|
showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
useRootNavigator: true,
|
|
|
|
isScrollControlled: true,
|
|
|
|
builder: (context) => RealmMemberListPopup(
|
|
|
|
realm: widget.realm,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void promptLeaveChannel() async {
|
|
|
|
final did = await showDialog(
|
|
|
|
context: context,
|
2024-05-30 15:14:29 +00:00
|
|
|
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-06-09 15:00:11 +00:00
|
|
|
title: Text('realmSettings'.tr.capitalize!),
|
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 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),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 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),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Divider(thickness: 0.3),
|
|
|
|
Expanded(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.supervisor_account),
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
2024-06-08 13:35:50 +00:00
|
|
|
title: Text('realmMembers'.tr.capitalize!),
|
2024-05-29 16:05:39 +00:00
|
|
|
onTap: () => showMemberList(),
|
|
|
|
),
|
|
|
|
...(_isOwned ? ownerActions : List.empty()),
|
|
|
|
const Divider(thickness: 0.3),
|
|
|
|
ListTile(
|
|
|
|
leading: _isOwned
|
|
|
|
? const Icon(Icons.delete)
|
|
|
|
: const Icon(Icons.exit_to_app),
|
|
|
|
title: Text(_isOwned ? 'delete'.tr : 'leave'.tr),
|
|
|
|
onTap: () => promptLeaveChannel(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2024-05-29 14:42:11 +00:00
|
|
|
}
|
|
|
|
}
|