opt: use NavigationRail on landscape page

This commit is contained in:
bggRGjQaUbCoE
2024-09-25 18:36:40 +08:00
parent e7af9b0ab3
commit 6138dfa51f

View File

@@ -111,157 +111,199 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
_homeController.flag = true; _homeController.flag = true;
} }
}, },
child: Scaffold( child: LayoutBuilder(
extendBody: true, builder: (_, constriants) {
body: Row( bool isPortait = constriants.maxHeight > constriants.maxWidth;
mainAxisAlignment: MainAxisAlignment.center,
children: [ return Scaffold(
if (useSideBar) ...[ extendBody: true,
SizedBox( body: Row(
width: context.width * 0.0387 + mainAxisAlignment: MainAxisAlignment.center,
36.801 + children: [
MediaQuery.of(context).padding.left, if (useSideBar) ...[
child: NavigationRail( SizedBox(
groupAlignment: 1, width: context.width * 0.0387 +
minWidth: context.width * 0.0286 + 28.56, 36.801 +
backgroundColor: Colors.transparent, MediaQuery.of(context).padding.left,
selectedIndex: _mainController.selectedIndex, child: NavigationRail(
groupAlignment: 1,
minWidth: context.width * 0.0286 + 28.56,
backgroundColor: Colors.transparent,
selectedIndex: _mainController.selectedIndex,
onDestinationSelected: (value) => setIndex(value),
labelType: NavigationRailLabelType.none,
leading: UserAndSearchVertical(ctr: _homeController),
destinations: _mainController.navigationBars
.map((e) => NavigationRailDestination(
icon: Badge(
label: _mainController.dynamicBadgeType ==
DynamicBadgeMode.number
? Text(e['count'].toString())
: null,
padding:
const EdgeInsets.symmetric(horizontal: 4),
isLabelVisible:
_mainController.dynamicBadgeType !=
DynamicBadgeMode.hidden &&
e['count'] > 0,
child: e['icon'],
backgroundColor:
Theme.of(context).colorScheme.primary,
textColor: Theme.of(context)
.colorScheme
.onInverseSurface,
),
selectedIcon: e['selectIcon'],
label: Text(e['label']),
padding: EdgeInsets.symmetric(
vertical: 0.01 * context.height),
))
.toList(),
trailing: SizedBox(height: 0.1 * context.height),
),
),
] else if (!isPortait)
NavigationRail(
onDestinationSelected: (value) => setIndex(value), onDestinationSelected: (value) => setIndex(value),
labelType: NavigationRailLabelType.none, selectedIndex: _mainController.selectedIndex,
leading: UserAndSearchVertical(ctr: _homeController),
destinations: _mainController.navigationBars destinations: _mainController.navigationBars
.map((e) => NavigationRailDestination( .map(
icon: Badge( (e) => NavigationRailDestination(
label: _mainController.dynamicBadgeType == icon: Badge(
DynamicBadgeMode.number label: _mainController.dynamicBadgeType ==
? Text(e['count'].toString()) DynamicBadgeMode.number
: null, ? Text(e['count'].toString())
padding: : null,
const EdgeInsets.symmetric(horizontal: 4), padding: const EdgeInsets.fromLTRB(6, 0, 6, 0),
isLabelVisible: isLabelVisible:
_mainController.dynamicBadgeType != _mainController.dynamicBadgeType !=
DynamicBadgeMode.hidden && DynamicBadgeMode.hidden &&
e['count'] > 0, e['count'] > 0,
child: e['icon'], child: e['icon'],
backgroundColor: backgroundColor:
Theme.of(context).colorScheme.primary, Theme.of(context).colorScheme.primary,
textColor: Theme.of(context) textColor: Theme.of(context)
.colorScheme .colorScheme
.onInverseSurface, .onInverseSurface,
), ),
selectedIcon: e['selectIcon'], selectedIcon: e['selectIcon'],
label: Text(e['label']), label: Text(e['label']),
padding: EdgeInsets.symmetric(
vertical: 0.01 * context.height),
))
.toList(),
trailing: SizedBox(height: 0.1 * context.height),
)),
],
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,
onPageChanged: (index) {
_mainController.selectedIndex = index;
setState(() {});
},
children: _mainController.pages,
),
),
if (useSideBar) SizedBox(width: context.width * 0.004),
],
),
bottomNavigationBar: useSideBar
? null
: StreamBuilder(
stream: _mainController.hideTabBar
? _mainController.bottomBarStream.stream
: StreamController<bool>.broadcast().stream,
initialData: true,
builder: (context, AsyncSnapshot snapshot) {
return AnimatedSlide(
curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 500),
offset: Offset(0, snapshot.data ? 0 : 1),
child: enableMYBar
? NavigationBar(
onDestinationSelected: (value) => setIndex(value),
selectedIndex: _mainController.selectedIndex,
destinations: <Widget>[
..._mainController.navigationBars.map((e) {
return NavigationDestination(
icon: Badge(
label: _mainController.dynamicBadgeType ==
DynamicBadgeMode.number
? Text(e['count'].toString())
: null,
padding:
const EdgeInsets.fromLTRB(6, 0, 6, 0),
isLabelVisible:
_mainController.dynamicBadgeType !=
DynamicBadgeMode.hidden &&
e['count'] > 0,
child: e['icon'],
backgroundColor:
Theme.of(context).colorScheme.primary,
textColor: Theme.of(context)
.colorScheme
.onInverseSurface,
),
selectedIcon: e['selectIcon'],
label: e['label'],
);
}).toList(),
],
)
: BottomNavigationBar(
currentIndex: _mainController.selectedIndex,
onTap: (value) => setIndex(value),
iconSize: 16,
selectedFontSize: 12,
unselectedFontSize: 12,
type: BottomNavigationBarType.fixed,
// selectedItemColor:
// Theme.of(context).colorScheme.primary, // 选中项的颜色
// unselectedItemColor:
// Theme.of(context).colorScheme.onSurface,
items: [
..._mainController.navigationBars.map((e) {
return BottomNavigationBarItem(
icon: Badge(
label: _mainController.dynamicBadgeType ==
DynamicBadgeMode.number
? Text(e['count'].toString())
: null,
padding:
const EdgeInsets.fromLTRB(6, 0, 6, 0),
isLabelVisible:
_mainController.dynamicBadgeType !=
DynamicBadgeMode.hidden &&
e['count'] > 0,
child: e['icon'],
backgroundColor:
Theme.of(context).colorScheme.primary,
textColor: Theme.of(context)
.colorScheme
.onInverseSurface,
),
activeIcon: e['selectIcon'],
label: e['label'],
);
}).toList(),
],
), ),
); )
}, .toList(),
), ),
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,
onPageChanged: (index) {
_mainController.selectedIndex = index;
setState(() {});
},
children: _mainController.pages,
),
),
if (useSideBar) SizedBox(width: context.width * 0.004),
],
),
bottomNavigationBar: useSideBar || !isPortait
? null
: StreamBuilder(
stream: _mainController.hideTabBar
? _mainController.bottomBarStream.stream
: StreamController<bool>.broadcast().stream,
initialData: true,
builder: (context, AsyncSnapshot snapshot) {
return AnimatedSlide(
curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 500),
offset: Offset(0, snapshot.data ? 0 : 1),
child: enableMYBar
? NavigationBar(
onDestinationSelected: (value) =>
setIndex(value),
selectedIndex: _mainController.selectedIndex,
destinations: _mainController.navigationBars
.map(
(e) => NavigationDestination(
icon: Badge(
label: _mainController
.dynamicBadgeType ==
DynamicBadgeMode.number
? Text(e['count'].toString())
: null,
padding: const EdgeInsets.fromLTRB(
6, 0, 6, 0),
isLabelVisible: _mainController
.dynamicBadgeType !=
DynamicBadgeMode.hidden &&
e['count'] > 0,
child: e['icon'],
backgroundColor: Theme.of(context)
.colorScheme
.primary,
textColor: Theme.of(context)
.colorScheme
.onInverseSurface,
),
selectedIcon: e['selectIcon'],
label: e['label'],
),
)
.toList(),
)
: BottomNavigationBar(
currentIndex: _mainController.selectedIndex,
onTap: (value) => setIndex(value),
iconSize: 16,
selectedFontSize: 12,
unselectedFontSize: 12,
type: BottomNavigationBarType.fixed,
// selectedItemColor:
// Theme.of(context).colorScheme.primary, // 选中项的颜色
// unselectedItemColor:
// Theme.of(context).colorScheme.onSurface,
items: _mainController.navigationBars
.map(
(e) => BottomNavigationBarItem(
icon: Badge(
label: _mainController
.dynamicBadgeType ==
DynamicBadgeMode.number
? Text(e['count'].toString())
: null,
padding: const EdgeInsets.fromLTRB(
6, 0, 6, 0),
isLabelVisible: _mainController
.dynamicBadgeType !=
DynamicBadgeMode.hidden &&
e['count'] > 0,
child: e['icon'],
backgroundColor: Theme.of(context)
.colorScheme
.primary,
textColor: Theme.of(context)
.colorScheme
.onInverseSurface,
),
activeIcon: e['selectIcon'],
label: e['label'],
),
)
.toList(),
),
);
},
),
);
},
), ),
); );
} }