♻️ Refactored navigation

This commit is contained in:
LittleSheep 2024-07-12 16:19:54 +08:00
parent 48b76ed574
commit aa43eaa0eb
27 changed files with 115 additions and 197 deletions

View File

@ -17,7 +17,7 @@ import 'package:solian/screens/realms.dart';
import 'package:solian/screens/realms/realm_detail.dart'; import 'package:solian/screens/realms/realm_detail.dart';
import 'package:solian/screens/realms/realm_organize.dart'; 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/feed.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/basic_shell.dart'; import 'package:solian/shells/basic_shell.dart';
import 'package:solian/shells/root_shell.dart'; import 'package:solian/shells/root_shell.dart';
@ -48,8 +48,8 @@ abstract class AppRouter {
routes: [ routes: [
GoRoute( GoRoute(
path: '/', path: '/',
name: 'feed', name: 'home',
builder: (context, state) => const FeedScreen(), builder: (context, state) => const HomeScreen(),
), ),
GoRoute( GoRoute(
path: '/feed/search', path: '/feed/search',

View File

@ -4,7 +4,7 @@ import 'package:solian/exts.dart';
import 'package:solian/models/articles.dart'; import 'package:solian/models/articles.dart';
import 'package:solian/providers/content/feed.dart'; import 'package:solian/providers/content/feed.dart';
import 'package:solian/widgets/articles/article_item.dart'; import 'package:solian/widgets/articles/article_item.dart';
import 'package:solian/widgets/centered_container.dart'; import 'package:solian/widgets/sized_container.dart';
class ArticleDetailScreen extends StatefulWidget { class ArticleDetailScreen extends StatefulWidget {
final String alias; final String alias;

View File

@ -10,7 +10,6 @@ import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/attachments/attachment_publish.dart'; import 'package:solian/widgets/attachments/attachment_publish.dart';
import 'package:solian/widgets/feed/feed_tags_field.dart'; import 'package:solian/widgets/feed/feed_tags_field.dart';
import 'package:solian/widgets/prev_page.dart';
import 'package:textfield_tags/textfield_tags.dart'; import 'package:textfield_tags/textfield_tags.dart';
import 'package:badges/badges.dart' as badges; import 'package:badges/badges.dart' as badges;
@ -133,7 +132,6 @@ class _ArticlePublishScreenState extends State<ArticlePublishScreen> {
title: AppBarTitle('articlePublish'.tr), title: AppBarTitle('articlePublish'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: const PrevPageButton(),
actions: [ actions: [
TextButton( TextButton(
onPressed: _isBusy ? null : () => applyPost(), onPressed: _isBusy ? null : () => applyPost(),

View File

@ -7,7 +7,6 @@ import 'package:solian/providers/content/call.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/chat/call/call_controls.dart'; import 'package:solian/widgets/chat/call/call_controls.dart';
import 'package:solian/widgets/chat/call/call_participant.dart'; import 'package:solian/widgets/chat/call/call_participant.dart';
import 'package:solian/widgets/prev_page.dart';
class CallScreen extends StatefulWidget { class CallScreen extends StatefulWidget {
const CallScreen({super.key}); const CallScreen({super.key});
@ -72,7 +71,6 @@ class _CallScreenState extends State<CallScreen> {
), ),
]), ]),
), ),
leading: const PrevPageButton(),
), ),
body: SafeArea( body: SafeArea(
child: Obx( child: Obx(

View File

@ -9,7 +9,6 @@ import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/prev_page.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
class ChannelOrganizeArguments { class ChannelOrganizeArguments {
@ -112,7 +111,6 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
title: AppBarTitle('channelOrganizing'.tr), title: AppBarTitle('channelOrganizing'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: const PrevPageButton(),
actions: [ actions: [
TextButton( TextButton(
onPressed: _isBusy ? null : () => applyChannel(), onPressed: _isBusy ? null : () => applyChannel(),

View File

@ -12,7 +12,6 @@ import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/channel/channel_list.dart'; import 'package:solian/widgets/channel/channel_list.dart';
import 'package:solian/widgets/chat/call/chat_call_indicator.dart'; import 'package:solian/widgets/chat/call/chat_call_indicator.dart';
import 'package:solian/widgets/current_state_action.dart'; import 'package:solian/widgets/current_state_action.dart';
import 'package:solian/widgets/drawer_button.dart' as drawer;
class ChatScreen extends StatefulWidget { class ChatScreen extends StatefulWidget {
const ChatScreen({super.key}); const ChatScreen({super.key});
@ -95,7 +94,6 @@ class _ChatScreenState extends State<ChatScreen> {
title: AppBarTitle('chat'.tr), title: AppBarTitle('chat'.tr),
centerTitle: false, centerTitle: false,
floating: true, floating: true,
leading: const drawer.DrawerButton(),
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
actions: [ actions: [
const BackgroundStateWidget(), const BackgroundStateWidget(),

View File

@ -6,14 +6,13 @@ import 'package:solian/models/feed.dart';
import 'package:solian/models/pagination.dart'; import 'package:solian/models/pagination.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:solian/providers/content/feed.dart'; import 'package:solian/providers/content/feed.dart';
import 'package:solian/screens/feed.dart'; import 'package:solian/screens/home.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/articles/article_action.dart'; import 'package:solian/widgets/articles/article_action.dart';
import 'package:solian/widgets/articles/article_owned_list.dart'; import 'package:solian/widgets/articles/article_owned_list.dart';
import 'package:solian/widgets/posts/post_action.dart'; import 'package:solian/widgets/posts/post_action.dart';
import 'package:solian/widgets/posts/post_owned_list.dart'; import 'package:solian/widgets/posts/post_owned_list.dart';
import 'package:solian/widgets/prev_page.dart';
class DraftBoxScreen extends StatefulWidget { class DraftBoxScreen extends StatefulWidget {
const DraftBoxScreen({super.key}); const DraftBoxScreen({super.key});
@ -66,7 +65,6 @@ class _DraftBoxScreenState extends State<DraftBoxScreen> {
title: AppBarTitle('draftBox'.tr), title: AppBarTitle('draftBox'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: const PrevPageButton(),
actions: [ actions: [
FeedCreationButton( FeedCreationButton(
hideDraftBox: true, hideDraftBox: true,

View File

@ -11,16 +11,15 @@ import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/current_state_action.dart'; import 'package:solian/widgets/current_state_action.dart';
import 'package:solian/widgets/feed/feed_list.dart'; import 'package:solian/widgets/feed/feed_list.dart';
import 'package:solian/widgets/drawer_button.dart' as drawer;
class FeedScreen extends StatefulWidget { class HomeScreen extends StatefulWidget {
const FeedScreen({super.key}); const HomeScreen({super.key});
@override @override
State<FeedScreen> createState() => _FeedScreenState(); State<HomeScreen> createState() => _HomeScreenState();
} }
class _FeedScreenState extends State<FeedScreen> { class _HomeScreenState extends State<HomeScreen> {
final PagingController<int, FeedRecord> _pagingController = final PagingController<int, FeedRecord> _pagingController =
PagingController(firstPageKey: 0); PagingController(firstPageKey: 0);
@ -60,11 +59,10 @@ class _FeedScreenState extends State<FeedScreen> {
child: CustomScrollView( child: CustomScrollView(
slivers: [ slivers: [
SliverAppBar( SliverAppBar(
title: AppBarTitle('feed'.tr), title: AppBarTitle('home'.tr),
centerTitle: false, centerTitle: false,
floating: true, floating: true,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: const drawer.DrawerButton(),
actions: [ actions: [
const BackgroundStateWidget(), const BackgroundStateWidget(),
const NotificationButton(), const NotificationButton(),

View File

@ -3,7 +3,7 @@ import 'package:get/get.dart';
import 'package:solian/exts.dart'; import 'package:solian/exts.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:solian/providers/content/feed.dart'; import 'package:solian/providers/content/feed.dart';
import 'package:solian/widgets/centered_container.dart'; import 'package:solian/widgets/sized_container.dart';
import 'package:solian/widgets/posts/post_item.dart'; import 'package:solian/widgets/posts/post_item.dart';
import 'package:solian/widgets/posts/post_replies.dart'; import 'package:solian/widgets/posts/post_replies.dart';

View File

@ -12,7 +12,6 @@ import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/attachments/attachment_publish.dart'; import 'package:solian/widgets/attachments/attachment_publish.dart';
import 'package:solian/widgets/posts/post_item.dart'; import 'package:solian/widgets/posts/post_item.dart';
import 'package:solian/widgets/feed/feed_tags_field.dart'; import 'package:solian/widgets/feed/feed_tags_field.dart';
import 'package:solian/widgets/prev_page.dart';
import 'package:textfield_tags/textfield_tags.dart'; import 'package:textfield_tags/textfield_tags.dart';
import 'package:badges/badges.dart' as badges; import 'package:badges/badges.dart' as badges;
@ -137,7 +136,6 @@ class _PostPublishScreenState extends State<PostPublishScreen> {
title: AppBarTitle('postPublish'.tr), title: AppBarTitle('postPublish'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: const PrevPageButton(),
actions: [ actions: [
TextButton( TextButton(
onPressed: _isBusy ? null : () => applyPost(), onPressed: _isBusy ? null : () => applyPost(),

View File

@ -11,7 +11,6 @@ import 'package:solian/theme.dart';
import 'package:solian/widgets/account/signin_required_overlay.dart'; import 'package:solian/widgets/account/signin_required_overlay.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/current_state_action.dart'; import 'package:solian/widgets/current_state_action.dart';
import 'package:solian/widgets/drawer_button.dart' as drawer;
class RealmListScreen extends StatefulWidget { class RealmListScreen extends StatefulWidget {
const RealmListScreen({super.key}); const RealmListScreen({super.key});
@ -80,7 +79,6 @@ class _RealmListScreenState extends State<RealmListScreen> {
title: AppBarTitle('realm'.tr), title: AppBarTitle('realm'.tr),
centerTitle: false, centerTitle: false,
floating: true, floating: true,
leading: const drawer.DrawerButton(),
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
actions: [ actions: [
const BackgroundStateWidget(), const BackgroundStateWidget(),

View File

@ -7,7 +7,6 @@ import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/prev_page.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
class RealmOrganizeArguments { class RealmOrganizeArguments {
@ -102,7 +101,6 @@ class _RealmOrganizeScreenState extends State<RealmOrganizeScreen> {
title: AppBarTitle('realmOrganizing'.tr), title: AppBarTitle('realmOrganizing'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: const PrevPageButton(),
actions: [ actions: [
TextButton( TextButton(
onPressed: _isBusy ? null : () => applyRealm(), onPressed: _isBusy ? null : () => applyRealm(),

View File

@ -1,10 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:solian/router.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/prev_page.dart';
import 'package:solian/widgets/sidebar/sidebar_placeholder.dart'; import 'package:solian/widgets/sidebar/sidebar_placeholder.dart';
class BasicShell extends StatelessWidget { class BasicShell extends StatelessWidget {
@ -42,16 +40,12 @@ class BasicShell extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final canPop = AppRouter.instance.canPop();
return Scaffold( return Scaffold(
appBar: showAppBar appBar: showAppBar
? AppBar( ? AppBar(
title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr), title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: canPop ? const PrevPageButton() : null,
automaticallyImplyLeading: false,
) )
: null, : null,
body: SolianTheme.isLargeScreen(context) body: SolianTheme.isLargeScreen(context)

View File

@ -1,10 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:solian/router.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/prev_page.dart';
class CenteredShell extends StatelessWidget { class CenteredShell extends StatelessWidget {
final bool showAppBar; final bool showAppBar;
@ -20,16 +18,12 @@ class CenteredShell extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final canPop = AppRouter.instance.canPop();
return Scaffold( return Scaffold(
appBar: showAppBar appBar: showAppBar
? AppBar( ? AppBar(
title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr), title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: canPop ? const PrevPageButton() : null,
automaticallyImplyLeading: false,
) )
: null, : null,
body: Center( body: Center(

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/navigation/app_navigation_drawer.dart'; import 'package:solian/widgets/navigation/app_navigation_drawer.dart';
import 'package:solian/widgets/navigation/app_navigation_rail.dart';
final GlobalKey<ScaffoldState> rootScaffoldKey = GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> rootScaffoldKey = GlobalKey<ScaffoldState>();
@ -32,14 +31,16 @@ class RootShell extends StatelessWidget {
return Scaffold( return Scaffold(
key: rootScaffoldKey, key: rootScaffoldKey,
drawer: AppNavigationDrawer( drawer: SolianTheme.isLargeScreen(context)
key: const ValueKey('navigation-drawer'), ? null
routeName: routeName, : AppNavigationDrawer(
), key: const ValueKey('navigation-drawer'),
routeName: routeName,
),
body: SolianTheme.isLargeScreen(context) body: SolianTheme.isLargeScreen(context)
? Row( ? Row(
children: [ children: [
if (showNavigation) const AppNavigationRail(), if (showNavigation) AppNavigationDrawer(routeName: routeName),
if (showNavigation) if (showNavigation)
const VerticalDivider(thickness: 0.3, width: 1), const VerticalDivider(thickness: 0.3, width: 1),
Expanded(child: child), Expanded(child: child),

View File

@ -1,11 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:solian/router.dart';
import 'package:solian/theme.dart'; import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_title.dart'; import 'package:solian/widgets/app_bar_title.dart';
import 'package:solian/widgets/prev_page.dart' as prev;
import 'package:solian/widgets/drawer_button.dart' as drawer;
class TitleShell extends StatelessWidget { class TitleShell extends StatelessWidget {
final bool showAppBar; final bool showAppBar;
@ -21,18 +18,12 @@ class TitleShell extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final canPop = AppRouter.instance.canPop();
return Scaffold( return Scaffold(
appBar: showAppBar appBar: showAppBar
? AppBar( ? AppBar(
title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr), title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr),
centerTitle: false, centerTitle: false,
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
leading: canPop
? const prev.PrevPageButton()
: const drawer.DrawerButton(),
automaticallyImplyLeading: false,
) )
: null, : null,
body: child, body: child,

View File

@ -5,6 +5,7 @@ const messagesEnglish = {
'next': 'Next', 'next': 'Next',
'reset': 'Reset', 'reset': 'Reset',
'page': 'Page', 'page': 'Page',
'home': 'Home',
'draft': 'Draft', 'draft': 'Draft',
'draftSave': 'Save', 'draftSave': 'Save',
'draftBox': 'Draft Box', 'draftBox': 'Draft Box',

View File

@ -2,6 +2,7 @@ const simplifiedChineseMessages = {
'done': '完成', 'done': '完成',
'hide': '隐藏', 'hide': '隐藏',
'okay': '确认', 'okay': '确认',
'home': '首页',
'next': '下一步', 'next': '下一步',
'reset': '重置', 'reset': '重置',
'cancel': '取消', 'cancel': '取消',

View File

@ -5,7 +5,7 @@ import 'package:solian/models/articles.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/widgets/articles/article_action.dart'; import 'package:solian/widgets/articles/article_action.dart';
import 'package:solian/widgets/articles/article_item.dart'; import 'package:solian/widgets/articles/article_item.dart';
import 'package:solian/widgets/centered_container.dart'; import 'package:solian/widgets/sized_container.dart';
class ArticleListWidget extends StatelessWidget { class ArticleListWidget extends StatelessWidget {
final bool isShowEmbed; final bool isShowEmbed;

View File

@ -1,19 +0,0 @@
import 'package:flutter/material.dart';
import 'package:solian/shells/root_shell.dart';
class DrawerButton extends StatelessWidget {
const DrawerButton({super.key});
void openDrawer() {
rootScaffoldKey.currentState!.openDrawer();
}
@override
Widget build(BuildContext context) {
return IconButton(
icon: const Icon(Icons.menu),
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
onPressed: openDrawer,
);
}
}

View File

@ -4,7 +4,7 @@ import 'package:solian/models/articles.dart';
import 'package:solian/models/feed.dart'; import 'package:solian/models/feed.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:solian/widgets/articles/article_list.dart'; import 'package:solian/widgets/articles/article_list.dart';
import 'package:solian/widgets/centered_container.dart'; import 'package:solian/widgets/sized_container.dart';
import 'package:solian/widgets/posts/post_list.dart'; import 'package:solian/widgets/posts/post_list.dart';
class FeedListWidget extends StatelessWidget { class FeedListWidget extends StatelessWidget {
@ -28,7 +28,7 @@ class FeedListWidget extends StatelessWidget {
pagingController: controller, pagingController: controller,
builderDelegate: PagedChildBuilderDelegate<FeedRecord>( builderDelegate: PagedChildBuilderDelegate<FeedRecord>(
itemBuilder: (context, item, index) { itemBuilder: (context, item, index) {
return CenteredContainer( return SizedContainer(
child: Builder( child: Builder(
builder: (context) { builder: (context) {
switch (item.type) { switch (item.type) {

View File

@ -4,9 +4,9 @@ import 'package:get/utils.dart';
abstract class AppNavigation { abstract class AppNavigation {
static List<AppNavigationDestination> destinations = [ static List<AppNavigationDestination> destinations = [
AppNavigationDestination( AppNavigationDestination(
icon: const Icon(Icons.feed), icon: const Icon(Icons.home),
label: 'feed'.tr, label: 'home'.tr,
page: 'feed', page: 'home',
), ),
AppNavigationDestination( AppNavigationDestination(
icon: const Icon(Icons.forum), icon: const Icon(Icons.forum),
@ -18,11 +18,6 @@ abstract class AppNavigation {
label: 'realms'.tr, label: 'realms'.tr,
page: 'realms', page: 'realms',
), ),
AppNavigationDestination(
icon: const Icon(Icons.account_circle),
label: 'account'.tr,
page: 'account',
),
]; ];
static List<String> get destinationPages => static List<String> get destinationPages =>

View File

@ -20,7 +20,7 @@ class AppNavigationDrawer extends StatefulWidget {
} }
class _AppNavigationDrawerState extends State<AppNavigationDrawer> { class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
int _selectedIndex = 0; int? _selectedIndex = 0;
AccountStatus? _accountStatus; AccountStatus? _accountStatus;
void getStatus() async { void getStatus() async {
@ -40,7 +40,11 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
final nameList = AppNavigation.destinations.map((x) => x.page).toList(); final nameList = AppNavigation.destinations.map((x) => x.page).toList();
final idx = nameList.indexOf(widget.routeName!); final idx = nameList.indexOf(widget.routeName!);
_selectedIndex = idx != -1 ? idx : 0; _selectedIndex = idx != -1 ? idx : null;
}
void closeDrawer() {
rootScaffoldKey.currentState!.closeDrawer();
} }
@override @override
@ -65,7 +69,7 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
onDestinationSelected: (idx) { onDestinationSelected: (idx) {
setState(() => _selectedIndex = idx); setState(() => _selectedIndex = idx);
AppRouter.instance.goNamed(AppNavigation.destinations[idx].page); AppRouter.instance.goNamed(AppNavigation.destinations[idx].page);
rootScaffoldKey.currentState!.closeDrawer(); closeDrawer();
}, },
children: [ children: [
FutureBuilder( FutureBuilder(
@ -75,67 +79,74 @@ class _AppNavigationDrawerState extends State<AppNavigationDrawer> {
return const SizedBox(); return const SizedBox();
} }
return Column( return ListTile(
children: [ contentPadding: const EdgeInsets.symmetric(horizontal: 24),
ListTile( title: Text(snapshot.data!.body['nick']),
contentPadding: const EdgeInsets.symmetric(horizontal: 24), subtitle: Builder(
title: Text(snapshot.data!.body['nick']), builder: (context) {
subtitle: Builder( if (_accountStatus == null) {
builder: (context) { return Text('loading'.tr);
if (_accountStatus == null) { }
return Text('loading'.tr); final info = StatusProvider.determineStatus(
} _accountStatus!,
final info = StatusProvider.determineStatus( );
return Text(info.$3);
},
),
leading: Builder(builder: (context) {
final badgeColor = _accountStatus != null
? StatusProvider.determineStatus(
_accountStatus!, _accountStatus!,
); ).$2
return Text(info.$3); : Colors.grey;
},
),
leading: Builder(builder: (context) {
final badgeColor = _accountStatus != null
? StatusProvider.determineStatus(
_accountStatus!,
).$2
: Colors.grey;
return badges.Badge( return badges.Badge(
showBadge: _accountStatus != null, showBadge: _accountStatus != null,
badgeStyle: badges.BadgeStyle(badgeColor: badgeColor), badgeStyle: badges.BadgeStyle(badgeColor: badgeColor),
position: badges.BadgePosition.bottomEnd( position: badges.BadgePosition.bottomEnd(
bottom: 0, bottom: 0,
end: -2, end: -2,
), ),
child: AccountAvatar( child: AccountAvatar(
content: snapshot.data!.body['avatar'], content: snapshot.data!.body['avatar'],
), ),
); );
}), }),
onTap: () { trailing: IconButton(
showModalBottomSheet( icon: const Icon(Icons.face_retouching_natural),
useRootNavigator: true, onPressed: () {
context: context, showModalBottomSheet(
builder: (context) => AccountStatusAction( useRootNavigator: true,
currentStatus: _accountStatus!.status, context: context,
), builder: (context) => AccountStatusAction(
).then((val) { currentStatus: _accountStatus!.status,
if (val == true) getStatus(); ),
}); ).then((val) {
}, if (val == true) getStatus();
), });
const Divider(thickness: 0.3, height: 1).paddingOnly( },
bottom: 16, ),
top: 8, onTap: () {
), AppRouter.instance.goNamed('account');
], closeDrawer();
); },
).paddingOnly(top: 8);
}, },
), ),
const Divider(thickness: 0.3, height: 1).paddingOnly(
bottom: 12,
top: 8,
),
...AppNavigation.destinations.map( ...AppNavigation.destinations.map(
(e) => NavigationDrawerDestination( (e) => NavigationDrawerDestination(
icon: e.icon, icon: e.icon,
label: Text(e.label), label: Text(e.label),
), ),
) ),
const Divider(thickness: 0.3, height: 1).paddingOnly(
top: 12,
bottom: 8,
),
], ],
); );
} }

View File

@ -1,36 +0,0 @@
import 'package:flutter/material.dart';
import 'package:solian/router.dart';
import 'package:solian/widgets/navigation/app_navigation.dart';
class AppNavigationRail extends StatefulWidget {
const AppNavigationRail({super.key});
@override
State<AppNavigationRail> createState() => _AppNavigationRailState();
}
class _AppNavigationRailState extends State<AppNavigationRail> {
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return NavigationRail(
destinations: AppNavigation.destinations
.map(
(e) => NavigationRailDestination(
icon: e.icon,
label: Text(e.label),
),
)
.toList(),
groupAlignment: 0,
labelType: NavigationRailLabelType.all,
selectedIndex: _selectedIndex,
onDestinationSelected: (idx) {
setState(() => _selectedIndex = idx);
AppRouter.instance
.pushReplacementNamed(AppNavigation.destinations[idx].page);
},
);
}
}

View File

@ -3,7 +3,7 @@ import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/widgets/centered_container.dart'; import 'package:solian/widgets/sized_container.dart';
import 'package:solian/widgets/posts/post_action.dart'; import 'package:solian/widgets/posts/post_action.dart';
import 'package:solian/widgets/posts/post_item.dart'; import 'package:solian/widgets/posts/post_item.dart';

View File

@ -1,19 +0,0 @@
import 'package:flutter/material.dart';
import 'package:solian/router.dart';
class PrevPageButton extends StatelessWidget {
const PrevPageButton({super.key});
@override
Widget build(BuildContext context) {
return IconButton(
icon: const Icon(Icons.arrow_back),
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
onPressed: () {
if (AppRouter.instance.canPop()) {
AppRouter.instance.pop();
}
},
);
}
}

View File

@ -1,5 +1,27 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class SizedContainer extends StatelessWidget {
final Widget child;
final double maxWidth;
const SizedContainer({
super.key,
required this.child,
this.maxWidth = 720,
});
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.centerLeft,
child: Container(
constraints: BoxConstraints(maxWidth: maxWidth),
child: child,
),
);
}
}
class CenteredContainer extends StatelessWidget { class CenteredContainer extends StatelessWidget {
final Widget child; final Widget child;
final double maxWidth; final double maxWidth;