2024-08-07 10:24:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
2024-09-12 15:55:31 +00:00
|
|
|
import 'package:solian/models/realm.dart';
|
|
|
|
import 'package:solian/providers/auth.dart';
|
2024-08-07 10:24:16 +00:00
|
|
|
import 'package:solian/providers/content/channel.dart';
|
2024-09-12 15:55:31 +00:00
|
|
|
import 'package:solian/providers/content/realm.dart';
|
2024-09-12 16:17:56 +00:00
|
|
|
import 'package:solian/providers/navigation.dart';
|
2024-09-12 15:55:31 +00:00
|
|
|
import 'package:solian/widgets/account/account_avatar.dart';
|
|
|
|
import 'package:solian/widgets/channel/channel_list.dart';
|
2024-08-07 10:24:16 +00:00
|
|
|
|
2024-09-12 15:55:31 +00:00
|
|
|
class AppNavigationRegion extends StatefulWidget {
|
2024-08-21 09:00:59 +00:00
|
|
|
final bool isCollapsed;
|
2024-08-07 10:24:16 +00:00
|
|
|
|
2024-08-21 11:11:27 +00:00
|
|
|
const AppNavigationRegion({
|
2024-08-21 09:00:59 +00:00
|
|
|
super.key,
|
|
|
|
this.isCollapsed = false,
|
|
|
|
});
|
2024-08-07 10:24:16 +00:00
|
|
|
|
2024-09-12 15:55:31 +00:00
|
|
|
@override
|
|
|
|
State<AppNavigationRegion> createState() => _AppNavigationRegionState();
|
|
|
|
}
|
|
|
|
|
2024-09-13 12:22:10 +00:00
|
|
|
class _AppNavigationRegionState extends State<AppNavigationRegion> {
|
2024-09-12 15:55:31 +00:00
|
|
|
bool _isTryingExit = false;
|
|
|
|
|
|
|
|
void _focusRealm(Realm item) {
|
2024-09-13 12:22:10 +00:00
|
|
|
setState(
|
|
|
|
() => Get.find<NavigationStateProvider>().focusedRealm.value = item,
|
|
|
|
);
|
2024-09-12 15:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _unFocusRealm() {
|
2024-09-13 12:22:10 +00:00
|
|
|
setState(
|
|
|
|
() => Get.find<NavigationStateProvider>().focusedRealm.value = null,
|
|
|
|
);
|
2024-09-12 15:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildRealmFocusAvatar() {
|
2024-09-12 16:17:56 +00:00
|
|
|
final focusedRealm = Get.find<NavigationStateProvider>().focusedRealm.value;
|
2024-09-13 12:22:10 +00:00
|
|
|
return GestureDetector(
|
|
|
|
child: MouseRegion(
|
|
|
|
child: AnimatedSwitcher(
|
|
|
|
switchInCurve: Curves.fastOutSlowIn,
|
|
|
|
switchOutCurve: Curves.fastOutSlowIn,
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
transitionBuilder: (child, animation) {
|
|
|
|
return ScaleTransition(
|
|
|
|
scale: animation,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: _isTryingExit
|
|
|
|
? CircleAvatar(
|
2024-09-12 15:55:31 +00:00
|
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
|
|
child: const Icon(
|
|
|
|
Icons.arrow_back,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 16,
|
|
|
|
),
|
|
|
|
).paddingSymmetric(
|
|
|
|
vertical: 8,
|
2024-09-13 12:22:10 +00:00
|
|
|
)
|
|
|
|
: _buildEntryAvatar(focusedRealm!),
|
|
|
|
),
|
|
|
|
onEnter: (_) => setState(() => _isTryingExit = true),
|
|
|
|
onExit: (_) => setState(() => _isTryingExit = false),
|
2024-09-12 15:55:31 +00:00
|
|
|
),
|
2024-09-13 12:22:10 +00:00
|
|
|
onTap: () => _unFocusRealm(),
|
2024-08-07 10:24:16 +00:00
|
|
|
);
|
2024-09-12 15:55:31 +00:00
|
|
|
}
|
2024-08-07 10:24:16 +00:00
|
|
|
|
2024-09-12 15:55:31 +00:00
|
|
|
Widget _buildEntryAvatar(Realm item) {
|
|
|
|
return Hero(
|
|
|
|
tag: Key('region-realm-avatar-${item.id}'),
|
|
|
|
child: (item.avatar?.isNotEmpty ?? false)
|
|
|
|
? AccountAvatar(content: item.avatar)
|
|
|
|
: CircleAvatar(
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
|
|
child: const Icon(
|
|
|
|
Icons.workspaces,
|
|
|
|
color: Colors.white,
|
|
|
|
size: 16,
|
|
|
|
),
|
|
|
|
).paddingSymmetric(
|
|
|
|
vertical: 8,
|
|
|
|
),
|
|
|
|
);
|
2024-08-07 10:24:16 +00:00
|
|
|
}
|
|
|
|
|
2024-09-12 15:55:31 +00:00
|
|
|
Widget _buildEntry(BuildContext context, Realm item) {
|
2024-09-13 12:22:10 +00:00
|
|
|
const padding = EdgeInsets.symmetric(horizontal: 20, vertical: 8);
|
2024-08-07 10:24:16 +00:00
|
|
|
|
2024-09-12 15:55:31 +00:00
|
|
|
if (widget.isCollapsed) {
|
2024-08-21 09:00:59 +00:00
|
|
|
return InkWell(
|
2024-09-13 12:22:10 +00:00
|
|
|
child: _buildEntryAvatar(item).paddingSymmetric(vertical: 8),
|
2024-09-12 15:55:31 +00:00
|
|
|
onTap: () => _focusRealm(item),
|
2024-08-21 09:00:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-07 10:24:16 +00:00
|
|
|
return ListTile(
|
|
|
|
minTileHeight: 0,
|
2024-09-12 15:55:31 +00:00
|
|
|
leading: _buildEntryAvatar(item),
|
2024-08-07 10:24:16 +00:00
|
|
|
contentPadding: padding,
|
|
|
|
title: Text(item.name),
|
|
|
|
subtitle: Text(
|
|
|
|
item.description,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
2024-09-12 15:55:31 +00:00
|
|
|
onTap: () => _focusRealm(item),
|
2024-08-07 10:24:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-09-12 15:55:31 +00:00
|
|
|
final RealmProvider realms = Get.find();
|
2024-08-07 10:24:16 +00:00
|
|
|
final ChannelProvider channels = Get.find();
|
2024-09-12 15:55:31 +00:00
|
|
|
final AuthProvider auth = Get.find();
|
2024-09-12 16:17:56 +00:00
|
|
|
final NavigationStateProvider navState = Get.find();
|
|
|
|
|
|
|
|
return Obx(
|
2024-09-13 12:22:10 +00:00
|
|
|
() => AnimatedSwitcher(
|
|
|
|
switchInCurve: Curves.fastOutSlowIn,
|
|
|
|
switchOutCurve: Curves.fastOutSlowIn,
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
transitionBuilder: (child, animation) {
|
2024-09-12 16:17:56 +00:00
|
|
|
return SlideTransition(
|
2024-09-13 12:22:10 +00:00
|
|
|
position: Tween<Offset>(
|
|
|
|
begin: const Offset(1.0, 0.0),
|
|
|
|
end: Offset.zero,
|
|
|
|
).animate(animation),
|
|
|
|
child: Material(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
|
|
|
child: child,
|
|
|
|
),
|
2024-09-12 16:17:56 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
child: navState.focusedRealm.value == null
|
|
|
|
? widget.isCollapsed
|
|
|
|
? CustomScrollView(
|
|
|
|
slivers: [
|
2024-09-13 12:22:10 +00:00
|
|
|
const SliverPadding(padding: EdgeInsets.only(top: 16)),
|
2024-09-12 16:17:56 +00:00
|
|
|
SliverList.builder(
|
|
|
|
itemCount: realms.availableRealms.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final element = realms.availableRealms[index];
|
|
|
|
return Tooltip(
|
|
|
|
message: element.name,
|
|
|
|
child: _buildEntry(context, element),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
SliverList.builder(
|
|
|
|
itemCount: realms.availableRealms.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final element = realms.availableRealms[index];
|
|
|
|
return _buildEntry(context, element);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2024-09-12 15:55:31 +00:00
|
|
|
)
|
2024-09-12 16:17:56 +00:00
|
|
|
: Column(
|
|
|
|
children: [
|
|
|
|
if (widget.isCollapsed)
|
|
|
|
Tooltip(
|
|
|
|
message: navState.focusedRealm.value!.name,
|
2024-09-13 12:22:10 +00:00
|
|
|
child: _buildRealmFocusAvatar().paddingOnly(
|
|
|
|
top: 24,
|
|
|
|
bottom: 8,
|
2024-09-12 16:17:56 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
else
|
|
|
|
ListTile(
|
|
|
|
minTileHeight: 0,
|
|
|
|
tileColor:
|
|
|
|
Theme.of(context).colorScheme.surfaceContainerLow,
|
|
|
|
leading: _buildRealmFocusAvatar(),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 20, vertical: 8),
|
|
|
|
title: Text(navState.focusedRealm.value!.name),
|
|
|
|
subtitle: Text(
|
|
|
|
navState.focusedRealm.value!.description,
|
|
|
|
maxLines: 1,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
2024-09-12 15:55:31 +00:00
|
|
|
),
|
2024-09-12 16:17:56 +00:00
|
|
|
Expanded(
|
|
|
|
child: Obx(
|
|
|
|
() => ChannelListWidget(
|
2024-09-13 12:22:10 +00:00
|
|
|
useReplace: true,
|
2024-09-12 16:17:56 +00:00
|
|
|
channels: channels.availableChannels
|
2024-09-13 12:22:10 +00:00
|
|
|
.where((x) =>
|
|
|
|
x.realm?.id == navState.focusedRealm.value?.id)
|
2024-09-12 16:17:56 +00:00
|
|
|
.toList(),
|
2024-09-13 12:22:10 +00:00
|
|
|
isCollapsed: widget.isCollapsed,
|
2024-09-12 16:17:56 +00:00
|
|
|
selfId: auth.userProfile.value!['id'],
|
|
|
|
noCategory: true,
|
|
|
|
),
|
2024-09-12 15:55:31 +00:00
|
|
|
),
|
|
|
|
),
|
2024-09-12 16:17:56 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2024-09-12 15:55:31 +00:00
|
|
|
);
|
2024-08-07 10:24:16 +00:00
|
|
|
}
|
|
|
|
}
|