veilidchat/lib/pages/home.dart

146 lines
4.3 KiB
Dart
Raw Normal View History

2023-08-05 19:34:00 -04:00
import 'dart:async';
2023-08-07 00:55:57 -04:00
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
2023-01-08 22:27:33 -05:00
import 'package:flutter/material.dart';
2023-07-26 22:38:09 -04:00
import 'package:flutter_animate/flutter_animate.dart';
2023-01-09 22:50:34 -05:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2023-07-29 10:55:35 -04:00
import 'package:split_view/split_view.dart';
2023-07-26 22:38:09 -04:00
import 'package:signal_strength_indicator/signal_strength_indicator.dart';
2023-01-08 22:27:33 -05:00
2023-08-07 00:55:57 -04:00
import '../../entities/proto.dart' as proto;
2023-07-29 10:55:35 -04:00
import '../components/chat_component.dart';
2023-08-07 00:55:57 -04:00
import '../components/empty_chat_widget.dart';
2023-08-05 19:34:00 -04:00
import '../providers/account.dart';
2023-08-07 00:55:57 -04:00
import '../providers/chat.dart';
2023-08-05 19:34:00 -04:00
import '../providers/contact.dart';
2023-08-05 23:58:13 -04:00
import '../providers/contact_invite.dart';
2023-08-07 11:02:29 -04:00
import '../providers/conversation.dart';
2023-07-28 20:36:05 -04:00
import '../providers/window_control.dart';
2023-07-26 22:38:09 -04:00
import '../tools/tools.dart';
2023-07-28 20:36:05 -04:00
import 'main_pager/main_pager.dart';
2023-07-26 22:38:09 -04:00
class HomePage extends ConsumerStatefulWidget {
2023-01-09 22:50:34 -05:00
const HomePage({super.key});
static const path = '/home';
2023-01-08 22:27:33 -05:00
@override
2023-07-26 22:38:09 -04:00
HomePageState createState() => HomePageState();
2023-08-08 02:03:26 -04:00
static Widget buildChatComponent(BuildContext context, WidgetRef ref) {
final contactList = ref.watch(fetchContactListProvider).asData?.value ??
const IListConst([]);
final activeChat = ref.watch(activeChatStateProvider).asData?.value;
if (activeChat == null) {
return const EmptyChatWidget();
}
final activeAccountInfo =
ref.watch(fetchActiveAccountProvider).asData?.value;
if (activeAccountInfo == null) {
return const EmptyChatWidget();
}
final activeChatContactIdx = contactList.indexWhere(
(c) =>
proto.TypedKeyProto.fromProto(c.remoteConversationRecordKey) ==
activeChat,
);
if (activeChatContactIdx == -1) {
activeChatState.add(null);
return const EmptyChatWidget();
}
final activeChatContact = contactList[activeChatContactIdx];
return ChatComponent(
activeAccountInfo: activeAccountInfo,
activeChat: activeChat,
activeChatContact: activeChatContact);
}
}
2023-08-05 19:34:00 -04:00
2023-07-26 22:38:09 -04:00
class HomePageState extends ConsumerState<HomePage>
with TickerProviderStateMixin {
final _unfocusNode = FocusNode();
2023-07-28 20:36:05 -04:00
2023-07-26 22:38:09 -04:00
@override
void initState() {
super.initState();
2023-07-28 20:36:05 -04:00
WidgetsBinding.instance.addPostFrameCallback((_) async {
setState(() {});
await ref.read(windowControlProvider.notifier).changeWindowSetup(
TitleBarStyle.normal, OrientationCapability.normal);
});
2023-07-26 22:38:09 -04:00
}
@override
void dispose() {
_unfocusNode.dispose();
super.dispose();
}
2023-07-28 20:36:05 -04:00
// ignore: prefer_expression_function_bodies
Widget buildPhone(BuildContext context) {
return Material(
color: Colors.transparent, elevation: 4, child: MainPager());
}
// ignore: prefer_expression_function_bodies
Widget buildTabletLeftPane(BuildContext context) {
//
return Material(
color: Colors.transparent, elevation: 4, child: MainPager());
}
// ignore: prefer_expression_function_bodies
Widget buildTabletRightPane(BuildContext context) {
//
2023-08-08 02:03:26 -04:00
return HomePage.buildChatComponent(context, ref);
2023-07-28 20:36:05 -04:00
}
// ignore: prefer_expression_function_bodies
Widget buildTablet(BuildContext context) {
2023-07-29 10:55:35 -04:00
final theme = Theme.of(context);
final w = MediaQuery.of(context).size.width;
2023-07-28 20:36:05 -04:00
final children = [
2023-07-29 10:55:35 -04:00
ConstrainedBox(
constraints: BoxConstraints(minWidth: 300, maxWidth: 300),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: w / 2),
child: buildTabletLeftPane(context))),
Expanded(child: buildTabletRightPane(context)),
2023-07-28 20:36:05 -04:00
];
2023-07-29 10:55:35 -04:00
return Row(
children: children,
);
2023-07-28 20:36:05 -04:00
2023-07-29 10:55:35 -04:00
// final theme = MultiSplitViewTheme(
// data: isDesktop
// ? MultiSplitViewThemeData(
// dividerThickness: 1,
// dividerPainter: DividerPainters.grooved2(thickness: 1))
// : MultiSplitViewThemeData(
// dividerThickness: 3,
// dividerPainter: DividerPainters.grooved2(thickness: 1)),
// child: multiSplitView);
2023-07-28 20:36:05 -04:00
}
2023-07-26 22:38:09 -04:00
@override
2023-07-28 20:36:05 -04:00
Widget build(BuildContext context) {
ref.watch(windowControlProvider);
return SafeArea(
2023-07-26 22:38:09 -04:00
child: GestureDetector(
2023-07-28 20:36:05 -04:00
onTap: () => FocusScope.of(context).requestFocus(_unfocusNode),
child: responsiveVisibility(
context: context,
phone: false,
)
? buildTablet(context)
: buildPhone(context),
));
}
2023-01-08 22:27:33 -05:00
}