Solian/lib/screens/channel/channel_detail.dart

156 lines
4.5 KiB
Dart
Raw Normal View History

2024-05-26 15:13:43 +00:00
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/channel/channel_organize.dart';
import 'package:solian/widgets/channel/channel_deletion.dart';
2024-05-27 13:21:10 +00:00
import 'package:solian/widgets/channel/channel_member.dart';
2024-05-26 15:13:43 +00:00
class ChannelDetailScreen extends StatefulWidget {
final String realm;
final Channel channel;
const ChannelDetailScreen({
super.key,
required this.channel,
required this.realm,
});
@override
State<ChannelDetailScreen> createState() => _ChannelDetailScreenState();
}
class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
bool _isOwned = false;
void checkOwner() async {
final AuthProvider auth = Get.find();
final prof = await auth.getProfile();
setState(() {
_isOwned = prof.body['id'] == widget.channel.account.externalId;
});
}
2024-05-27 13:21:10 +00:00
void showMemberList() {
showModalBottomSheet(
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (context) => ChannelMemberListPopup(
channel: widget.channel,
realm: widget.realm,
),
);
}
2024-05-26 15:13:43 +00:00
void promptLeaveChannel() async {
final did = await showDialog(
context: context,
builder: (context) => ChannelDeletionDialog(
2024-05-26 15:13:43 +00:00
channel: widget.channel,
realm: widget.realm,
isOwned: _isOwned,
),
);
if (did == true && AppRouter.instance.canPop()) {
AppRouter.instance.pop(false);
}
}
@override
void initState() {
super.initState();
checkOwner();
}
@override
Widget build(BuildContext context) {
final ownerActions = [
ListTile(
leading: const Icon(Icons.edit),
2024-05-27 13:21:10 +00:00
trailing: const Icon(Icons.chevron_right),
2024-06-08 13:35:50 +00:00
title: Text('channelAdjust'.tr.capitalize!),
2024-05-26 15:13:43 +00:00
onTap: () async {
AppRouter.instance
.pushNamed(
'channelOrganizing',
extra: ChannelOrganizeArguments(edit: widget.channel),
)
.then((resp) {
if (resp != null) {
AppRouter.instance.pop(resp);
}
});
},
),
];
return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: Row(
children: [
2024-05-28 16:14:41 +00:00
const CircleAvatar(
2024-05-26 15:13:43 +00:00
radius: 28,
backgroundColor: Colors.teal,
child: FaIcon(
2024-05-28 16:14:41 +00:00
FontAwesomeIcons.hashtag,
2024-05-26 15:13:43 +00:00
color: Colors.white,
size: 18,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.channel.name,
style: Theme.of(context).textTheme.bodyLarge),
Text(widget.channel.description,
style: Theme.of(context).textTheme.bodySmall),
Text(
'#${widget.channel.id.toString().padLeft(8, '0')} · ${widget.channel.alias}',
style: const TextStyle(fontSize: 11),
),
],
),
)
],
),
),
const Divider(thickness: 0.3),
Expanded(
child: ListView(
children: [
ListTile(
leading: const Icon(Icons.settings),
2024-05-27 13:21:10 +00:00
trailing: const Icon(Icons.chevron_right),
2024-06-08 13:35:50 +00:00
title: Text('channelSettings'.tr.capitalize!),
2024-05-26 15:13:43 +00:00
),
ListTile(
leading: const Icon(Icons.supervisor_account),
2024-05-27 13:21:10 +00:00
trailing: const Icon(Icons.chevron_right),
2024-06-08 13:35:50 +00:00
title: Text('channelMembers'.tr.capitalize!),
2024-05-27 13:21:10 +00:00
onTap: () => showMemberList(),
2024-05-26 15:13:43 +00:00
),
...(_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(),
),
],
),
),
],
);
}
}