mod: nav bar

Closes #138

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-14 18:47:59 +08:00
parent 9ebf4b4533
commit e87a46706e
2 changed files with 60 additions and 104 deletions

View File

@@ -36,11 +36,14 @@ class _HomePageState extends State<HomePage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); super.build(context);
return Scaffold( return Scaffold(
appBar: AppBar(toolbarHeight: 0), appBar: AppBar(toolbarHeight: 0),
body: Column( body: Column(
children: [ children: [
if (!_homeController.useSideBar) customAppBar, if (!_homeController.useSideBar &&
context.orientation == Orientation.portrait)
customAppBar,
if (_homeController.tabs.length > 1) ...[ if (_homeController.tabs.length > 1) ...[
const SizedBox(height: 4), const SizedBox(height: 4),
Material( Material(

View File

@@ -165,105 +165,64 @@ class _MainAppState extends State<MainApp>
} }
} }
}, },
child: LayoutBuilder( child: Scaffold(
builder: (context, constriants) { resizeToAvoidBottomInset: false,
bool isPortait = constriants.maxHeight > constriants.maxWidth; extendBody: true,
body: Row(
return Scaffold( mainAxisAlignment: MainAxisAlignment.center,
resizeToAvoidBottomInset: false, children: [
extendBody: true, if (useSideBar || context.orientation == Orientation.landscape)
body: Row( Obx(
mainAxisAlignment: MainAxisAlignment.center, () => _mainController.navigationBars.length > 1
children: [ ? NavigationRail(
if (useSideBar) ...[ groupAlignment: 0.5,
SizedBox( selectedIndex: _mainController.selectedIndex.value,
width: context.width * 0.04 + onDestinationSelected: setIndex,
40 + labelType: NavigationRailLabelType.selected,
MediaQuery.of(context).padding.left, leading: userAndSearchVertical,
child: Obx( destinations: _mainController.navigationBars
() => _mainController.navigationBars.length > 1 .map(
? NavigationRail( (e) => NavigationRailDestination(
groupAlignment: 1, icon: _buildIcon(
minWidth: context.width * 0.0286 + 28.56, id: e['id'],
backgroundColor: Colors.transparent, count: e['count'],
selectedIndex: icon: e['icon'],
_mainController.selectedIndex.value, ),
onDestinationSelected: setIndex, selectedIcon: _buildIcon(
labelType: NavigationRailLabelType.none, id: e['id'],
leading: userAndSearchVertical, count: e['count'],
destinations: _mainController.navigationBars icon: e['selectIcon'],
.map((e) => NavigationRailDestination( ),
icon: _buildIcon( label: Text(e['label']),
id: e['id'],
count: e['count'],
icon: e['icon'],
),
selectedIcon: _buildIcon(
id: e['id'],
count: e['count'],
icon: e['selectIcon'],
),
label: Text(e['label']),
padding: EdgeInsets.symmetric(
vertical: 0.01 * context.height),
))
.toList(),
trailing: SizedBox(height: 0.1 * context.height),
)
: Container(
padding: EdgeInsets.only(
top: MediaQuery.paddingOf(context).top + 10),
constraints: BoxConstraints(
minWidth: context.width * 0.0286 + 28.56,
), ),
child: userAndSearchVertical, )
), .toList(),
), )
), : Container(
] else if (!isPortait) padding: EdgeInsets.only(
Obx( top: MediaQuery.paddingOf(context).top + 10,
() => _mainController.navigationBars.length > 1 ),
? NavigationRail( width: 56,
onDestinationSelected: setIndex, child: userAndSearchVertical,
selectedIndex: _mainController.selectedIndex.value, ),
destinations: _mainController.navigationBars ),
.map( VerticalDivider(
(e) => NavigationRailDestination( width: 1,
icon: _buildIcon( indent: MediaQuery.of(context).padding.top,
id: e['id'], endIndent: MediaQuery.of(context).padding.bottom,
count: e['count'], color: Theme.of(context).colorScheme.outline.withOpacity(0.06),
icon: e['icon'],
),
selectedIcon: _buildIcon(
id: e['id'],
count: e['count'],
icon: e['selectIcon'],
),
label: Text(e['label']),
),
)
.toList(),
)
: const SizedBox.shrink(),
),
VerticalDivider(
width: 1,
indent: MediaQuery.of(context).padding.top,
endIndent: MediaQuery.of(context).padding.bottom,
color:
Theme.of(context).colorScheme.outline.withOpacity(0.06),
),
Expanded(
child: PageView(
physics: const NeverScrollableScrollPhysics(),
controller: _mainController.pageController,
children: _mainController.pages,
),
),
if (useSideBar) SizedBox(width: context.width * 0.004),
],
), ),
bottomNavigationBar: useSideBar || !isPortait Expanded(
child: PageView(
physics: const NeverScrollableScrollPhysics(),
controller: _mainController.pageController,
children: _mainController.pages,
),
),
],
),
bottomNavigationBar:
useSideBar || context.orientation == Orientation.landscape
? null ? null
: StreamBuilder( : StreamBuilder(
stream: _mainController.hideTabBar stream: _mainController.hideTabBar
@@ -313,10 +272,6 @@ class _MainAppState extends State<MainApp>
selectedFontSize: 12, selectedFontSize: 12,
unselectedFontSize: 12, unselectedFontSize: 12,
type: BottomNavigationBarType.fixed, type: BottomNavigationBarType.fixed,
// selectedItemColor:
// Theme.of(context).colorScheme.primary, // 选中项的颜色
// unselectedItemColor:
// Theme.of(context).colorScheme.onSurface,
items: _mainController.navigationBars items: _mainController.navigationBars
.map( .map(
(e) => BottomNavigationBarItem( (e) => BottomNavigationBarItem(
@@ -340,8 +295,6 @@ class _MainAppState extends State<MainApp>
); );
}, },
), ),
);
},
), ),
); );
} }