diff --git a/CHANGELOG.md b/CHANGELOG.md index 75b601321..9fa627337 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Date format: DD/MM/YYYY +## [3.10.3] + +- Do not use duplicated `Scrollbar`s ([#279](https://github.com/bdlukaa/fluent_ui/pull/279/)) + ## [3.10.2] - [09/04/2022] - `NavigationView` without pane no longer throws error ([#276](https://github.com/bdlukaa/fluent_ui/issues/276)) diff --git a/lib/src/controls/navigation/navigation_view/pane.dart b/lib/src/controls/navigation/navigation_view/pane.dart index 5747b10b1..a6ffcb027 100644 --- a/lib/src/controls/navigation/navigation_view/pane.dart +++ b/lib/src/controls/navigation/navigation_view/pane.dart @@ -376,13 +376,11 @@ class _TopNavigationPane extends StatelessWidget { _TopNavigationPane({ required this.pane, this.listKey, - this.scrollbarKey, this.appBar, }) : super(key: pane.key); final NavigationPane pane; final GlobalKey? listKey; - final GlobalKey? scrollbarKey; final NavigationAppBar? appBar; Widget _buildItem(BuildContext context, NavigationPaneItem item) { @@ -465,14 +463,12 @@ class _CompactNavigationPane extends StatelessWidget { required this.pane, this.paneKey, this.listKey, - this.scrollbarKey, this.onToggle, }) : super(key: pane.key); final NavigationPane pane; final Key? paneKey; final GlobalKey? listKey; - final GlobalKey? scrollbarKey; final VoidCallback? onToggle; Widget _buildItem(BuildContext context, NavigationPaneItem item) { @@ -544,17 +540,12 @@ class _CompactNavigationPane extends StatelessWidget { ), ), Expanded( - child: Scrollbar( - key: scrollbarKey, - controller: pane.scrollController, - isAlwaysShown: false, - child: ListView( - key: listKey, - primary: true, - children: pane.items.map((item) { - return _buildItem(context, item); - }).toList(), - ), + child: ListView( + key: listKey, + primary: true, + children: pane.items.map((item) { + return _buildItem(context, item); + }).toList(), ), ), ListView( @@ -577,7 +568,6 @@ class _OpenNavigationPane extends StatefulWidget { required this.theme, this.paneKey, this.listKey, - this.scrollbarKey, this.onToggle, this.onItemSelected, }) : super(key: pane.key); @@ -585,7 +575,6 @@ class _OpenNavigationPane extends StatefulWidget { final NavigationPane pane; final Key? paneKey; final GlobalKey? listKey; - final GlobalKey? scrollbarKey; final VoidCallback? onToggle; final VoidCallback? onItemSelected; @@ -715,22 +704,17 @@ class _OpenNavigationPaneState extends State<_OpenNavigationPane> child: widget.pane.autoSuggestBox!, ), Expanded( - child: Scrollbar( - key: widget.scrollbarKey, - controller: widget.pane.scrollController, - isAlwaysShown: false, - child: ListView( - key: widget.listKey, - primary: true, - children: widget.pane.items.map((item) { - return _OpenNavigationPane.buildItem( - context, - widget.pane, - item, - widget.onItemSelected, - ); - }).toList(), - ), + child: ListView( + key: widget.listKey, + primary: true, + children: widget.pane.items.map((item) { + return _OpenNavigationPane.buildItem( + context, + widget.pane, + item, + widget.onItemSelected, + ); + }).toList(), ), ), ListView( diff --git a/lib/src/controls/navigation/navigation_view/view.dart b/lib/src/controls/navigation/navigation_view/view.dart index 82079d3ed..2261419ef 100644 --- a/lib/src/controls/navigation/navigation_view/view.dart +++ b/lib/src/controls/navigation/navigation_view/view.dart @@ -95,7 +95,6 @@ class NavigationViewState extends State { /// The key used to animate between open and compact display mode final _panelKey = GlobalKey(); final _listKey = GlobalKey(); - final _scrollbarKey = GlobalKey(); final _contentKey = GlobalKey(); final _overlayKey = GlobalKey(); @@ -298,12 +297,10 @@ class NavigationViewState extends State { case PaneDisplayMode.top: paneResult = Column(children: [ appBar, - PrimaryScrollController( - controller: scrollController, + PaneScrollConfiguration( child: _TopNavigationPane( pane: pane, listKey: _listKey, - scrollbarKey: _scrollbarKey, appBar: widget.appBar, ), ), @@ -348,8 +345,7 @@ class NavigationViewState extends State { ), ), ), - PrimaryScrollController( - controller: scrollController, + PaneScrollConfiguration( child: () { if (openedWithoutOverlay) { return Mica( @@ -363,7 +359,6 @@ class NavigationViewState extends State { pane: pane, paneKey: _panelKey, listKey: _listKey, - scrollbarKey: _scrollbarKey, onToggle: toggleCompactOpenMode, onItemSelected: toggleCompactOpenMode, ), @@ -389,7 +384,6 @@ class NavigationViewState extends State { pane: pane, paneKey: _panelKey, listKey: _listKey, - scrollbarKey: _scrollbarKey, onToggle: toggleCompactOpenMode, onItemSelected: toggleCompactOpenMode, ), @@ -405,7 +399,6 @@ class NavigationViewState extends State { pane: pane, paneKey: _panelKey, listKey: _listKey, - scrollbarKey: _scrollbarKey, onToggle: toggleCompactOpenMode, ), ), @@ -421,14 +414,12 @@ class NavigationViewState extends State { appBar, Expanded( child: Row(children: [ - PrimaryScrollController( - controller: scrollController, + PaneScrollConfiguration( child: _OpenNavigationPane( theme: theme, pane: pane, paneKey: _panelKey, listKey: _listKey, - scrollbarKey: _scrollbarKey, ), ), Expanded(child: content), @@ -466,8 +457,7 @@ class NavigationViewState extends State { start: _minimalPaneOpen ? 0.0 : -_kOpenNavigationPanelWidth, width: _kOpenNavigationPanelWidth, height: MediaQuery.of(context).size.height, - child: PrimaryScrollController( - controller: scrollController, + child: PaneScrollConfiguration( child: Mica( backgroundColor: _overlayBackgroundColor(), elevation: 10.0, @@ -486,7 +476,6 @@ class NavigationViewState extends State { pane: pane, paneKey: _panelKey, listKey: _listKey, - scrollbarKey: _scrollbarKey, onItemSelected: () { setState(() => _minimalPaneOpen = false); }, @@ -523,6 +512,17 @@ class NavigationViewState extends State { ); }); } + + // ignore: non_constant_identifier_names + Widget PaneScrollConfiguration({required Widget child}) { + return PrimaryScrollController( + controller: scrollController, + child: ScrollConfiguration( + behavior: const _NavigationViewScrollBehavior(), + child: child, + ), + ); + } } /// The bar displayed at the top of the app. It can adapt itself to @@ -745,3 +745,21 @@ class _NavigationAppBar extends StatelessWidget { ); } } + +class _NavigationViewScrollBehavior extends ScrollBehavior { + const _NavigationViewScrollBehavior({ + this.scrollbarKey, + }); + + final Key? scrollbarKey; + + @override + Widget buildScrollbar(context, child, details) { + return Scrollbar( + key: scrollbarKey, + controller: PrimaryScrollController.of(context), + isAlwaysShown: false, + child: child, + ); + } +} diff --git a/lib/src/controls/navigation/tab_view.dart b/lib/src/controls/navigation/tab_view.dart index 5e68cf9cd..64e17be1d 100644 --- a/lib/src/controls/navigation/tab_view.dart +++ b/lib/src/controls/navigation/tab_view.dart @@ -486,6 +486,10 @@ class _TabViewState extends State { if (widget.bodies.isNotEmpty) Expanded(child: widget.bodies[widget.currentIndex]), ]); + tabBar = ScrollConfiguration( + behavior: const _TabViewScrollBehavior(), + child: tabBar, + ); if (widget.shortcutsEnabled) { void _onClosePressed() { widget.tabs[widget.currentIndex].onClosed?.call(); @@ -793,3 +797,12 @@ class _TabPainter extends CustomPainter { @override bool shouldRebuildSemantics(_TabPainter oldDelegate) => false; } + +class _TabViewScrollBehavior extends ScrollBehavior { + const _TabViewScrollBehavior(); + + @override + Widget buildScrollbar(context, child, details) { + return child; + } +}