💄 Optimized for navigation drawer

This commit is contained in:
LittleSheep 2024-07-13 18:54:08 +08:00
parent 201c38800b
commit a68a78597e
15 changed files with 143 additions and 93 deletions

View File

@ -29,6 +29,8 @@ abstract class PlatformInfo {
static bool get canRecord => (isMobile || isMacOS); static bool get canRecord => (isMobile || isMacOS);
static bool get canPushNotification => isAndroid || isIOS || isMacOS;
static Future<String> getVersion() async { static Future<String> getVersion() async {
var version = kIsWeb ? 'Web' : 'Unknown'; var version = kIsWeb ? 'Web' : 'Unknown';
try { try {

View File

@ -96,7 +96,9 @@ class AccountProvider extends GetxController {
final notification = Notification.fromJson(packet.payload!); final notification = Notification.fromJson(packet.payload!);
notificationUnread++; notificationUnread++;
notifications.add(notification); notifications.add(notification);
if (!PlatformInfo.canPushNotification) {
notifyMessage(notification.subject, notification.content); notifyMessage(notification.subject, notification.content);
}
break; break;
} }
}, },
@ -212,27 +214,31 @@ class AccountProvider extends GetxController {
Future<String?> _getDeviceUuid() async { Future<String?> _getDeviceUuid() async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
final WebBrowserInfo webInfo = await deviceInfo.webBrowserInfo; final webInfo = await deviceInfo.webBrowserInfo;
return webInfo.vendor! + return webInfo.vendor! +
webInfo.userAgent! + webInfo.userAgent! +
webInfo.hardwareConcurrency.toString(); webInfo.hardwareConcurrency.toString();
} }
if (PlatformInfo.isAndroid) { if (PlatformInfo.isAndroid) {
final AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; final androidInfo = await deviceInfo.androidInfo;
return androidInfo.id; return androidInfo.id;
} }
if (PlatformInfo.isIOS) { if (PlatformInfo.isIOS) {
final IosDeviceInfo iosInfo = await deviceInfo.iosInfo; final iosInfo = await deviceInfo.iosInfo;
return iosInfo.identifierForVendor!; return iosInfo.identifierForVendor!;
} }
if (PlatformInfo.isLinux) { if (PlatformInfo.isLinux) {
final LinuxDeviceInfo linuxInfo = await deviceInfo.linuxInfo; final linuxInfo = await deviceInfo.linuxInfo;
return linuxInfo.machineId!; return linuxInfo.machineId!;
} }
if (PlatformInfo.isWindows) { if (PlatformInfo.isWindows) {
final WindowsDeviceInfo windowsInfo = await deviceInfo.windowsInfo; final windowsInfo = await deviceInfo.windowsInfo;
return windowsInfo.deviceId; return windowsInfo.deviceId;
} }
if (PlatformInfo.isMacOS) {
final macosInfo = await deviceInfo.macOsInfo;
return macosInfo.systemGUID;
}
return null; return null;
} }
} }

View File

@ -19,11 +19,8 @@ import 'package:solian/screens/realms/realm_organize.dart';
import 'package:solian/screens/realms/realm_view.dart'; import 'package:solian/screens/realms/realm_view.dart';
import 'package:solian/screens/home.dart'; import 'package:solian/screens/home.dart';
import 'package:solian/screens/posts/post_editor.dart'; import 'package:solian/screens/posts/post_editor.dart';
import 'package:solian/shells/sidebar_shell.dart';
import 'package:solian/shells/root_shell.dart'; import 'package:solian/shells/root_shell.dart';
import 'package:solian/shells/title_shell.dart'; import 'package:solian/shells/title_shell.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/sidebar/empty_placeholder.dart';
abstract class AppRouter { abstract class AppRouter {
static GoRouter instance = GoRouter( static GoRouter instance = GoRouter(
@ -203,20 +200,16 @@ abstract class AppRouter {
); );
static final ShellRoute _accountRoute = ShellRoute( static final ShellRoute _accountRoute = ShellRoute(
builder: (context, state, child) => SidebarShell( builder: (context, state, child) => child,
state: state,
sidebarFirst: true,
showAppBar: false,
sidebar: const AccountScreen(),
child: child,
),
routes: [ routes: [
GoRoute( GoRoute(
path: '/account', path: '/account',
name: 'account', name: 'account',
builder: (context, state) => SolianTheme.isExtraLargeScreen(context) builder: (context, state) => TitleShell(
? const EmptyPagePlaceholder() state: state,
: TitleShell(state: state, child: const AccountScreen()), isCenteredTitle: true,
child: const AccountScreen(),
),
), ),
GoRoute( GoRoute(
path: '/account/friend', path: '/account/friend',

View File

@ -7,6 +7,7 @@ import 'package:solian/router.dart';
import 'package:solian/screens/auth/signin.dart'; import 'package:solian/screens/auth/signin.dart';
import 'package:solian/screens/auth/signup.dart'; import 'package:solian/screens/auth/signup.dart';
import 'package:solian/widgets/account/account_heading.dart'; import 'package:solian/widgets/account/account_heading.dart';
import 'package:solian/widgets/sized_container.dart';
class AccountScreen extends StatefulWidget { class AccountScreen extends StatefulWidget {
const AccountScreen({super.key}); const AccountScreen({super.key});
@ -85,7 +86,8 @@ class _AccountScreenState extends State<AccountScreen> {
); );
} }
return ListView( return CenteredContainer(
child: ListView(
children: [ children: [
const AccountHeading().paddingOnly(bottom: 8, top: 8), const AccountHeading().paddingOnly(bottom: 8, top: 8),
...(actionItems.map( ...(actionItems.map(
@ -110,6 +112,7 @@ class _AccountScreenState extends State<AccountScreen> {
}, },
), ),
], ],
),
); );
}, },
), ),

View File

@ -46,7 +46,7 @@ class _ChatScreenState extends State<ChatScreen> {
appBar: AppBar( appBar: AppBar(
leading: AppBarLeadingButton.adaptive(context), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('chat'.tr), title: AppBarTitle('chat'.tr),
centerTitle: false, centerTitle: true,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
actions: [ actions: [
const BackgroundStateWidget(), const BackgroundStateWidget(),

View File

@ -54,6 +54,7 @@ class _PostDetailScreenState extends State<PostDetailScreen> {
isClickable: true, isClickable: true,
isFullDate: true, isFullDate: true,
isShowReply: false, isShowReply: false,
isContentSelectable: true,
), ),
), ),
), ),

View File

@ -61,7 +61,7 @@ class _RealmListScreenState extends State<RealmListScreen> {
appBar: AppBar( appBar: AppBar(
leading: AppBarLeadingButton.adaptive(context), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle('realm'.tr), title: AppBarTitle('realm'.tr),
centerTitle: false, centerTitle: true,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
actions: [ actions: [
const BackgroundStateWidget(), const BackgroundStateWidget(),

View File

@ -33,10 +33,7 @@ class RootShell extends StatelessWidget {
key: rootScaffoldKey, key: rootScaffoldKey,
drawer: SolianTheme.isLargeScreen(context) drawer: SolianTheme.isLargeScreen(context)
? null ? null
: AppNavigationDrawer( : AppNavigationDrawer(routeName: routeName),
key: const ValueKey('navigation-drawer'),
routeName: routeName,
),
body: SolianTheme.isLargeScreen(context) body: SolianTheme.isLargeScreen(context)
? Row( ? Row(
children: [ children: [

View File

@ -7,6 +7,7 @@ import 'package:solian/widgets/app_bar_leading.dart';
class TitleShell extends StatelessWidget { class TitleShell extends StatelessWidget {
final bool showAppBar; final bool showAppBar;
final bool isCenteredTitle;
final GoRouterState state; final GoRouterState state;
final Widget child; final Widget child;
@ -15,6 +16,7 @@ class TitleShell extends StatelessWidget {
required this.child, required this.child,
required this.state, required this.state,
this.showAppBar = true, this.showAppBar = true,
this.isCenteredTitle = false,
}); });
@override @override
@ -24,7 +26,7 @@ class TitleShell extends StatelessWidget {
? AppBar( ? AppBar(
leading: AppBarLeadingButton.adaptive(context), leading: AppBarLeadingButton.adaptive(context),
title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr), title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr),
centerTitle: false, centerTitle: isCenteredTitle,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
) )
: null, : null,

View File

@ -6,6 +6,7 @@ const messagesEnglish = {
'reset': 'Reset', 'reset': 'Reset',
'page': 'Page', 'page': 'Page',
'home': 'Home', 'home': 'Home',
'guest': 'Guest',
'draft': 'Draft', 'draft': 'Draft',
'draftSave': 'Save', 'draftSave': 'Save',
'draftBox': 'Draft Box', 'draftBox': 'Draft Box',
@ -53,6 +54,7 @@ const messagesEnglish = {
'aspectRatioSquare': 'Square', 'aspectRatioSquare': 'Square',
'aspectRatioPortrait': 'Portrait', 'aspectRatioPortrait': 'Portrait',
'aspectRatioLandscape': 'Landscape', 'aspectRatioLandscape': 'Landscape',
'unsignedIn': 'Unsigned in',
'signin': 'Sign in', 'signin': 'Sign in',
'signinRequired': 'Sign in', 'signinRequired': 'Sign in',
'signinRequiredHint': 'Sign in to get full access of Solar Network', 'signinRequiredHint': 'Sign in to get full access of Solar Network',
@ -88,6 +90,7 @@ const messagesEnglish = {
'postAction': 'Post', 'postAction': 'Post',
'postEdited': 'Edited at @date', 'postEdited': 'Edited at @date',
'postNewCreated': 'Created at @date', 'postNewCreated': 'Created at @date',
'postAttachmentTip': '@count attachment(s)',
'postInRealm': 'In realm @realm', 'postInRealm': 'In realm @realm',
'postDetail': 'Post', 'postDetail': 'Post',
'postReplies': 'Replies', 'postReplies': 'Replies',

View File

@ -9,6 +9,7 @@ const simplifiedChineseMessages = {
'confirm': '确认', 'confirm': '确认',
'leave': '离开', 'leave': '离开',
'loading': '载入中…', 'loading': '载入中…',
'guest': '游客',
'about': '关于', 'about': '关于',
'edit': '编辑', 'edit': '编辑',
'delete': '删除', 'delete': '删除',
@ -52,6 +53,7 @@ const simplifiedChineseMessages = {
'aspectRatioSquare': '方型', 'aspectRatioSquare': '方型',
'aspectRatioPortrait': '竖型', 'aspectRatioPortrait': '竖型',
'aspectRatioLandscape': '横型', 'aspectRatioLandscape': '横型',
'unsignedIn': '未登录',
'signin': '登录', 'signin': '登录',
'signinRequired': '需要登录', 'signinRequired': '需要登录',
'signinRequiredHint': '登陆以获得 Solar Network 的全部功能使用权。', 'signinRequiredHint': '登陆以获得 Solar Network 的全部功能使用权。',
@ -83,6 +85,7 @@ const simplifiedChineseMessages = {
'postEdited': '编辑于 @date', 'postEdited': '编辑于 @date',
'postNewCreated': '创建于 @date', 'postNewCreated': '创建于 @date',
'postInRealm': '发表于 @realm', 'postInRealm': '发表于 @realm',
'postAttachmentTip': '@count 个附件',
'postDetail': '帖子详情', 'postDetail': '帖子详情',
'postReplies': '帖子回复', 'postReplies': '帖子回复',
'postPublish': '编辑帖子', 'postPublish': '编辑帖子',

View File

@ -5,8 +5,13 @@ import 'package:url_launcher/url_launcher_string.dart';
class MarkdownTextContent extends StatelessWidget { class MarkdownTextContent extends StatelessWidget {
final String content; final String content;
final bool isSelectable;
const MarkdownTextContent({super.key, required this.content}); const MarkdownTextContent({
super.key,
required this.content,
this.isSelectable = false,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -15,6 +20,7 @@ class MarkdownTextContent extends StatelessWidget {
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
data: content, data: content,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
selectable: isSelectable,
styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith( styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith(
horizontalRuleDecoration: BoxDecoration( horizontalRuleDecoration: BoxDecoration(
border: Border( border: Border(

View File

@ -8,16 +8,16 @@ abstract class AppNavigation {
label: 'home'.tr, label: 'home'.tr,
page: 'home', page: 'home',
), ),
AppNavigationDestination(
icon: const Icon(Icons.forum),
label: 'chat'.tr,
page: 'chat',
),
AppNavigationDestination( AppNavigationDestination(
icon: const Icon(Icons.workspaces), icon: const Icon(Icons.workspaces),
label: 'realms'.tr, label: 'realms'.tr,
page: 'realms', page: 'realms',
), ),
AppNavigationDestination(
icon: const Icon(Icons.forum),
label: 'channelTypeDirect'.tr,
page: 'chat',
),
]; ];
static List<String> get destinationPages => static List<String> get destinationPages =>

View File

@ -86,8 +86,18 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
FutureBuilder( FutureBuilder(
future: auth.getProfileWithCheck(), future: auth.getProfileWithCheck(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == null) { if (snapshot.data == null) {
return const SizedBox(); return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 28),
leading: const Icon(Icons.account_circle),
title: Text('guest'.tr),
subtitle: Text('unsignedIn'.tr),
onTap: () {
AppRouter.instance.goNamed('account');
setState(() => _selectedIndex = null);
closeDrawer();
},
);
} }
return ListTile( return ListTile(
@ -147,11 +157,12 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
), ),
onTap: () { onTap: () {
AppRouter.instance.goNamed('account'); AppRouter.instance.goNamed('account');
setState(() => _selectedIndex = null);
closeDrawer(); closeDrawer();
}, },
).paddingOnly(top: 8); );
}, },
), ).paddingOnly(top: 8),
const Divider(thickness: 0.3, height: 1).paddingOnly( const Divider(thickness: 0.3, height: 1).paddingOnly(
bottom: 12, bottom: 12,
top: 8, top: 8,
@ -176,26 +187,34 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
return Column( return Column(
children: [ children: [
ExpansionTile( Theme(
title: Text('chat'.tr), data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
child: ExpansionTile(
title: Text('channels'.tr),
tilePadding: const EdgeInsets.symmetric(horizontal: 24), tilePadding: const EdgeInsets.symmetric(horizontal: 24),
children: [ children: [
Obx( Obx(
() => SizedBox( () => SizedBox(
height: 360, height: 360,
child: RefreshIndicator(
onRefresh: () =>
_channels.refreshAvailableChannel(),
child: ChannelListWidget( child: ChannelListWidget(
channels: _channels.groupChannels, channels: _channels.groupChannels,
selfId: selfId, selfId: selfId,
isDense: true, isDense: true,
useReplace: true, useReplace: true,
onSelected: (_) { onSelected: (_) {
setState(() => _selectedIndex = null);
closeDrawer(); closeDrawer();
}, },
), ),
), ),
), ),
),
], ],
), ),
),
], ],
); );
}, },

View File

@ -20,6 +20,7 @@ class PostItem extends StatefulWidget {
final bool isShowReply; final bool isShowReply;
final bool isShowEmbed; final bool isShowEmbed;
final bool isFullDate; final bool isFullDate;
final bool isContentSelectable;
final String? overrideAttachmentParent; final String? overrideAttachmentParent;
const PostItem({ const PostItem({
@ -31,6 +32,7 @@ class PostItem extends StatefulWidget {
this.isShowReply = true, this.isShowReply = true,
this.isShowEmbed = true, this.isShowEmbed = true,
this.isFullDate = false, this.isFullDate = false,
this.isContentSelectable = false,
this.overrideAttachmentParent, this.overrideAttachmentParent,
}); });
@ -41,6 +43,9 @@ class PostItem extends StatefulWidget {
class _PostItemState extends State<PostItem> { class _PostItemState extends State<PostItem> {
late final Post item; late final Post item;
Color get _unFocusColor =>
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
@override @override
void initState() { void initState() {
item = widget.item; item = widget.item;
@ -96,7 +101,7 @@ class _PostItemState extends State<PostItem> {
textAlign: TextAlign.left, textAlign: TextAlign.left,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.75), color: _unFocusColor,
), ),
)); ));
} }
@ -119,17 +124,14 @@ class _PostItemState extends State<PostItem> {
FaIcon( FaIcon(
FontAwesomeIcons.reply, FontAwesomeIcons.reply,
size: 16, size: 16,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.75), color: _unFocusColor,
), ),
Expanded( Expanded(
child: Text( child: Text(
'postRepliedNotify'.trParams( 'postRepliedNotify'.trParams(
{'username': '@${widget.item.replyTo!.author.name}'}, {'username': '@${widget.item.replyTo!.author.name}'},
), ),
style: TextStyle( style: TextStyle(color: _unFocusColor),
color:
Theme.of(context).colorScheme.onSurface.withOpacity(0.75),
),
).paddingOnly(left: 6), ).paddingOnly(left: 6),
), ),
], ],
@ -154,17 +156,14 @@ class _PostItemState extends State<PostItem> {
FaIcon( FaIcon(
FontAwesomeIcons.retweet, FontAwesomeIcons.retweet,
size: 16, size: 16,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.75), color: _unFocusColor,
), ),
Expanded( Expanded(
child: Text( child: Text(
'postRepostedNotify'.trParams( 'postRepostedNotify'.trParams(
{'username': '@${widget.item.repostTo!.author.name}'}, {'username': '@${widget.item.repostTo!.author.name}'},
), ),
style: TextStyle( style: TextStyle(color: _unFocusColor),
color:
Theme.of(context).colorScheme.onSurface.withOpacity(0.75),
),
).paddingOnly(left: 6), ).paddingOnly(left: 6),
), ),
], ],
@ -190,18 +189,32 @@ class _PostItemState extends State<PostItem> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
buildHeader().paddingSymmetric(horizontal: 12), buildHeader().paddingSymmetric(horizontal: 12),
MarkdownTextContent(content: item.content).paddingOnly( MarkdownTextContent(
content: item.content,
isSelectable: widget.isContentSelectable,
).paddingOnly(
left: 16, left: 16,
right: 12, right: 12,
top: 2, top: 2,
bottom: hasAttachment ? 4 : 0, bottom: hasAttachment ? 4 : 0,
), ),
buildFooter().paddingOnly(left: 16), buildFooter().paddingOnly(left: 16),
AttachmentList( if (item.attachments?.isNotEmpty ?? false)
parentId: widget.overrideAttachmentParent ?? widget.item.alias, Row(
attachmentsId: item.attachments ?? List.empty(), children: [
divided: true, Icon(
Icons.attachment,
size: 18,
color: _unFocusColor,
).paddingOnly(right: 6),
Text(
'postAttachmentTip'.trParams(
{'count': item.attachments!.length.toString()},
), ),
style: TextStyle(color: _unFocusColor),
)
],
).paddingOnly(left: 16, top: 4),
], ],
); );
} }
@ -231,8 +244,10 @@ class _PostItemState extends State<PostItem> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
buildHeader(), buildHeader(),
MarkdownTextContent(content: item.content) MarkdownTextContent(
.paddingOnly(left: 12, right: 8), content: item.content,
isSelectable: widget.isContentSelectable,
).paddingOnly(left: 12, right: 8),
if (widget.item.replyTo != null && widget.isShowEmbed) if (widget.item.replyTo != null && widget.isShowEmbed)
GestureDetector( GestureDetector(
child: buildReply(context).paddingOnly(top: 4), child: buildReply(context).paddingOnly(top: 4),