mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
92 lines
2.5 KiB
Dart
92 lines
2.5 KiB
Dart
import 'package:auto_route/auto_route.dart';
|
|
import 'package:fladder/widgets/navigation_scaffold/components/adaptive_fab.dart';
|
|
import 'package:fladder/widgets/navigation_scaffold/components/navigation_button.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DestinationModel {
|
|
final String label;
|
|
final Widget? icon;
|
|
final Widget? selectedIcon;
|
|
final PageRouteInfo? route;
|
|
final Function()? action;
|
|
final String? tooltip;
|
|
final Badge? badge;
|
|
final AdaptiveFab? floatingActionButton;
|
|
// final FloatingActionButton? floatingActionButton;
|
|
|
|
DestinationModel({
|
|
required this.label,
|
|
this.icon,
|
|
this.selectedIcon,
|
|
this.route,
|
|
this.action,
|
|
this.tooltip,
|
|
this.badge,
|
|
this.floatingActionButton,
|
|
}) : assert(
|
|
badge == null || icon == null,
|
|
'Only one of icon or badge should be provided, not both.',
|
|
);
|
|
|
|
/// Converts this [DestinationModel] to a [NavigationRailDestination] used in a [NavigationRail].
|
|
NavigationRailDestination toNavigationRailDestination({EdgeInsets? padding}) {
|
|
if (badge != null) {
|
|
return NavigationRailDestination(
|
|
icon: badge!,
|
|
label: Text(label),
|
|
selectedIcon: badge!,
|
|
padding: padding,
|
|
);
|
|
}
|
|
return NavigationRailDestination(
|
|
icon: icon!,
|
|
label: Text(label),
|
|
selectedIcon: selectedIcon,
|
|
padding: padding,
|
|
);
|
|
}
|
|
|
|
/// Converts this [DestinationModel] to a [NavigationDrawerDestination] used in a [NavigationDrawer].
|
|
NavigationDrawerDestination toNavigationDrawerDestination() {
|
|
if (badge != null) {
|
|
return NavigationDrawerDestination(
|
|
icon: badge!,
|
|
label: Text(label),
|
|
selectedIcon: badge!,
|
|
);
|
|
}
|
|
return NavigationDrawerDestination(
|
|
icon: icon!,
|
|
label: Text(label),
|
|
selectedIcon: selectedIcon,
|
|
);
|
|
}
|
|
|
|
/// Converts this [DestinationModel] to a [NavigationDestination] used in a [BottomNavigationBar].
|
|
NavigationDestination toNavigationDestination() {
|
|
if (badge != null) {
|
|
return NavigationDestination(
|
|
icon: badge!,
|
|
label: label,
|
|
selectedIcon: badge!,
|
|
);
|
|
}
|
|
return NavigationDestination(
|
|
icon: icon!,
|
|
label: label,
|
|
selectedIcon: selectedIcon,
|
|
tooltip: tooltip,
|
|
);
|
|
}
|
|
|
|
NavigationButton toNavigationButton(bool selected, bool expanded) {
|
|
return NavigationButton(
|
|
label: label,
|
|
selected: selected,
|
|
onPressed: action,
|
|
horizontal: expanded,
|
|
selectedIcon: selectedIcon!,
|
|
icon: icon!,
|
|
);
|
|
}
|
|
}
|