buildNavigationRail method
Implementation
@protected
Widget buildNavigationRail(BuildParameters params) {
final props = params.props;
final destinations = <NavigationRailDestination>[];
final destinationActions = <Function?>[];
final destinationsSpec = params.widgets["destinations"];
if (destinationsSpec != null) {
for (var spec in destinationsSpec) {
var specProps = spec["properties"] ?? {};
if (!EditorBloc.editMode &&
specProps["buildCondition"] != null &&
!properties.evaluateCondition(specProps["buildCondition"])) {
continue;
}
var type = spec["_type"];
var iconCode = parseInt(specProps["iconCode"]);
var selectedIconCode = parseInt(specProps["selectedIconCode"]);
String label = specProps["label"] ?? "";
if (type == "ScreenDestination") {
var screen = Schema.getScreen(specProps["screen"]);
if (screen == null) {
continue;
}
if (label.isEmpty) {
label = screen.name ?? label;
}
if (iconCode == 0) {
iconCode = parseInt(screen.props["iconCode"]);
}
if (selectedIconCode == 0) {
selectedIconCode = parseInt(screen.props["selectedIconCode"]);
}
destinationActions.add(() {
SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
final navigator = Navigator.of(params.context);
navigator.popUntil((route) => route.isFirst);
if (!Lowder.editorMode) {
navigator.pushReplacement(builder.buildRoute(screen));
} else {
navigator.push(builder.buildRoute(screen));
}
});
SchedulerBinding.instance.ensureVisualUpdate();
});
} else {
var specActions = spec["actions"] ?? {};
destinationActions.add(events.getFunction(params.context,
specActions["onTap"], params.state, params.parentContext));
}
destinations.add(NavigationRailDestination(
icon: Icon(IconData(iconCode, fontFamily: "MaterialIcons")),
selectedIcon:
Icon(IconData(selectedIconCode, fontFamily: "MaterialIcons")),
label: Text(properties.getText(label, "menu")),
padding: params.buildProp("padding"),
));
}
}
final minWidth = parseDouble(props["minWidth"], defaultValue: 72);
final minExtendedWidth =
parseDouble(props["minExtendedWidth"], defaultValue: 256);
final groupAlignment =
parseDouble(props["groupAlignment"], defaultValue: -1);
return StatefulBuilder(builder: (context, setState) {
final selectedIndex = parseInt(
Lowder.globalVariables["${params.id}.selectedIndex"],
defaultValue: parseInt(params.props["selectedIndex"]));
var extended = parseBool(Lowder.globalVariables["${params.id}.extended"],
defaultValue: parseBool(props["extended"]));
var leadingWidget = builder.tryBuildWidget(params.context,
params.widgets["leading"], params.state, params.parentContext);
if (leadingWidget != null && groupAlignment != -1) {
leadingWidget = Expanded(child: leadingWidget);
}
final trailing = builder.tryBuildWidget(params.context,
params.widgets["trailing"], params.state, params.parentContext);
var trailingWidget = trailing;
if (params.widgets["toggle"] != null) {
trailingWidget = Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (trailing != null) trailing,
InkWell(
onTap: () => setState(() {
extended = !extended;
Lowder.globalVariables["${params.id}.extended"] = extended;
}),
child: builder.buildWidget(
params.context,
params.widgets["toggle"],
params.state.clone()..addAll({"extended": extended}),
params.parentContext),
),
],
);
if (groupAlignment != 1) {
trailingWidget = Expanded(child: trailingWidget);
}
}
return SizedBox(
width: extended ? minExtendedWidth : minWidth,
child: NavigationRail(
key: properties.getKey(params.id),
selectedIndex: selectedIndex,
destinations: destinations,
elevation: tryParseDouble(props["elevation"]),
extended: extended,
useIndicator: tryParseBool(props["useIndicator"]),
indicatorColor: tryParseColor(props["indicatorColor"]),
backgroundColor: tryParseColor(props["backgroundColor"]),
minWidth: minWidth,
minExtendedWidth: minExtendedWidth,
labelType: params.buildProp("labelType"),
selectedLabelTextStyle: params.buildProp("selectedLabelTextStyle"),
selectedIconTheme: params.buildProp("selectedIconTheme"),
unselectedLabelTextStyle:
params.buildProp("unselectedLabelTextStyle"),
unselectedIconTheme: params.buildProp("unselectedIconTheme"),
groupAlignment: groupAlignment,
leading: leadingWidget,
trailing: trailingWidget,
onDestinationSelected: (idx) {
Lowder.globalVariables["${params.id}.selectedIndex"] = idx;
final action = destinationActions[idx];
if (action != null) {
action();
}
},
));
});
}