mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-10-01 06:55:46 -04:00
cancellable waitingpage
This commit is contained in:
parent
cbac96de99
commit
ab9838f375
@ -20,9 +20,14 @@ import '../chat.dart';
|
||||
const onEndReachedThreshold = 0.75;
|
||||
|
||||
class ChatComponentWidget extends StatelessWidget {
|
||||
const ChatComponentWidget(
|
||||
{required super.key, required TypedKey localConversationRecordKey})
|
||||
: _localConversationRecordKey = localConversationRecordKey;
|
||||
const ChatComponentWidget({
|
||||
required super.key,
|
||||
required TypedKey localConversationRecordKey,
|
||||
required void Function() onCancel,
|
||||
required void Function() onClose,
|
||||
}) : _localConversationRecordKey = localConversationRecordKey,
|
||||
_onCancel = onCancel,
|
||||
_onClose = onClose;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -48,7 +53,7 @@ class ChatComponentWidget extends StatelessWidget {
|
||||
(x) => x.tryOperateSync(_localConversationRecordKey,
|
||||
closure: (cubit) => cubit));
|
||||
if (activeConversationCubit == null) {
|
||||
return waitingPage();
|
||||
return waitingPage(onCancel: _onCancel);
|
||||
}
|
||||
|
||||
// Get the messages cubit
|
||||
@ -57,7 +62,7 @@ class ChatComponentWidget extends StatelessWidget {
|
||||
(x) => x.tryOperateSync(_localConversationRecordKey,
|
||||
closure: (cubit) => cubit));
|
||||
if (messagesCubit == null) {
|
||||
return waitingPage();
|
||||
return waitingPage(onCancel: _onCancel);
|
||||
}
|
||||
|
||||
// Make chat component state
|
||||
@ -97,7 +102,7 @@ class ChatComponentWidget extends StatelessWidget {
|
||||
|
||||
final localUser = chatComponentState.localUser;
|
||||
if (localUser == null) {
|
||||
return waitingPage();
|
||||
return const EmptyChatWidget();
|
||||
}
|
||||
|
||||
final messageWindow = chatComponentState.messageWindow.asData?.value;
|
||||
@ -135,10 +140,10 @@ class ChatComponentWidget extends StatelessWidget {
|
||||
)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(Icons.close, color: scale.primaryScale.borderText),
|
||||
onPressed: () async {
|
||||
context.read<ActiveChatCubit>().setActiveChat(null);
|
||||
}).paddingLTRB(16, 0, 16, 0)
|
||||
icon:
|
||||
Icon(Icons.close, color: scale.primaryScale.borderText),
|
||||
onPressed: _onClose)
|
||||
.paddingLTRB(16, 0, 16, 0)
|
||||
]),
|
||||
),
|
||||
DecoratedBox(
|
||||
@ -339,4 +344,6 @@ class ChatComponentWidget extends StatelessWidget {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
final TypedKey _localConversationRecordKey;
|
||||
final void Function() _onCancel;
|
||||
final void Function() _onClose;
|
||||
}
|
||||
|
@ -122,13 +122,19 @@ class _HomeAccountReadyState extends State<HomeAccountReady> {
|
||||
Material(color: Colors.transparent, child: buildUserPanel()));
|
||||
|
||||
Widget buildRightPane(BuildContext context) {
|
||||
final activeChatLocalConversationKey =
|
||||
context.watch<ActiveChatCubit>().state;
|
||||
final activeChatCubit = context.watch<ActiveChatCubit>();
|
||||
final activeChatLocalConversationKey = activeChatCubit.state;
|
||||
if (activeChatLocalConversationKey == null) {
|
||||
return const NoConversationWidget();
|
||||
}
|
||||
return ChatComponentWidget(
|
||||
localConversationRecordKey: activeChatLocalConversationKey,
|
||||
onCancel: () {
|
||||
activeChatCubit.setActiveChat(null);
|
||||
},
|
||||
onClose: () {
|
||||
activeChatCubit.setActiveChat(null);
|
||||
},
|
||||
key: ValueKey(activeChatLocalConversationKey));
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:sliver_expandable/sliver_expandable.dart';
|
||||
|
||||
import '../theme.dart';
|
||||
@ -121,7 +122,8 @@ Widget buildProgressIndicator() => Builder(builder: (context) {
|
||||
));
|
||||
});
|
||||
|
||||
Widget waitingPage({String? text}) => Builder(builder: (context) {
|
||||
Widget waitingPage({String? text, void Function()? onCancel}) =>
|
||||
Builder(builder: (context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
return ColoredBox(
|
||||
@ -130,12 +132,20 @@ Widget waitingPage({String? text}) => Builder(builder: (context) {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
buildProgressIndicator(),
|
||||
buildProgressIndicator().paddingAll(24),
|
||||
if (text != null)
|
||||
Text(text,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodySmall!
|
||||
.copyWith(color: scale.tertiaryScale.appText))
|
||||
.copyWith(color: scale.tertiaryScale.appText)),
|
||||
if (onCancel != null)
|
||||
ElevatedButton(
|
||||
onPressed: onCancel,
|
||||
child: Text(translate('button.cancel'),
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodySmall!.copyWith(
|
||||
color: scale.tertiaryScale.appText)))
|
||||
.alignAtCenter(),
|
||||
]));
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user