veilidchat/lib/layout/home/home_account_ready.dart

207 lines
7.8 KiB
Dart
Raw Normal View History

2024-02-11 23:18:20 -05:00
import 'package:awesome_extensions/awesome_extensions.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_translate/flutter_translate.dart';
2024-06-11 21:27:20 -04:00
import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart';
2024-02-11 23:18:20 -05:00
2024-07-09 13:27:54 -04:00
import '../../account_manager/account_manager.dart';
import '../../chat/chat.dart';
2024-07-31 13:04:43 -04:00
import '../../chat_list/chat_list.dart';
import '../../contacts/contacts.dart';
2024-07-09 13:27:54 -04:00
import '../../proto/proto.dart' as proto;
import '../../theme/theme.dart';
2024-02-11 23:18:20 -05:00
2024-07-09 13:27:54 -04:00
class HomeAccountReady extends StatefulWidget {
const HomeAccountReady({super.key});
2024-02-11 23:18:20 -05:00
2024-02-28 20:32:37 -05:00
@override
2024-07-09 13:27:54 -04:00
State<HomeAccountReady> createState() => _HomeAccountReadyState();
2024-02-28 20:32:37 -05:00
}
2024-07-09 13:27:54 -04:00
class _HomeAccountReadyState extends State<HomeAccountReady> {
2024-02-28 20:32:37 -05:00
@override
void initState() {
super.initState();
}
2024-07-31 13:04:43 -04:00
Widget buildMenuButton() => Builder(builder: (context) {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
return IconButton(
icon: const Icon(Icons.menu),
color: scaleConfig.preferBorders
? scale.primaryScale.border
: scale.primaryScale.borderText,
constraints: const BoxConstraints.expand(height: 48, width: 48),
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
scaleConfig.preferBorders
? scale.primaryScale.hoverElementBackground
: scale.primaryScale.hoverBorder),
shape: WidgetStateProperty.all(
RoundedRectangleBorder(
side: !scaleConfig.useVisualIndicators
? BorderSide.none
: BorderSide(
strokeAlign: BorderSide.strokeAlignCenter,
color: scaleConfig.preferBorders
? scale.primaryScale.border
: scale.primaryScale.borderText,
width: 2),
borderRadius: BorderRadius.all(
Radius.circular(12 * scaleConfig.borderRadiusScale))),
)),
tooltip: translate('menu.accounts_menu_tooltip'),
onPressed: () async {
final ctrl = context.read<ZoomDrawerController>();
await ctrl.toggle?.call();
});
});
Widget buildContactsButton() => Builder(builder: (context) {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;
return IconButton(
icon: const Icon(Icons.contacts),
color: scaleConfig.preferBorders
? scale.primaryScale.border
: scale.primaryScale.borderText,
constraints: const BoxConstraints.expand(height: 48, width: 48),
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
scaleConfig.preferBorders
? scale.primaryScale.hoverElementBackground
: scale.primaryScale.hoverBorder),
shape: WidgetStateProperty.all(
RoundedRectangleBorder(
side: !scaleConfig.useVisualIndicators
? BorderSide.none
: BorderSide(
strokeAlign: BorderSide.strokeAlignCenter,
color: scaleConfig.preferBorders
? scale.primaryScale.border
: scale.primaryScale.borderText,
width: 2),
borderRadius: BorderRadius.all(
Radius.circular(12 * scaleConfig.borderRadiusScale))),
)),
tooltip: translate('menu.contacts_tooltip'),
onPressed: () async {
await ContactsDialog.show(context);
});
});
2024-02-11 23:18:20 -05:00
Widget buildUserPanel() => Builder(builder: (context) {
2024-06-15 23:29:15 -04:00
final profile = context.select<AccountRecordCubit, proto.Profile>(
(c) => c.state.asData!.value.profile);
2024-02-11 23:18:20 -05:00
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
2024-07-06 20:09:18 -04:00
final scaleConfig = theme.extension<ScaleConfig>()!;
2024-02-11 23:18:20 -05:00
2024-06-24 19:44:08 -04:00
return ColoredBox(
2024-07-06 20:09:18 -04:00
color: scaleConfig.preferBorders
? scale.primaryScale.subtleBackground
: scale.primaryScale.subtleBorder,
2024-06-24 19:44:08 -04:00
child: Column(children: <Widget>[
Row(children: [
2024-07-31 13:04:43 -04:00
buildMenuButton().paddingLTRB(0, 0, 8, 0),
2024-07-08 21:29:52 -04:00
ProfileWidget(
profile: profile,
showPronouns: false,
).expanded(),
2024-07-31 13:04:43 -04:00
buildContactsButton().paddingLTRB(8, 0, 0, 0),
2024-06-24 19:44:08 -04:00
]).paddingAll(8),
2024-07-31 13:04:43 -04:00
const ChatListWidget().expanded()
2024-06-24 19:44:08 -04:00
]));
2024-02-11 23:18:20 -05:00
});
2024-07-09 12:00:15 -04:00
Widget buildLeftPane(BuildContext context) => Builder(
2024-02-11 23:18:20 -05:00
builder: (context) =>
Material(color: Colors.transparent, child: buildUserPanel()));
2024-07-09 12:00:15 -04:00
Widget buildRightPane(BuildContext context) {
2024-08-03 16:53:11 -04:00
final activeChatCubit = context.watch<ActiveChatCubit>();
final activeChatLocalConversationKey = activeChatCubit.state;
2024-05-27 18:04:00 -04:00
if (activeChatLocalConversationKey == null) {
2024-06-02 11:04:19 -04:00
return const NoConversationWidget();
2024-02-11 23:18:20 -05:00
}
2024-07-24 15:20:29 -04:00
return ChatComponentWidget(
2024-06-15 23:29:15 -04:00
localConversationRecordKey: activeChatLocalConversationKey,
2024-08-03 16:53:11 -04:00
onCancel: () {
activeChatCubit.setActiveChat(null);
},
onClose: () {
activeChatCubit.setActiveChat(null);
},
2024-06-15 23:29:15 -04:00
key: ValueKey(activeChatLocalConversationKey));
2024-02-11 23:18:20 -05:00
}
2024-07-09 12:00:15 -04:00
@override
Widget build(BuildContext context) {
final isLarge = responsiveVisibility(
context: context,
phone: false,
);
2024-02-11 23:18:20 -05:00
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
2024-07-06 20:09:18 -04:00
final scaleConfig = theme.extension<ScaleConfig>()!;
2024-02-11 23:18:20 -05:00
2024-07-09 12:00:15 -04:00
final activeChat = context.watch<ActiveChatCubit>().state;
final hasActiveChat = activeChat != null;
2024-02-11 23:18:20 -05:00
2024-07-09 13:27:54 -04:00
return LayoutBuilder(builder: (context, constraints) {
const leftColumnSize = 300.0;
late final bool visibleLeft;
late final bool visibleRight;
late final double leftWidth;
late final double rightWidth;
if (isLarge) {
visibleLeft = true;
visibleRight = true;
leftWidth = leftColumnSize;
rightWidth = constraints.maxWidth - leftColumnSize - 2;
2024-07-09 12:00:15 -04:00
} else {
2024-07-09 13:27:54 -04:00
if (hasActiveChat) {
visibleLeft = false;
visibleRight = true;
leftWidth = leftColumnSize;
rightWidth = constraints.maxWidth;
} else {
visibleLeft = true;
visibleRight = false;
leftWidth = constraints.maxWidth;
rightWidth = 400; // whatever
}
2024-07-09 12:00:15 -04:00
}
2024-02-11 23:18:20 -05:00
2024-07-09 13:27:54 -04:00
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),
)),
]);
});
2024-07-09 12:00:15 -04:00
}
2024-02-11 23:18:20 -05:00
}