Solian/lib/screens/chat.dart

142 lines
4.6 KiB
Dart
Raw Normal View History

2024-05-23 13:12:47 +00:00
import 'package:flutter/material.dart';
2024-05-25 16:11:00 +00:00
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
2024-07-12 13:59:16 +00:00
import 'package:solian/exts.dart';
2024-05-25 16:11:00 +00:00
import 'package:solian/providers/auth.dart';
import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/account/notification.dart';
import 'package:solian/theme.dart';
2024-05-28 12:13:36 +00:00
import 'package:solian/widgets/account/signin_required_overlay.dart';
import 'package:solian/widgets/app_bar_leading.dart';
2024-06-22 15:59:11 +00:00
import 'package:solian/widgets/app_bar_title.dart';
2024-05-29 15:22:24 +00:00
import 'package:solian/widgets/channel/channel_list.dart';
2024-06-01 12:18:25 +00:00
import 'package:solian/widgets/chat/call/chat_call_indicator.dart';
2024-06-06 12:23:50 +00:00
import 'package:solian/widgets/current_state_action.dart';
2024-07-12 13:59:16 +00:00
import 'package:solian/widgets/sized_container.dart';
2024-05-23 13:12:47 +00:00
class ChatScreen extends StatefulWidget {
const ChatScreen({super.key});
2024-05-23 13:12:47 +00:00
2024-05-25 16:11:00 +00:00
@override
State<ChatScreen> createState() => _ChatScreenState();
2024-05-25 16:11:00 +00:00
}
class _ChatScreenState extends State<ChatScreen> {
2024-07-12 13:59:16 +00:00
late final ChannelProvider _channels;
2024-05-25 16:11:00 +00:00
@override
void initState() {
super.initState();
2024-07-12 13:59:16 +00:00
try {
_channels = Get.find();
_channels.refreshAvailableChannel();
} catch (e) {
context.showErrorDialog(e);
}
2024-05-25 16:11:00 +00:00
}
2024-05-23 13:12:47 +00:00
@override
Widget build(BuildContext context) {
2024-05-25 16:11:00 +00:00
final AuthProvider auth = Get.find();
2024-05-23 13:12:47 +00:00
return Material(
color: Theme.of(context).colorScheme.surface,
2024-07-12 13:59:16 +00:00
child: Scaffold(
appBar: AppBar(
2024-07-12 14:37:58 +00:00
leading: AppBarLeadingButton.adaptive(context),
2024-07-12 13:59:16 +00:00
title: AppBarTitle('chat'.tr),
centerTitle: true,
2024-07-12 13:59:16 +00:00
toolbarHeight: SolianTheme.toolbarHeight(context),
actions: [
const BackgroundStateWidget(),
const NotificationButton(),
PopupMenuButton(
icon: const Icon(Icons.add_circle),
itemBuilder: (BuildContext context) => [
PopupMenuItem(
child: ListTile(
title: Text('channelOrganizeCommon'.tr),
leading: const Icon(Icons.tag),
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
2024-06-22 18:25:45 +00:00
),
2024-07-12 13:59:16 +00:00
onTap: () {
AppRouter.instance.pushNamed('channelOrganizing').then(
(value) {
if (value != null) {
_channels.refreshAvailableChannel();
}
},
);
},
),
PopupMenuItem(
child: ListTile(
title: Text('channelOrganizeDirect'.tr),
leading: const FaIcon(
FontAwesomeIcons.userGroup,
size: 16,
2024-05-25 16:11:00 +00:00
),
2024-07-12 13:59:16 +00:00
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
),
onTap: () {
final ChannelProvider channels = Get.find();
channels
2024-07-12 13:59:16 +00:00
.createDirectChannel(context, 'global')
.then((resp) {
if (resp != null) {
_channels.refreshAvailableChannel();
}
}).catchError((e) {
context.showErrorDialog(e);
2024-07-12 13:59:16 +00:00
});
},
),
],
),
SizedBox(
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
),
],
),
2024-07-24 17:18:47 +00:00
body: Obx(() {
if (auth.isAuthorized.isFalse) {
return SigninRequiredOverlay(
onSignedIn: () => _channels.refreshAvailableChannel(),
);
}
2024-07-12 13:59:16 +00:00
2024-07-24 17:18:47 +00:00
final selfId = auth.userProfile.value!['id'];
2024-07-12 13:59:16 +00:00
2024-07-24 17:18:47 +00:00
return Column(
children: [
Obx(() {
if (_channels.isLoading.isFalse) {
return const SizedBox();
} else {
return const LinearProgressIndicator();
}
}),
const ChatCallCurrentIndicator(),
Expanded(
child: CenteredContainer(
child: RefreshIndicator(
onRefresh: _channels.refreshAvailableChannel,
child: Obx(
() => ChannelListWidget(
noCategory: true,
channels: _channels.directChannels,
selfId: selfId,
2024-07-12 13:59:16 +00:00
),
2024-05-28 14:13:23 +00:00
),
2024-07-12 13:59:16 +00:00
),
),
2024-07-24 17:18:47 +00:00
),
],
);
}),
2024-05-28 14:13:23 +00:00
),
2024-05-23 13:12:47 +00:00
);
}
}