more layout cleanup

This commit is contained in:
Christien Rioux 2024-07-09 13:27:54 -04:00
parent 68f7a26ed1
commit 67812b3c6f
12 changed files with 197 additions and 260 deletions

View File

@ -192,11 +192,7 @@ class ChatComponentWidget extends StatelessWidget {
chatComponentCubit.scrollOffset = 0; chatComponentCubit.scrollOffset = 0;
} }
return Align( return Column(
alignment: AlignmentDirectional.centerEnd,
child: Stack(
children: [
Column(
children: [ children: [
Container( Container(
height: 48, height: 48,
@ -207,26 +203,23 @@ class ChatComponentWidget extends StatelessWidget {
Align( Align(
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
child: Padding( child: Padding(
padding: padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 0),
const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 0),
child: Text(title, child: Text(title,
textAlign: TextAlign.start, textAlign: TextAlign.start,
style: textTheme.titleMedium!.copyWith( style: textTheme.titleMedium!
color: scale.primaryScale.borderText)), .copyWith(color: scale.primaryScale.borderText)),
)), )),
const Spacer(), const Spacer(),
IconButton( IconButton(
icon: Icon(Icons.close, icon: Icon(Icons.close, color: scale.primaryScale.borderText),
color: scale.primaryScale.borderText),
onPressed: () async { onPressed: () async {
context.read<ActiveChatCubit>().setActiveChat(null); context.read<ActiveChatCubit>().setActiveChat(null);
}).paddingLTRB(16, 0, 16, 0) }).paddingLTRB(16, 0, 16, 0)
]), ]),
), ),
Expanded( DecoratedBox(
child: DecoratedBox( decoration:
decoration: BoxDecoration( BoxDecoration(color: scale.primaryScale.subtleBackground),
color: scale.primaryScale.subtleBackground),
child: NotificationListener<ScrollNotification>( child: NotificationListener<ScrollNotification>(
onNotification: (notification) { onNotification: (notification) {
if (chatComponentCubit.scrollOffset != 0) { if (chatComponentCubit.scrollOffset != 0) {
@ -236,13 +229,11 @@ class ChatComponentWidget extends StatelessWidget {
if (!isFirstPage && if (!isFirstPage &&
notification.metrics.pixels <= notification.metrics.pixels <=
((notification.metrics.maxScrollExtent - ((notification.metrics.maxScrollExtent -
notification notification.metrics.minScrollExtent) *
.metrics.minScrollExtent) *
(1.0 - onEndReachedThreshold) + (1.0 - onEndReachedThreshold) +
notification.metrics.minScrollExtent)) { notification.metrics.minScrollExtent)) {
// //
final scrollOffset = final scrollOffset = (notification.metrics.maxScrollExtent -
(notification.metrics.maxScrollExtent -
notification.metrics.minScrollExtent) * notification.metrics.minScrollExtent) *
(1.0 - onEndReachedThreshold); (1.0 - onEndReachedThreshold);
@ -250,14 +241,13 @@ class ChatComponentWidget extends StatelessWidget {
// //
singleFuture(chatComponentState.chatKey, () async { singleFuture(chatComponentState.chatKey, () async {
await _handlePageForward(chatComponentCubit, await _handlePageForward(
messageWindow, notification); chatComponentCubit, messageWindow, notification);
}); });
} else if (!isLastPage && } else if (!isLastPage &&
notification.metrics.pixels >= notification.metrics.pixels >=
((notification.metrics.maxScrollExtent - ((notification.metrics.maxScrollExtent -
notification notification.metrics.minScrollExtent) *
.metrics.minScrollExtent) *
onEndReachedThreshold + onEndReachedThreshold +
notification.metrics.minScrollExtent)) { notification.metrics.minScrollExtent)) {
// //
@ -269,26 +259,23 @@ class ChatComponentWidget extends StatelessWidget {
chatComponentCubit.scrollOffset = scrollOffset; chatComponentCubit.scrollOffset = scrollOffset;
// //
singleFuture(chatComponentState.chatKey, () async { singleFuture(chatComponentState.chatKey, () async {
await _handlePageBackward(chatComponentCubit, await _handlePageBackward(
messageWindow, notification); chatComponentCubit, messageWindow, notification);
}); });
} }
return false; return false;
}, },
child: ValueListenableBuilder( child: ValueListenableBuilder(
valueListenable: valueListenable: chatComponentState.textEditingController,
chatComponentState.textEditingController,
builder: (context, textEditingValue, __) { builder: (context, textEditingValue, __) {
final messageIsValid = utf8 final messageIsValid =
.encode(textEditingValue.text) utf8.encode(textEditingValue.text).lengthInBytes <
.lengthInBytes <
2048; 2048;
return Chat( return Chat(
key: chatComponentState.chatKey, key: chatComponentState.chatKey,
theme: messageIsValid theme:
? chatTheme messageIsValid ? chatTheme : errorChatTheme,
: errorChatTheme,
messages: messageWindow.window.toList(), messages: messageWindow.window.toList(),
scrollToBottomOnSend: isFirstPage, scrollToBottomOnSend: isFirstPage,
scrollController: scrollController:
@ -298,8 +285,7 @@ class ChatComponentWidget extends StatelessWidget {
? InputClearMode.always ? InputClearMode.always
: InputClearMode.never, : InputClearMode.never,
textEditingController: textEditingController:
chatComponentState chatComponentState.textEditingController),
.textEditingController),
// isLastPage: isLastPage, // isLastPage: isLastPage,
// onEndReached: () async { // onEndReached: () async {
// await _handlePageBackward( // await _handlePageBackward(
@ -312,41 +298,29 @@ class ChatComponentWidget extends StatelessWidget {
onSendPressed: (pt) { onSendPressed: (pt) {
try { try {
if (!messageIsValid) { if (!messageIsValid) {
showErrorToast( showErrorToast(context,
context, translate('chat.message_too_long'));
translate(
'chat.message_too_long'));
return; return;
} }
_handleSendPressed( _handleSendPressed(chatComponentCubit, pt);
chatComponentCubit, pt);
} on FormatException { } on FormatException {
showErrorToast( showErrorToast(context,
context, translate('chat.message_too_long'));
translate(
'chat.message_too_long'));
} }
}, },
listBottomWidget: messageIsValid listBottomWidget: messageIsValid
? null ? null
: Text( : Text(translate('chat.message_too_long'),
translate(
'chat.message_too_long'),
style: TextStyle( style: TextStyle(
color: scale color: scale.errorScale.primary))
.errorScale.primary))
.toCenter(), .toCenter(),
//showUserAvatars: false, //showUserAvatars: false,
//showUserNames: true, //showUserNames: true,
user: localUser, user: localUser,
emptyState: const EmptyChatWidget()) emptyState: const EmptyChatWidget())
.paddingLTRB(0, 2, 0, 0); .paddingLTRB(0, 2, 0, 0);
}))), }))).expanded(),
),
], ],
),
],
),
); );
} }
} }

View File

@ -19,6 +19,7 @@ class NoConversationWidget extends StatelessWidget {
color: scale.primaryScale.appBackground, color: scale.primaryScale.appBackground,
), ),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon( Icon(

View File

@ -2,6 +2,6 @@ export 'drawer_menu/drawer_menu.dart';
export 'home_account_invalid.dart'; export 'home_account_invalid.dart';
export 'home_account_locked.dart'; export 'home_account_locked.dart';
export 'home_account_missing.dart'; export 'home_account_missing.dart';
export 'home_account_ready/home_account_ready.dart'; export 'home_account_ready.dart';
export 'home_no_active.dart'; export 'home_no_active.dart';
export 'home_screen.dart'; export 'home_screen.dart';

View File

@ -4,20 +4,20 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_translate/flutter_translate.dart'; import 'package:flutter_translate/flutter_translate.dart';
import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart'; import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart';
import '../../../account_manager/account_manager.dart'; import '../../account_manager/account_manager.dart';
import '../../../chat/chat.dart'; import '../../chat/chat.dart';
import '../../../proto/proto.dart' as proto; import '../../proto/proto.dart' as proto;
import '../../../theme/theme.dart'; import '../../theme/theme.dart';
import 'main_pager/main_pager.dart'; import 'main_pager/main_pager.dart';
class HomeAccountReadyMain extends StatefulWidget { class HomeAccountReady extends StatefulWidget {
const HomeAccountReadyMain({super.key}); const HomeAccountReady({super.key});
@override @override
State<HomeAccountReadyMain> createState() => _HomeAccountReadyMainState(); State<HomeAccountReady> createState() => _HomeAccountReadyState();
} }
class _HomeAccountReadyMainState extends State<HomeAccountReadyMain> { class _HomeAccountReadyState extends State<HomeAccountReady> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -98,7 +98,6 @@ class _HomeAccountReadyMainState extends State<HomeAccountReadyMain> {
phone: false, phone: false,
); );
final w = MediaQuery.of(context).size.width;
final theme = Theme.of(context); final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!; final scale = theme.extension<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!; final scaleConfig = theme.extension<ScaleConfig>()!;
@ -111,36 +110,40 @@ class _HomeAccountReadyMainState extends State<HomeAccountReadyMain> {
// _chatAnimationController.reset(); // _chatAnimationController.reset();
// } // }
late final bool offstageLeft; return LayoutBuilder(builder: (context, constraints) {
late final bool offstageRight; const leftColumnSize = 300.0;
late final bool visibleLeft;
late final bool visibleRight;
late final double leftWidth; late final double leftWidth;
late final double rightWidth; late final double rightWidth;
if (isLarge) { if (isLarge) {
leftWidth = 300; visibleLeft = true;
rightWidth = w - 300 - 2; visibleRight = true;
offstageLeft = false; leftWidth = leftColumnSize;
offstageRight = false; rightWidth = constraints.maxWidth - leftColumnSize - 2;
} else { } else {
leftWidth = w;
rightWidth = w;
if (hasActiveChat) { if (hasActiveChat) {
offstageLeft = true; visibleLeft = false;
offstageRight = false; visibleRight = true;
leftWidth = leftColumnSize;
rightWidth = constraints.maxWidth;
} else { } else {
offstageLeft = false; visibleLeft = true;
offstageRight = true; visibleRight = false;
leftWidth = constraints.maxWidth;
rightWidth = 400; // whatever
} }
} }
return Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [ return Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Offstage( Offstage(
offstage: offstageLeft, offstage: !visibleLeft,
child: ConstrainedBox( child: ConstrainedBox(
constraints: constraints: BoxConstraints(maxWidth: leftWidth),
BoxConstraints(minWidth: leftWidth, maxWidth: leftWidth),
child: buildLeftPane(context))), child: buildLeftPane(context))),
Offstage( Offstage(
offstage: offstageLeft || offstageRight, offstage: !(visibleLeft && visibleRight),
child: SizedBox( child: SizedBox(
width: 2, width: 2,
height: double.infinity, height: double.infinity,
@ -149,13 +152,14 @@ class _HomeAccountReadyMainState extends State<HomeAccountReadyMain> {
? scale.primaryScale.subtleBorder ? scale.primaryScale.subtleBorder
: scale.primaryScale.subtleBackground))), : scale.primaryScale.subtleBackground))),
Offstage( Offstage(
offstage: offstageRight, offstage: !visibleRight,
child: ConstrainedBox( child: ConstrainedBox(
constraints: constraints: BoxConstraints(
BoxConstraints(minWidth: rightWidth, maxWidth: rightWidth), maxHeight: constraints.maxHeight, maxWidth: rightWidth),
child: buildRightPane(context), child: buildRightPane(context),
)), )),
]); ]);
});
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////

View File

@ -1,2 +0,0 @@
export 'home_account_ready_chat.dart';
export 'home_account_ready_main.dart';

View File

@ -1,40 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../chat/chat.dart';
class HomeAccountReadyChat extends StatefulWidget {
const HomeAccountReadyChat({super.key});
@override
HomeAccountReadyChatState createState() => HomeAccountReadyChatState();
}
class HomeAccountReadyChatState extends State<HomeAccountReadyChat> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
Widget buildChatComponent(BuildContext context) {
final activeChatLocalConversationKey =
context.watch<ActiveChatCubit>().state;
if (activeChatLocalConversationKey == null) {
return const NoConversationWidget();
}
return ChatComponentWidget.builder(
localConversationRecordKey: activeChatLocalConversationKey,
key: ValueKey(activeChatLocalConversationKey));
}
@override
Widget build(BuildContext context) => SafeArea(
bottom: false,
child: buildChatComponent(context),
);
}

View File

@ -13,7 +13,7 @@ import 'drawer_menu/drawer_menu.dart';
import 'home_account_invalid.dart'; import 'home_account_invalid.dart';
import 'home_account_locked.dart'; import 'home_account_locked.dart';
import 'home_account_missing.dart'; import 'home_account_missing.dart';
import 'home_account_ready/home_account_ready.dart'; import 'home_account_ready.dart';
import 'home_no_active.dart'; import 'home_no_active.dart';
class HomeScreen extends StatefulWidget { class HomeScreen extends StatefulWidget {
@ -64,7 +64,7 @@ class HomeScreenState extends State<HomeScreen>
// Re-export all ready blocs to the account display subtree // Re-export all ready blocs to the account display subtree
return perAccountCollectionState.provide( return perAccountCollectionState.provide(
child: const HomeAccountReadyMain()); child: const HomeAccountReady());
} }
} }

View File

@ -4,9 +4,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_translate/flutter_translate.dart'; import 'package:flutter_translate/flutter_translate.dart';
import '../../../../contact_invitation/contact_invitation.dart'; import '../../../contact_invitation/contact_invitation.dart';
import '../../../../contacts/contacts.dart'; import '../../../contacts/contacts.dart';
import '../../../../theme/theme.dart'; import '../../../theme/theme.dart';
class AccountPage extends StatefulWidget { class AccountPage extends StatefulWidget {
const AccountPage({ const AccountPage({

View File

@ -1,7 +1,7 @@
import 'package:awesome_extensions/awesome_extensions.dart'; import 'package:awesome_extensions/awesome_extensions.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../chat_list/chat_list.dart'; import '../../../chat_list/chat_list.dart';
class ChatsPage extends StatefulWidget { class ChatsPage extends StatefulWidget {
const ChatsPage({super.key}); const ChatsPage({super.key});

View File

@ -10,9 +10,9 @@ import 'package:flutter_translate/flutter_translate.dart';
import 'package:preload_page_view/preload_page_view.dart'; import 'package:preload_page_view/preload_page_view.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../../../../chat/chat.dart'; import '../../../chat/chat.dart';
import '../../../../contact_invitation/contact_invitation.dart'; import '../../../contact_invitation/contact_invitation.dart';
import '../../../../theme/theme.dart'; import '../../../theme/theme.dart';
import 'account_page.dart'; import 'account_page.dart';
import 'bottom_sheet_action_button.dart'; import 'bottom_sheet_action_button.dart';
import 'chats_page.dart'; import 'chats_page.dart';

View File

@ -1,4 +1,4 @@
export 'default_app_bar.dart'; export 'default_app_bar.dart';
export 'home/home.dart'; export 'home/home.dart';
export 'home/home_account_ready/main_pager/main_pager.dart'; export 'home/main_pager/main_pager.dart';
export 'splash.dart'; export 'splash.dart';