refactor: sidebar trailing widget in the end and use NavigationBar instead of BottomNavigationBar

This commit is contained in:
Kingkor Roy Tirtho 2023-03-10 13:00:07 +06:00
parent a4927c7013
commit f8a2b9afd8
3 changed files with 105 additions and 78 deletions

View File

@ -90,15 +90,40 @@ class Sidebar extends HookConsumerWidget {
); );
}, },
).toList(), ).toList(),
extended: true, extended: breakpoints > Breakpoints.md,
leading: Padding( leading: const SidebarHeader(),
trailing: const Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: SidebarFooter(),
),
),
),
Expanded(child: child)
],
);
}
}
class SidebarHeader extends HookWidget {
const SidebarHeader({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final breakpoint = useBreakpoints();
if (breakpoint <= Breakpoints.md) {
return Sidebar.brandLogo();
}
return Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Column( child: Column(
children: [ children: [
if (kIsMacOS) macSpacer, if (kIsMacOS) const SizedBox(height: 25),
Row( Row(
children: [ children: [
brandLogo(), Sidebar.brandLogo(),
const SizedBox(width: 10), const SizedBox(width: 10),
Text( Text(
"Spotube", "Spotube",
@ -108,11 +133,6 @@ class Sidebar extends HookConsumerWidget {
), ),
], ],
), ),
),
trailing: const SidebarFooter(),
),
Expanded(child: child)
],
); );
} }
} }
@ -124,10 +144,7 @@ class SidebarFooter extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, ref) { Widget build(BuildContext context, ref) {
return SizedBox( final breakpoint = useBreakpoints();
width: 256,
child: HookBuilder(
builder: (context) {
final me = useQueries.user.me(ref); final me = useQueries.user.me(ref);
final data = me.data; final data = me.data;
@ -139,32 +156,35 @@ class SidebarFooter extends HookConsumerWidget {
final auth = ref.watch(AuthenticationNotifier.provider); final auth = ref.watch(AuthenticationNotifier.provider);
return Padding( if (breakpoint <= Breakpoints.md) {
padding: const EdgeInsets.all(16).copyWith(left: 0), return IconButton(
icon: const Icon(SpotubeIcons.settings),
onPressed: () => Sidebar.goToSettings(context),
);
}
return Container(
padding: const EdgeInsets.only(left: 12),
width: 250,
child: Row( child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
if (auth != null && data == null) if (auth != null && data == null)
const Center( const CircularProgressIndicator()
child: CircularProgressIndicator(),
)
else if (data != null) else if (data != null)
Flexible( Flexible(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
CircleAvatar( CircleAvatar(
backgroundImage: backgroundImage: UniversalImage.imageProvider(avatarImg),
UniversalImage.imageProvider(avatarImg),
onBackgroundImageError: (exception, stackTrace) => onBackgroundImageError: (exception, stackTrace) =>
Assets.userPlaceholder.image( Assets.userPlaceholder.image(
height: 16, height: 16,
width: 16, width: 16,
), ),
), ),
const SizedBox( const SizedBox(width: 10),
width: 10,
),
Flexible( Flexible(
child: Text( child: Text(
data.displayName ?? "Guest", data.displayName ?? "Guest",
@ -182,10 +202,9 @@ class SidebarFooter extends HookConsumerWidget {
), ),
IconButton( IconButton(
icon: const Icon(SpotubeIcons.settings), icon: const Icon(SpotubeIcons.settings),
onPressed: () => Sidebar.goToSettings(context)), onPressed: () => Sidebar.goToSettings(context),
),
], ],
));
},
), ),
); );
} }

View File

@ -37,11 +37,11 @@ class SpotubeNavigationBar extends HookConsumerWidget {
if (layoutMode == LayoutMode.extended || if (layoutMode == LayoutMode.extended ||
(breakpoint.isMoreThan(Breakpoints.sm) && (breakpoint.isMoreThan(Breakpoints.sm) &&
layoutMode == LayoutMode.adaptive)) return const SizedBox(); layoutMode == LayoutMode.adaptive)) return const SizedBox();
return BottomNavigationBar( return NavigationBar(
items: [ destinations: [
...navbarTileList.map( ...navbarTileList.map(
(e) { (e) {
return BottomNavigationBarItem( return NavigationDestination(
icon: Badge( icon: Badge(
backgroundColor: Theme.of(context).primaryColor, backgroundColor: Theme.of(context).primaryColor,
isLabelVisible: e.title == "Library" && downloadCount > 0, isLabelVisible: e.title == "Library" && downloadCount > 0,
@ -59,8 +59,8 @@ class SpotubeNavigationBar extends HookConsumerWidget {
}, },
), ),
], ],
currentIndex: insideSelectedIndex.value, selectedIndex: insideSelectedIndex.value,
onTap: (i) { onDestinationSelected: (i) {
insideSelectedIndex.value = i; insideSelectedIndex.value = i;
if (navbarTileList[i].title == "Settings") { if (navbarTileList[i].title == "Settings") {
Sidebar.goToSettings(context); Sidebar.goToSettings(context);

View File

@ -551,6 +551,14 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_adaptive_scaffold:
dependency: "direct main"
description:
name: flutter_adaptive_scaffold
sha256: d5842a235ec810320c7e6dac282876d93bccf231201be6e684b016cd717c0576
url: "https://pub.dev"
source: hosted
version: "0.1.0"
flutter_app_builder: flutter_app_builder:
dependency: transitive dependency: transitive
description: description: