💄 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 canPushNotification => isAndroid || isIOS || isMacOS;
static Future<String> getVersion() async {
var version = kIsWeb ? 'Web' : 'Unknown';
try {

View File

@ -96,7 +96,9 @@ class AccountProvider extends GetxController {
final notification = Notification.fromJson(packet.payload!);
notificationUnread++;
notifications.add(notification);
notifyMessage(notification.subject, notification.content);
if (!PlatformInfo.canPushNotification) {
notifyMessage(notification.subject, notification.content);
}
break;
}
},
@ -212,27 +214,31 @@ class AccountProvider extends GetxController {
Future<String?> _getDeviceUuid() async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if (PlatformInfo.isWeb) {
final WebBrowserInfo webInfo = await deviceInfo.webBrowserInfo;
final webInfo = await deviceInfo.webBrowserInfo;
return webInfo.vendor! +
webInfo.userAgent! +
webInfo.hardwareConcurrency.toString();
}
if (PlatformInfo.isAndroid) {
final AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
final androidInfo = await deviceInfo.androidInfo;
return androidInfo.id;
}
if (PlatformInfo.isIOS) {
final IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
final iosInfo = await deviceInfo.iosInfo;
return iosInfo.identifierForVendor!;
}
if (PlatformInfo.isLinux) {
final LinuxDeviceInfo linuxInfo = await deviceInfo.linuxInfo;
final linuxInfo = await deviceInfo.linuxInfo;
return linuxInfo.machineId!;
}
if (PlatformInfo.isWindows) {
final WindowsDeviceInfo windowsInfo = await deviceInfo.windowsInfo;
final windowsInfo = await deviceInfo.windowsInfo;
return windowsInfo.deviceId;
}
if (PlatformInfo.isMacOS) {
final macosInfo = await deviceInfo.macOsInfo;
return macosInfo.systemGUID;
}
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/home.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/title_shell.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/sidebar/empty_placeholder.dart';
abstract class AppRouter {
static GoRouter instance = GoRouter(
@ -203,20 +200,16 @@ abstract class AppRouter {
);
static final ShellRoute _accountRoute = ShellRoute(
builder: (context, state, child) => SidebarShell(
state: state,
sidebarFirst: true,
showAppBar: false,
sidebar: const AccountScreen(),
child: child,
),
builder: (context, state, child) => child,
routes: [
GoRoute(
path: '/account',
name: 'account',
builder: (context, state) => SolianTheme.isExtraLargeScreen(context)
? const EmptyPagePlaceholder()
: TitleShell(state: state, child: const AccountScreen()),
builder: (context, state) => TitleShell(
state: state,
isCenteredTitle: true,
child: const AccountScreen(),
),
),
GoRoute(
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/signup.dart';
import 'package:solian/widgets/account/account_heading.dart';
import 'package:solian/widgets/sized_container.dart';
class AccountScreen extends StatefulWidget {
const AccountScreen({super.key});
@ -85,31 +86,33 @@ class _AccountScreenState extends State<AccountScreen> {
);
}
return ListView(
children: [
const AccountHeading().paddingOnly(bottom: 8, top: 8),
...(actionItems.map(
(x) => ListTile(
return CenteredContainer(
child: ListView(
children: [
const AccountHeading().paddingOnly(bottom: 8, top: 8),
...(actionItems.map(
(x) => ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
leading: x.$1,
title: Text(x.$2),
onTap: () {
AppRouter.instance
.pushNamed(x.$3)
.then((_) => setState(() {}));
},
),
)),
ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
leading: x.$1,
title: Text(x.$2),
leading: const Icon(Icons.logout),
title: Text('signout'.tr),
onTap: () {
AppRouter.instance
.pushNamed(x.$3)
.then((_) => setState(() {}));
provider.signout();
setState(() {});
},
),
)),
ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
leading: const Icon(Icons.logout),
title: Text('signout'.tr),
onTap: () {
provider.signout();
setState(() {});
},
),
],
],
),
);
},
),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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