Add configurable scroll threshold (#910)

* Add configurable scroll threshold

* update

---------

Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
Tong xuewen
2025-07-29 23:02:05 +08:00
committed by GitHub
parent cf403aaf78
commit 3eb9c5b8ba
8 changed files with 191 additions and 103 deletions

View File

@@ -16,7 +16,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:stream_transform/stream_transform.dart';
class MainApp extends StatefulWidget {
const MainApp({super.key});
@@ -91,6 +90,52 @@ class _MainAppState extends State<MainApp>
Widget build(BuildContext context) {
final theme = Theme.of(context);
final bool isPortrait = context.orientation == Orientation.portrait;
final useBottomNav = isPortrait && !_mainController.useSideBar;
Widget? bottomNav = useBottomNav
? _mainController.navigationBars.length > 1
? _mainController.enableMYBar
? Obx(
() => NavigationBar(
onDestinationSelected: _mainController.setIndex,
selectedIndex: _mainController.selectedIndex.value,
destinations: _mainController.navigationBars
.map(
(e) => NavigationDestination(
label: e.label,
icon: _buildIcon(type: e),
selectedIcon: _buildIcon(
type: e,
selected: true,
),
),
)
.toList(),
),
)
: Obx(
() => BottomNavigationBar(
currentIndex: _mainController.selectedIndex.value,
onTap: _mainController.setIndex,
iconSize: 16,
selectedFontSize: 12,
unselectedFontSize: 12,
type: BottomNavigationBarType.fixed,
items: _mainController.navigationBars
.map(
(e) => BottomNavigationBarItem(
label: e.label,
icon: _buildIcon(type: e),
activeIcon: _buildIcon(
type: e,
selected: true,
),
),
)
.toList(),
),
)
: const SizedBox.shrink()
: null;
return PopScope(
canPop: false,
onPopInvokedWithResult: (bool didPop, Object? result) {
@@ -120,7 +165,7 @@ class _MainAppState extends State<MainApp>
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (_mainController.useSideBar || !isPortrait) ...[
if (!useBottomNav) ...[
_mainController.navigationBars.length > 1
? context.isTablet && _mainController.optTabletNav
? Column(
@@ -228,74 +273,23 @@ class _MainAppState extends State<MainApp>
],
),
),
bottomNavigationBar: _mainController.useSideBar || !isPortrait
? null
: StreamBuilder(
stream: _mainController.hideTabBar
? _mainController.navSearchStreamDebounce
? _mainController.bottomBarStream?.stream
.distinct()
.throttle(const Duration(milliseconds: 500))
: _mainController.bottomBarStream?.stream.distinct()
: null,
initialData: true,
builder: (context, AsyncSnapshot snapshot) {
return AnimatedSlide(
curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 500),
offset: Offset(0, snapshot.data ? 0 : 1),
child: _mainController.enableMYBar
? _mainController.navigationBars.length > 1
? Obx(
() => NavigationBar(
onDestinationSelected:
_mainController.setIndex,
selectedIndex:
_mainController.selectedIndex.value,
destinations: _mainController
.navigationBars
.map(
(e) => NavigationDestination(
label: e.label,
icon: _buildIcon(type: e),
selectedIcon: _buildIcon(
type: e,
selected: true,
),
),
)
.toList(),
),
)
: const SizedBox.shrink()
: _mainController.navigationBars.length > 1
? Obx(
() => BottomNavigationBar(
currentIndex:
_mainController.selectedIndex.value,
onTap: _mainController.setIndex,
iconSize: 16,
selectedFontSize: 12,
unselectedFontSize: 12,
type: BottomNavigationBarType.fixed,
items: _mainController.navigationBars
.map(
(e) => BottomNavigationBarItem(
label: e.label,
icon: _buildIcon(type: e),
activeIcon: _buildIcon(
type: e,
selected: true,
),
),
)
.toList(),
),
)
: const SizedBox.shrink(),
);
},
),
bottomNavigationBar: useBottomNav
? _mainController.hideTabBar
? StreamBuilder(
stream: _mainController.bottomBarStream?.stream
.distinct(),
initialData: true,
builder: (context, AsyncSnapshot snapshot) {
return AnimatedSlide(
curve: Curves.easeInOutCubicEmphasized,
duration: const Duration(milliseconds: 500),
offset: Offset(0, snapshot.data ? 0 : 1),
child: bottomNav,
);
},
)
: bottomNav
: null,
),
),
);