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) => ChannelDeletion(
|
|
|
|
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-05-26 15:13:43 +00:00
|
|
|
title: Text('channelAdjust'.tr),
|
|
|
|
onTap: () async {
|
|
|
|
AppRouter.instance
|
|
|
|
.pushNamed(
|
|
|
|
'channelOrganizing',
|
|
|
|
extra: ChannelOrganizeArguments(edit: widget.channel),
|
|
|
|
queryParameters:
|
|
|
|
widget.realm != 'global' ? {'realm': 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: [
|
|
|
|
CircleAvatar(
|
|
|
|
radius: 28,
|
|
|
|
backgroundColor: Colors.teal,
|
|
|
|
child: FaIcon(
|
|
|
|
widget.channel.icon,
|
|
|
|
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-05-26 15:13:43 +00:00
|
|
|
title: Text('channelSettings'.tr),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.supervisor_account),
|
2024-05-27 13:21:10 +00:00
|
|
|
trailing: const Icon(Icons.chevron_right),
|
2024-05-26 15:13:43 +00:00
|
|
|
title: Text('channelMembers'.tr),
|
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(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|