Solian/lib/screens/chat/chat_detail.dart

127 lines
4.1 KiB
Dart
Raw Normal View History

2024-04-25 13:33:53 +00:00
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
2024-04-26 15:25:56 +00:00
import 'package:solian/widgets/chat/channel_deletion.dart';
import 'package:solian/widgets/scaffold.dart';
2024-04-25 13:33:53 +00:00
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ChatDetailScreen extends StatefulWidget {
2024-04-25 13:33:53 +00:00
final Channel channel;
2024-05-05 15:01:08 +00:00
final String realm;
2024-04-25 13:33:53 +00:00
2024-05-05 15:01:08 +00:00
const ChatDetailScreen({super.key, required this.channel, this.realm = 'global'});
2024-04-25 13:33:53 +00:00
@override
State<ChatDetailScreen> createState() => _ChatDetailScreenState();
2024-04-25 13:33:53 +00:00
}
class _ChatDetailScreenState extends State<ChatDetailScreen> {
2024-04-26 15:25:56 +00:00
bool _isOwned = false;
void promptLeaveChannel() async {
final did = await showDialog(
context: context,
builder: (context) => ChannelDeletion(
channel: widget.channel,
2024-05-05 15:01:08 +00:00
realm: widget.realm,
2024-04-26 15:25:56 +00:00
isOwned: _isOwned,
),
);
if (did == true && SolianRouter.router.canPop()) {
SolianRouter.router.pop('disposed');
2024-04-26 15:25:56 +00:00
}
}
2024-04-25 13:33:53 +00:00
@override
void initState() {
super.initState();
Future.delayed(Duration.zero, () async {
final auth = context.read<AuthProvider>();
final prof = await auth.getProfiles();
setState(() {
2024-04-26 15:25:56 +00:00
_isOwned = prof['id'] == widget.channel.account.externalId;
2024-04-25 13:33:53 +00:00
});
});
}
@override
Widget build(BuildContext context) {
final authorizedItems = [
ListTile(
leading: const Icon(Icons.settings),
title: Text(AppLocalizations.of(context)!.settings),
onTap: () async {
SolianRouter.router.pushNamed('chat.channel.editor', extra: widget.channel).then((did) {
2024-04-25 13:33:53 +00:00
if (did == true) {
if (SolianRouter.router.canPop()) SolianRouter.router.pop('refresh');
2024-04-25 13:33:53 +00:00
}
});
},
),
];
return IndentScaffold(
2024-05-03 08:16:42 +00:00
title: AppLocalizations.of(context)!.chatDetail,
2024-04-25 13:33:53 +00:00
hideDrawer: true,
noSafeArea: true,
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: Row(
children: [
const CircleAvatar(
radius: 24,
backgroundColor: Colors.teal,
child: Icon(Icons.tag, color: Colors.white),
),
const SizedBox(width: 16),
2024-04-26 15:25:56 +00:00
Expanded(
2024-05-02 10:56:40 +00:00
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),
]),
2024-04-26 15:25:56 +00:00
)
2024-04-25 13:33:53 +00:00
],
),
),
const Divider(thickness: 0.3),
Expanded(
child: ListView(
children: [
ListTile(
leading: const Icon(Icons.edit_notifications),
title: Text(AppLocalizations.of(context)!.chatNotifySetting),
onTap: () {},
),
ListTile(
leading: const Icon(Icons.supervisor_account),
title: Text(AppLocalizations.of(context)!.chatMember),
2024-04-26 12:49:21 +00:00
onTap: () {
SolianRouter.router.pushNamed(
2024-04-26 12:49:21 +00:00
'chat.channel.member',
extra: widget.channel,
pathParameters: {'channel': widget.channel.alias},
);
},
2024-04-25 13:33:53 +00:00
),
2024-04-26 15:25:56 +00:00
...(_isOwned ? authorizedItems : List.empty()),
const Divider(thickness: 0.3),
ListTile(
2024-05-02 10:56:40 +00:00
leading: _isOwned ? const Icon(Icons.delete) : const Icon(Icons.exit_to_app),
title: Text(_isOwned ? AppLocalizations.of(context)!.delete : AppLocalizations.of(context)!.exit),
2024-04-26 15:25:56 +00:00
onTap: () => promptLeaveChannel(),
),
2024-04-25 13:33:53 +00:00
],
),
),
],
),
);
}
}