💄 Chat channels loading indicator

This commit is contained in:
LittleSheep 2024-10-10 23:48:37 +08:00
parent af7cc8dab0
commit ca18d6ade4

View File

@ -69,6 +69,8 @@ class _ChatListState extends State<ChatList> {
late final ChannelProvider _channels = Get.find(); late final ChannelProvider _channels = Get.find();
bool _isBusy = true;
List<Channel> _sortChannels(List<Channel> channels) { List<Channel> _sortChannels(List<Channel> channels) {
channels.sort( channels.sort(
(a, b) => (a, b) =>
@ -130,7 +132,12 @@ class _ChatListState extends State<ChatList> {
void initState() { void initState() {
super.initState(); super.initState();
_loadLastMessages().then((_) { _loadLastMessages().then((_) {
_loadAllChannels(); if (!mounted) return;
_loadAllChannels().then((_) {
if (mounted) {
setState(() => _isBusy = false);
}
});
}); });
} }
@ -145,16 +152,7 @@ class _ChatListState extends State<ChatList> {
child: ResponsiveRootContainer( child: ResponsiveRootContainer(
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
leading: Obx(() { leading: AppBarLeadingButton.adaptive(context),
final adaptive = AppBarLeadingButton.adaptive(context);
if (adaptive != null) return adaptive;
if (_channels.isLoading.value) {
return const CircularProgressIndicator(
strokeWidth: 3,
).paddingAll(18);
}
return const SizedBox.shrink();
}),
title: AppBarTitle('chat'.tr), title: AppBarTitle('chat'.tr),
centerTitle: true, centerTitle: true,
toolbarHeight: AppTheme.toolbarHeight(context), toolbarHeight: AppTheme.toolbarHeight(context),
@ -282,6 +280,26 @@ class _ChatListState extends State<ChatList> {
return Column( return Column(
children: [ children: [
const ChatCallCurrentIndicator(), const ChatCallCurrentIndicator(),
if (_isBusy)
Container(
color: Theme.of(context)
.colorScheme
.surfaceContainerLow
.withOpacity(0.8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 16,
width: 16,
child: CircularProgressIndicator(strokeWidth: 2.5),
),
const Gap(8),
Text('loading'.tr)
],
).paddingSymmetric(vertical: 8),
),
Expanded( Expanded(
child: TabBarView( child: TabBarView(
children: [ children: [