cancellable waitingpage

This commit is contained in:
Christien Rioux 2024-08-03 15:53:11 -05:00
parent cbac96de99
commit ab9838f375
3 changed files with 38 additions and 15 deletions

View File

@ -20,9 +20,14 @@ import '../chat.dart';
const onEndReachedThreshold = 0.75; const onEndReachedThreshold = 0.75;
class ChatComponentWidget extends StatelessWidget { class ChatComponentWidget extends StatelessWidget {
const ChatComponentWidget( const ChatComponentWidget({
{required super.key, required TypedKey localConversationRecordKey}) required super.key,
: _localConversationRecordKey = localConversationRecordKey; 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, (x) => x.tryOperateSync(_localConversationRecordKey,
closure: (cubit) => cubit)); closure: (cubit) => cubit));
if (activeConversationCubit == null) { if (activeConversationCubit == null) {
return waitingPage(); return waitingPage(onCancel: _onCancel);
} }
// Get the messages cubit // Get the messages cubit
@ -57,7 +62,7 @@ class ChatComponentWidget extends StatelessWidget {
(x) => x.tryOperateSync(_localConversationRecordKey, (x) => x.tryOperateSync(_localConversationRecordKey,
closure: (cubit) => cubit)); closure: (cubit) => cubit));
if (messagesCubit == null) { if (messagesCubit == null) {
return waitingPage(); return waitingPage(onCancel: _onCancel);
} }
// Make chat component state // Make chat component state
@ -97,7 +102,7 @@ class ChatComponentWidget extends StatelessWidget {
final localUser = chatComponentState.localUser; final localUser = chatComponentState.localUser;
if (localUser == null) { if (localUser == null) {
return waitingPage(); return const EmptyChatWidget();
} }
final messageWindow = chatComponentState.messageWindow.asData?.value; final messageWindow = chatComponentState.messageWindow.asData?.value;
@ -135,10 +140,10 @@ class ChatComponentWidget extends StatelessWidget {
)), )),
const Spacer(), const Spacer(),
IconButton( IconButton(
icon: Icon(Icons.close, color: scale.primaryScale.borderText), icon:
onPressed: () async { Icon(Icons.close, color: scale.primaryScale.borderText),
context.read<ActiveChatCubit>().setActiveChat(null); onPressed: _onClose)
}).paddingLTRB(16, 0, 16, 0) .paddingLTRB(16, 0, 16, 0)
]), ]),
), ),
DecoratedBox( DecoratedBox(
@ -339,4 +344,6 @@ class ChatComponentWidget extends StatelessWidget {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
final TypedKey _localConversationRecordKey; final TypedKey _localConversationRecordKey;
final void Function() _onCancel;
final void Function() _onClose;
} }

View File

@ -122,13 +122,19 @@ class _HomeAccountReadyState extends State<HomeAccountReady> {
Material(color: Colors.transparent, child: buildUserPanel())); Material(color: Colors.transparent, child: buildUserPanel()));
Widget buildRightPane(BuildContext context) { Widget buildRightPane(BuildContext context) {
final activeChatLocalConversationKey = final activeChatCubit = context.watch<ActiveChatCubit>();
context.watch<ActiveChatCubit>().state; final activeChatLocalConversationKey = activeChatCubit.state;
if (activeChatLocalConversationKey == null) { if (activeChatLocalConversationKey == null) {
return const NoConversationWidget(); return const NoConversationWidget();
} }
return ChatComponentWidget( return ChatComponentWidget(
localConversationRecordKey: activeChatLocalConversationKey, localConversationRecordKey: activeChatLocalConversationKey,
onCancel: () {
activeChatCubit.setActiveChat(null);
},
onClose: () {
activeChatCubit.setActiveChat(null);
},
key: ValueKey(activeChatLocalConversationKey)); key: ValueKey(activeChatLocalConversationKey));
} }

View File

@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.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 'package:sliver_expandable/sliver_expandable.dart';
import '../theme.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 theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!; final scale = theme.extension<ScaleScheme>()!;
return ColoredBox( return ColoredBox(
@ -130,12 +132,20 @@ Widget waitingPage({String? text}) => Builder(builder: (context) {
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
buildProgressIndicator(), buildProgressIndicator().paddingAll(24),
if (text != null) if (text != null)
Text(text, Text(text,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: theme.textTheme.bodySmall! 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(),
])); ]));
}); });