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,161 +192,135 @@ class ChatComponentWidget extends StatelessWidget {
chatComponentCubit.scrollOffset = 0; chatComponentCubit.scrollOffset = 0;
} }
return Align( return Column(
alignment: AlignmentDirectional.centerEnd, children: [
child: Stack( Container(
children: [ height: 48,
Column( decoration: BoxDecoration(
children: [ color: scale.primaryScale.subtleBorder,
Container(
height: 48,
decoration: BoxDecoration(
color: scale.primaryScale.subtleBorder,
),
child: Row(children: [
Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding:
const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 0),
child: Text(title,
textAlign: TextAlign.start,
style: textTheme.titleMedium!.copyWith(
color: scale.primaryScale.borderText)),
)),
const Spacer(),
IconButton(
icon: Icon(Icons.close,
color: scale.primaryScale.borderText),
onPressed: () async {
context.read<ActiveChatCubit>().setActiveChat(null);
}).paddingLTRB(16, 0, 16, 0)
]),
),
Expanded(
child: DecoratedBox(
decoration: BoxDecoration(
color: scale.primaryScale.subtleBackground),
child: NotificationListener<ScrollNotification>(
onNotification: (notification) {
if (chatComponentCubit.scrollOffset != 0) {
return false;
}
if (!isFirstPage &&
notification.metrics.pixels <=
((notification.metrics.maxScrollExtent -
notification
.metrics.minScrollExtent) *
(1.0 - onEndReachedThreshold) +
notification.metrics.minScrollExtent)) {
//
final scrollOffset =
(notification.metrics.maxScrollExtent -
notification.metrics.minScrollExtent) *
(1.0 - onEndReachedThreshold);
chatComponentCubit.scrollOffset = scrollOffset;
//
singleFuture(chatComponentState.chatKey, () async {
await _handlePageForward(chatComponentCubit,
messageWindow, notification);
});
} else if (!isLastPage &&
notification.metrics.pixels >=
((notification.metrics.maxScrollExtent -
notification
.metrics.minScrollExtent) *
onEndReachedThreshold +
notification.metrics.minScrollExtent)) {
//
final scrollOffset =
-(notification.metrics.maxScrollExtent -
notification.metrics.minScrollExtent) *
(1.0 - onEndReachedThreshold);
chatComponentCubit.scrollOffset = scrollOffset;
//
singleFuture(chatComponentState.chatKey, () async {
await _handlePageBackward(chatComponentCubit,
messageWindow, notification);
});
}
return false;
},
child: ValueListenableBuilder(
valueListenable:
chatComponentState.textEditingController,
builder: (context, textEditingValue, __) {
final messageIsValid = utf8
.encode(textEditingValue.text)
.lengthInBytes <
2048;
return Chat(
key: chatComponentState.chatKey,
theme: messageIsValid
? chatTheme
: errorChatTheme,
messages: messageWindow.window.toList(),
scrollToBottomOnSend: isFirstPage,
scrollController:
chatComponentState.scrollController,
inputOptions: InputOptions(
inputClearMode: messageIsValid
? InputClearMode.always
: InputClearMode.never,
textEditingController:
chatComponentState
.textEditingController),
// isLastPage: isLastPage,
// onEndReached: () async {
// await _handlePageBackward(
// chatComponentCubit, messageWindow);
// },
//onEndReachedThreshold: onEndReachedThreshold,
//onAttachmentPressed: _handleAttachmentPressed,
//onMessageTap: _handleMessageTap,
//onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: (pt) {
try {
if (!messageIsValid) {
showErrorToast(
context,
translate(
'chat.message_too_long'));
return;
}
_handleSendPressed(
chatComponentCubit, pt);
} on FormatException {
showErrorToast(
context,
translate(
'chat.message_too_long'));
}
},
listBottomWidget: messageIsValid
? null
: Text(
translate(
'chat.message_too_long'),
style: TextStyle(
color: scale
.errorScale.primary))
.toCenter(),
//showUserAvatars: false,
//showUserNames: true,
user: localUser,
emptyState: const EmptyChatWidget())
.paddingLTRB(0, 2, 0, 0);
}))),
),
],
), ),
], child: Row(children: [
), Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 0),
child: Text(title,
textAlign: TextAlign.start,
style: textTheme.titleMedium!
.copyWith(color: scale.primaryScale.borderText)),
)),
const Spacer(),
IconButton(
icon: Icon(Icons.close, color: scale.primaryScale.borderText),
onPressed: () async {
context.read<ActiveChatCubit>().setActiveChat(null);
}).paddingLTRB(16, 0, 16, 0)
]),
),
DecoratedBox(
decoration:
BoxDecoration(color: scale.primaryScale.subtleBackground),
child: NotificationListener<ScrollNotification>(
onNotification: (notification) {
if (chatComponentCubit.scrollOffset != 0) {
return false;
}
if (!isFirstPage &&
notification.metrics.pixels <=
((notification.metrics.maxScrollExtent -
notification.metrics.minScrollExtent) *
(1.0 - onEndReachedThreshold) +
notification.metrics.minScrollExtent)) {
//
final scrollOffset = (notification.metrics.maxScrollExtent -
notification.metrics.minScrollExtent) *
(1.0 - onEndReachedThreshold);
chatComponentCubit.scrollOffset = scrollOffset;
//
singleFuture(chatComponentState.chatKey, () async {
await _handlePageForward(
chatComponentCubit, messageWindow, notification);
});
} else if (!isLastPage &&
notification.metrics.pixels >=
((notification.metrics.maxScrollExtent -
notification.metrics.minScrollExtent) *
onEndReachedThreshold +
notification.metrics.minScrollExtent)) {
//
final scrollOffset =
-(notification.metrics.maxScrollExtent -
notification.metrics.minScrollExtent) *
(1.0 - onEndReachedThreshold);
chatComponentCubit.scrollOffset = scrollOffset;
//
singleFuture(chatComponentState.chatKey, () async {
await _handlePageBackward(
chatComponentCubit, messageWindow, notification);
});
}
return false;
},
child: ValueListenableBuilder(
valueListenable: chatComponentState.textEditingController,
builder: (context, textEditingValue, __) {
final messageIsValid =
utf8.encode(textEditingValue.text).lengthInBytes <
2048;
return Chat(
key: chatComponentState.chatKey,
theme:
messageIsValid ? chatTheme : errorChatTheme,
messages: messageWindow.window.toList(),
scrollToBottomOnSend: isFirstPage,
scrollController:
chatComponentState.scrollController,
inputOptions: InputOptions(
inputClearMode: messageIsValid
? InputClearMode.always
: InputClearMode.never,
textEditingController:
chatComponentState.textEditingController),
// isLastPage: isLastPage,
// onEndReached: () async {
// await _handlePageBackward(
// chatComponentCubit, messageWindow);
// },
//onEndReachedThreshold: onEndReachedThreshold,
//onAttachmentPressed: _handleAttachmentPressed,
//onMessageTap: _handleMessageTap,
//onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: (pt) {
try {
if (!messageIsValid) {
showErrorToast(context,
translate('chat.message_too_long'));
return;
}
_handleSendPressed(chatComponentCubit, pt);
} on FormatException {
showErrorToast(context,
translate('chat.message_too_long'));
}
},
listBottomWidget: messageIsValid
? null
: Text(translate('chat.message_too_long'),
style: TextStyle(
color: scale.errorScale.primary))
.toCenter(),
//showUserAvatars: false,
//showUserNames: true,
user: localUser,
emptyState: const EmptyChatWidget())
.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,51 +110,56 @@ 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 double leftWidth;
late final double rightWidth;
if (isLarge) {
leftWidth = 300;
rightWidth = w - 300 - 2;
offstageLeft = false;
offstageRight = false;
} else {
leftWidth = w;
rightWidth = w;
if (hasActiveChat) {
offstageLeft = true;
offstageRight = false;
} else {
offstageLeft = false;
offstageRight = true;
}
}
return Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [ late final bool visibleLeft;
Offstage( late final bool visibleRight;
offstage: offstageLeft, late final double leftWidth;
child: ConstrainedBox( late final double rightWidth;
constraints: if (isLarge) {
BoxConstraints(minWidth: leftWidth, maxWidth: leftWidth), visibleLeft = true;
child: buildLeftPane(context))), visibleRight = true;
Offstage( leftWidth = leftColumnSize;
offstage: offstageLeft || offstageRight, rightWidth = constraints.maxWidth - leftColumnSize - 2;
child: SizedBox( } else {
width: 2, if (hasActiveChat) {
height: double.infinity, visibleLeft = false;
child: ColoredBox( visibleRight = true;
color: scaleConfig.preferBorders leftWidth = leftColumnSize;
? scale.primaryScale.subtleBorder rightWidth = constraints.maxWidth;
: scale.primaryScale.subtleBackground))), } else {
Offstage( visibleLeft = true;
offstage: offstageRight, visibleRight = false;
child: ConstrainedBox( leftWidth = constraints.maxWidth;
constraints: rightWidth = 400; // whatever
BoxConstraints(minWidth: rightWidth, maxWidth: rightWidth), }
child: buildRightPane(context), }
)),
]); return Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Offstage(
offstage: !visibleLeft,
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: leftWidth),
child: buildLeftPane(context))),
Offstage(
offstage: !(visibleLeft && visibleRight),
child: SizedBox(
width: 2,
height: double.infinity,
child: ColoredBox(
color: scaleConfig.preferBorders
? scale.primaryScale.subtleBorder
: scale.primaryScale.subtleBackground))),
Offstage(
offstage: !visibleRight,
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: constraints.maxHeight, maxWidth: rightWidth),
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';