From 5843d7c919e7a170781d952ecefd9d581c9a9e8e Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 1 Mar 2025 09:20:33 +0800 Subject: [PATCH] Fix sidebar. --- lib/components/side_bar.dart | 96 ++---------------------------------- 1 file changed, 3 insertions(+), 93 deletions(-) diff --git a/lib/components/side_bar.dart b/lib/components/side_bar.dart index 752cae4..a881500 100644 --- a/lib/components/side_bar.dart +++ b/lib/components/side_bar.dart @@ -1,15 +1,13 @@ part of 'components.dart'; class SideBarRoute extends PopupRoute { - SideBarRoute(this.title, this.widget, + SideBarRoute(this.widget, {this.showBarrier = true, this.useSurfaceTintColor = false, required this.width, this.addBottomPadding = true, this.addTopPadding = true}); - final String? title; - final Widget widget; final bool showBarrier; @@ -36,11 +34,7 @@ class SideBarRoute extends PopupRoute { Animation secondaryAnimation) { bool showSideBar = MediaQuery.of(context).size.width > width; - Widget body = SidebarBody( - title: title, - widget: widget, - autoChangeTitleBarColor: !useSurfaceTintColor, - ); + Widget body = widget; if (addTopPadding) { body = Padding( @@ -129,97 +123,13 @@ class SideBarRoute extends PopupRoute { } } -class SidebarBody extends StatefulWidget { - const SidebarBody( - {required this.title, - required this.widget, - required this.autoChangeTitleBarColor, - super.key}); - - final String? title; - final Widget widget; - final bool autoChangeTitleBarColor; - - @override - State createState() => _SidebarBodyState(); -} - -class _SidebarBodyState extends State { - bool top = true; - - @override - Widget build(BuildContext context) { - Widget body = Expanded(child: widget.widget); - - if (widget.autoChangeTitleBarColor) { - body = NotificationListener( - onNotification: (notifications) { - if (notifications.metrics.pixels == - notifications.metrics.minScrollExtent && - !top) { - setState(() { - top = true; - }); - } else if (notifications.metrics.pixels != - notifications.metrics.minScrollExtent && - top) { - setState(() { - top = false; - }); - } - return false; - }, - child: body, - ); - } - - return Column( - children: [ - if (widget.title != null) - Container( - height: 60 + MediaQuery.of(context).padding.top, - color: top - ? null - : Theme.of(context).colorScheme.surfaceTint.withAlpha(20), - padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top), - child: Row( - children: [ - const SizedBox( - width: 8, - ), - Tooltip( - message: "Back".tl, - child: IconButton( - iconSize: 25, - icon: const Icon(Icons.arrow_back), - onPressed: () => Navigator.of(context).pop(), - ), - ), - const SizedBox( - width: 10, - ), - Text( - widget.title!, - style: const TextStyle(fontSize: 22), - ) - ], - ), - ), - body - ], - ); - } -} - Future showSideBar(BuildContext context, Widget widget, - {String? title, - bool showBarrier = true, + {bool showBarrier = true, bool useSurfaceTintColor = false, double width = 500, bool addTopPadding = false}) { return Navigator.of(context).push( SideBarRoute( - title, widget, showBarrier: showBarrier, useSurfaceTintColor: useSurfaceTintColor,