veilidchat/lib/layout/home/home_account_ready.dart

168 lines
6.3 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';
import '../../proto/proto.dart' as proto;
import '../../theme/theme.dart';
2024-02-11 23:18:20 -05:00
import 'main_pager/main_pager.dart';
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-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: [
IconButton(
icon: const Icon(Icons.menu),
2024-07-06 20:09:18 -04:00
color: scaleConfig.preferBorders
? scale.primaryScale.border
: scale.primaryScale.borderText,
2024-06-24 19:44:08 -04:00
constraints:
2024-07-08 21:29:52 -04:00
const BoxConstraints.expand(height: 48, width: 48),
2024-06-24 19:44:08 -04:00
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
2024-07-06 20:09:18 -04:00
scaleConfig.preferBorders
? scale.primaryScale.hoverElementBackground
: scale.primaryScale.hoverBorder),
2024-06-24 19:44:08 -04:00
shape: WidgetStateProperty.all(
2024-07-06 20:09:18 -04:00
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(
2024-07-08 21:29:52 -04:00
12 * scaleConfig.borderRadiusScale))),
2024-07-06 20:09:18 -04:00
)),
2024-06-24 19:44:08 -04:00
tooltip: translate('menu.settings_tooltip'),
onPressed: () async {
final ctrl = context.read<ZoomDrawerController>();
await ctrl.toggle?.call();
//await GoRouterHelper(context).push('/settings');
}).paddingLTRB(0, 0, 8, 0),
2024-07-08 21:29:52 -04:00
ProfileWidget(
profile: profile,
showPronouns: false,
).expanded(),
2024-06-24 19:44:08 -04:00
]).paddingAll(8),
MainPager(key: _mainPagerKey).expanded()
]));
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-05-27 18:04:00 -04:00
final activeChatLocalConversationKey =
2024-02-11 23:18:20 -05:00
context.watch<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-06-06 00:19:07 -04:00
return ChatComponentWidget.builder(
2024-06-15 23:29:15 -04:00
localConversationRecordKey: activeChatLocalConversationKey,
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;
// if (hasActiveChat) {
// _chatAnimationController.forward();
// } else {
// _chatAnimationController.reset();
// }
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-06-24 19:44:08 -04:00
////////////////////////////////////////////////////////////////////////////
final _mainPagerKey = GlobalKey(debugLabel: '_mainPagerKey');
2024-02-11 23:18:20 -05:00
}