diff --git a/lib/src/routing/presentation/widgets/responsive_scaffold.dart b/lib/src/routing/presentation/widgets/responsive_scaffold.dart index e5a1ed31..5141c745 100644 --- a/lib/src/routing/presentation/widgets/responsive_scaffold.dart +++ b/lib/src/routing/presentation/widgets/responsive_scaffold.dart @@ -47,7 +47,7 @@ class ResponsiveScaffold extends StatefulHookWidget { this.buildBottomNavigationBar = _defaultBottomNavigationBarBuilder, this.buildDrawer, this.buildSidebar, - this.buildDismissableSliverAppBar, + this.buildAppBar, this.buildSidebarAppBar, this.buildTopBar, }); @@ -165,13 +165,13 @@ class ResponsiveScaffold extends StatefulHookWidget { /// Custom [SliverAppBar] builder for [NavigationType.drawer] and [NavigationType.bottom] /// /// A sliver must be returned from this builder. - final Widget Function( + final PreferredSizeWidget Function( BuildContext context, RouteName? topRoute, NavigationType navigationType, Widget? trailing, String? title, - )? buildDismissableSliverAppBar; + )? buildAppBar; final PreferredSizeWidget Function( BuildContext context, @@ -266,8 +266,7 @@ class _ResponsiveScaffoldState extends State navigationType, ); - final buildSliverAppBar = widget.buildDismissableSliverAppBar ?? - _defaultBuildDismissableSliverAppBar; + final buildAppBar = widget.buildAppBar ?? _defaultBuildAppBar; final buildSidebarAppBar = widget.buildSidebarAppBar ?? _defaultBuildSidebarAppBar; @@ -281,85 +280,77 @@ class _ResponsiveScaffoldState extends State ], ); - return Scaffold( - key: _key, - appBar: switch (navigationType) { - NavigationType.top => buildTopBar( - context, - topRouteName, - navigationType, - tabBar, - widget.title, - ), - NavigationType.sidebar => buildSidebarAppBar( - context, - topRouteName, - navigationType, - widget.title, + return SwapExpandedWidgetBuilder( + collapsed: widget.buildActionButton + ?.call(context, topRouteName, widget.currentIndex, false), + expanded: widget.buildActionButton + ?.call(context, topRouteName, widget.currentIndex, true), + minExpandedWidth: widget.minActionExpandedWidth, + builder: (context, action) { + return Scaffold( + key: _key, + appBar: switch (navigationType) { + NavigationType.top => buildTopBar( + context, + topRouteName, + navigationType, + tabBar, + widget.title, + ), + NavigationType.sidebar => buildSidebarAppBar( + context, + topRouteName, + navigationType, + widget.title, + ), + NavigationType.bottom => buildAppBar( + context, + topRouteName, + navigationType, + action, + widget.title, + ), + NavigationType.drawer => buildAppBar( + context, + topRouteName, + navigationType, + action, + widget.title, + ), + }, + body: Row( + children: [ + AnimatedSwitcher( + duration: widget.transitionDuration, + reverseDuration: widget.transitionReverseDuration, + child: + navigationType == NavigationType.sidebar ? sidebar : null, + ), + widget.divider, + Expanded(child: widget.child), + ], ), - _ => null, + drawer: hasDrawer ? drawer : null, + bottomNavigationBar: + hasBottomNavigationBar ? bottomNavigationBar : null, + endDrawer: widget.scaffoldConfig.endDrawer, + bottomSheet: widget.scaffoldConfig.bottomSheet, + backgroundColor: widget.scaffoldConfig.backgroundColor, + resizeToAvoidBottomInset: + widget.scaffoldConfig.resizeToAvoidBottomInset, + primary: widget.scaffoldConfig.primary, + drawerDragStartBehavior: + widget.scaffoldConfig.drawerDragStartBehavior, + extendBody: widget.scaffoldConfig.extendBody, + extendBodyBehindAppBar: widget.scaffoldConfig.extendBodyBehindAppBar, + drawerScrimColor: widget.scaffoldConfig.drawerScrimColor, + drawerEdgeDragWidth: widget.scaffoldConfig.drawerEdgeDragWidth, + drawerEnableOpenDragGesture: + widget.scaffoldConfig.drawerEnableOpenDragGesture, + endDrawerEnableOpenDragGesture: + widget.scaffoldConfig.endDrawerEnableOpenDragGesture, + ); }, - body: SwapExpandedWidgetBuilder( - collapsed: widget.buildActionButton - ?.call(context, topRouteName, widget.currentIndex, false), - expanded: widget.buildActionButton - ?.call(context, topRouteName, widget.currentIndex, true), - minExpandedWidth: widget.minActionExpandedWidth, - builder: (context, action) { - return NestedScrollView( - headerSliverBuilder: - (BuildContext context, bool innerBoxIsScrolled) { - return [ - switch (navigationType) { - NavigationType.bottom => buildSliverAppBar( - context, - topRouteName, - navigationType, - action, - widget.title, - ), - NavigationType.drawer => buildSliverAppBar( - context, - topRouteName, - navigationType, - action, - widget.title, - ), - _ => const SliverToBoxAdapter(child: SizedBox.shrink()), - }, - ]; - }, - body: Row( - children: [ - AnimatedSwitcher( - duration: widget.transitionDuration, - reverseDuration: widget.transitionReverseDuration, - child: - navigationType == NavigationType.sidebar ? sidebar : null, - ), - widget.divider, - Expanded(child: widget.child), - ], - ), - ); - }, - ), - drawer: hasDrawer ? drawer : null, - bottomNavigationBar: hasBottomNavigationBar ? bottomNavigationBar : null, - endDrawer: widget.scaffoldConfig.endDrawer, - bottomSheet: widget.scaffoldConfig.bottomSheet, - backgroundColor: widget.scaffoldConfig.backgroundColor, - resizeToAvoidBottomInset: widget.scaffoldConfig.resizeToAvoidBottomInset, - primary: widget.scaffoldConfig.primary, - drawerDragStartBehavior: widget.scaffoldConfig.drawerDragStartBehavior, - extendBody: widget.scaffoldConfig.extendBody, - extendBodyBehindAppBar: widget.scaffoldConfig.extendBodyBehindAppBar, - drawerScrimColor: widget.scaffoldConfig.drawerScrimColor, - drawerEdgeDragWidth: widget.scaffoldConfig.drawerEdgeDragWidth, - drawerEnableOpenDragGesture: - widget.scaffoldConfig.drawerEnableOpenDragGesture, - endDrawerEnableOpenDragGesture: - widget.scaffoldConfig.endDrawerEnableOpenDragGesture, ); } @@ -470,7 +461,14 @@ class _ResponsiveScaffoldState extends State reverseDuration: widget.transitionReverseDuration, child: isRootRoute - ? tabBar + ? ConstrainedBox( + constraints: BoxConstraints( + minHeight: theme.appBarTheme + .toolbarHeight ?? + kToolbarHeight, + ), + child: tabBar, + ) : Text( title, style: theme.textTheme.titleMedium, @@ -549,14 +547,14 @@ class _ResponsiveScaffoldState extends State ); } - Widget _defaultBuildDismissableSliverAppBar( + PreferredSizeWidget _defaultBuildAppBar( BuildContext context, RouteName? topRoute, NavigationType navigationType, Widget? trailing, String? title, ) { - return SliverAppBar( + return AppBar( centerTitle: true, leading: Builder( builder: (context) { @@ -592,9 +590,6 @@ class _ResponsiveScaffoldState extends State child: title == null ? null : Text(title), ), automaticallyImplyLeading: false, - expandedHeight: 50, - floating: true, - snap: true, actions: trailing == null ? null : [trailing], ); } diff --git a/packages/pub/sidebarx/lib/src/sidebarx_base.dart b/packages/pub/sidebarx/lib/src/sidebarx_base.dart index 4a88ee46..1b403b96 100644 --- a/packages/pub/sidebarx/lib/src/sidebarx_base.dart +++ b/packages/pub/sidebarx/lib/src/sidebarx_base.dart @@ -4,7 +4,7 @@ import 'package:sidebarx/src/widgets/widgets.dart'; class SidebarX extends StatefulWidget { const SidebarX({ - Key? key, + super.key, required this.controller, this.items = const [], this.footerItems = const [], @@ -20,7 +20,7 @@ class SidebarX extends StatefulWidget { this.animationDuration = const Duration(milliseconds: 300), this.collapseIcon = Icons.arrow_back_ios_new, this.extendIcon = Icons.arrow_forward_ios, - }) : super(key: key); + }); /// Default theme of Sidebar final SidebarXTheme theme; @@ -100,86 +100,104 @@ class _SidebarXState extends State @override Widget build(BuildContext context) { - return AnimatedBuilder( - animation: widget.controller, - builder: (context, child) { - final extendedT = widget.extendedTheme?.mergeWith(widget.theme); - final selectedTheme = widget.controller.extended - ? extendedT ?? widget.theme - : widget.theme; + final orientation = MediaQuery.orientationOf(context); + final textDirection = Directionality.of(context); + final padding = switch ((orientation, textDirection)) { + (Orientation.portrait, _) => 0.0, + (Orientation.landscape, TextDirection.ltr) => + MediaQuery.viewPaddingOf(context).left, + (Orientation.landscape, TextDirection.rtl) => + MediaQuery.viewPaddingOf(context).right, + }; + return Padding( + padding: EdgeInsetsDirectional.only( + start: padding, + ), + child: AnimatedBuilder( + animation: widget.controller, + builder: (context, child) { + final extendedT = widget.extendedTheme?.mergeWith(widget.theme); + final selectedTheme = widget.controller.extended + ? extendedT ?? widget.theme + : widget.theme; - final t = selectedTheme.mergeFlutterTheme(context); + final t = selectedTheme.mergeFlutterTheme(context); - return AnimatedContainer( - duration: widget.animationDuration, - width: t.width, - height: t.height, - padding: t.padding, - margin: t.margin, - decoration: t.decoration, - child: Column( - children: [ - widget.headerBuilder?.call(context, widget.controller.extended) ?? - const SizedBox(), - widget.headerDivider ?? const SizedBox(), - Expanded( - child: ListView.separated( - itemCount: widget.items.length, - separatorBuilder: widget.separatorBuilder ?? - (_, __) => const SizedBox(height: 8), - itemBuilder: (context, index) { - final item = widget.items[index]; - return SidebarXCell( - item: item, - theme: t, - animationController: _animationController!, - extended: widget.controller.extended, - selected: widget.controller.selectedIndex == index, - onTap: () => _onItemSelected(item, index), - onLongPress: () => _onItemLongPressSelected(item, index), - onSecondaryTap: () => - _onItemSecondaryTapSelected(item, index), - ); - }, - ), - ), - widget.footerDivider ?? const SizedBox(), - widget.footerBuilder?.call(context, widget.controller.extended) ?? - const SizedBox(), - if (widget.footerItems.isNotEmpty) + return AnimatedContainer( + duration: widget.animationDuration, + width: t.width, + height: t.height, + padding: t.padding, + margin: t.margin, + decoration: t.decoration, + child: Column( + children: [ + widget.headerBuilder + ?.call(context, widget.controller.extended) ?? + const SizedBox(), + widget.headerDivider ?? const SizedBox(), Expanded( child: ListView.separated( - reverse: true, - itemCount: widget.footerItems.length, + itemCount: widget.items.length, separatorBuilder: widget.separatorBuilder ?? (_, __) => const SizedBox(height: 8), itemBuilder: (context, index) { - final item = widget.footerItems.reversed.toList()[index]; + final item = widget.items[index]; return SidebarXCell( item: item, theme: t, animationController: _animationController!, extended: widget.controller.extended, - selected: widget.controller.selectedIndex == - widget.items.length + - widget.footerItems.length - - index - - 1, - onTap: () => _onFooterItemSelected(item, index), + selected: widget.controller.selectedIndex == index, + onTap: () => _onItemSelected(item, index), onLongPress: () => - _onFooterItemLongPressSelected(item, index), + _onItemLongPressSelected(item, index), onSecondaryTap: () => - _onFooterItemSecondaryTapSelected(item, index), + _onItemSecondaryTapSelected(item, index), ); }, ), ), - if (widget.showToggleButton) - _buildToggleButton(t, widget.collapseIcon, widget.extendIcon), - ], - ), - ); - }, + widget.footerDivider ?? const SizedBox(), + widget.footerBuilder + ?.call(context, widget.controller.extended) ?? + const SizedBox(), + if (widget.footerItems.isNotEmpty) + Expanded( + child: ListView.separated( + reverse: true, + itemCount: widget.footerItems.length, + separatorBuilder: widget.separatorBuilder ?? + (_, __) => const SizedBox(height: 8), + itemBuilder: (context, index) { + final item = + widget.footerItems.reversed.toList()[index]; + return SidebarXCell( + item: item, + theme: t, + animationController: _animationController!, + extended: widget.controller.extended, + selected: widget.controller.selectedIndex == + widget.items.length + + widget.footerItems.length - + index - + 1, + onTap: () => _onFooterItemSelected(item, index), + onLongPress: () => + _onFooterItemLongPressSelected(item, index), + onSecondaryTap: () => + _onFooterItemSecondaryTapSelected(item, index), + ); + }, + ), + ), + if (widget.showToggleButton) + _buildToggleButton(t, widget.collapseIcon, widget.extendIcon), + ], + ), + ); + }, + ), ); } diff --git a/packages/pub/sidebarx/pubspec.yaml b/packages/pub/sidebarx/pubspec.yaml index 917a05df..cfb0c9be 100644 --- a/packages/pub/sidebarx/pubspec.yaml +++ b/packages/pub/sidebarx/pubspec.yaml @@ -12,8 +12,8 @@ topics: - sidebar environment: - sdk: ">=2.15.0 <4.0.0" - flutter: ">=1.17.0" + sdk: ">=3.3.0 <4.0.0" + flutter: ">=3.19.0" dependencies: flutter: diff --git a/pubspec.yaml b/pubspec.yaml index 5ab9ec16..2b802ed5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: An opinionated template for a Flutter project. publish_to: none -version: 0.7.3 +version: 0.7.4 environment: sdk: ">=3.1.0 <4.0.0"