responsive_scaffold.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import 'package:flutter/material.dart';
  2. import '../../core/responsive.dart';
  3. class ResponsiveScaffold extends StatelessWidget {
  4. final String? title;
  5. final List<Widget>? actions;
  6. final Widget body;
  7. final Widget? drawer;
  8. final int? selectedIndex;
  9. final ValueChanged<int>? onNavigationChanged;
  10. final List<NavigationDestination>? navigationDestinations;
  11. const ResponsiveScaffold({
  12. super.key,
  13. this.title,
  14. this.actions,
  15. required this.body,
  16. this.drawer,
  17. this.selectedIndex,
  18. this.onNavigationChanged,
  19. this.navigationDestinations,
  20. });
  21. @override
  22. Widget build(BuildContext context) {
  23. if (ResponsiveBreakpoints.isDesktop(context)) {
  24. return Scaffold(
  25. appBar: AppBar(title: Text(title ?? ''), actions: actions),
  26. drawer: drawer is Drawer ? drawer as Drawer : null,
  27. body: Row(
  28. children: [
  29. if (navigationDestinations != null)
  30. NavigationRail(
  31. selectedIndex: selectedIndex ?? 0,
  32. onDestinationSelected: onNavigationChanged ?? (_) {},
  33. labelType: NavigationRailLabelType.all,
  34. destinations: navigationDestinations!.map((d) => NavigationRailDestination(
  35. icon: d.icon,
  36. selectedIcon: d.selectedIcon,
  37. label: Text(d.label ?? ''),
  38. )).toList(),
  39. ),
  40. Expanded(child: body),
  41. ],
  42. ),
  43. );
  44. }
  45. return Scaffold(
  46. appBar: AppBar(title: Text(title ?? ''), actions: actions),
  47. drawer: drawer,
  48. body: body,
  49. bottomNavigationBar: navigationDestinations != null && !ResponsiveBreakpoints.isDesktop(context)
  50. ? NavigationBar(
  51. selectedIndex: selectedIndex ?? 0,
  52. onDestinationSelected: onNavigationChanged ?? (_) {},
  53. destinations: navigationDestinations!,
  54. )
  55. : null,
  56. );
  57. }
  58. }