buildBottomNavigationBar method

  1. @protected
Widget buildBottomNavigationBar(
  1. BuildParameters params
)

Implementation

@protected
Widget buildBottomNavigationBar(BuildParameters params) {
  var currentIdx = parseInt(params.props["startIndex"]);
  final type = params.props["type"] == "shifting"
      ? BottomNavigationBarType.shifting
      : BottomNavigationBarType.fixed;

  var landscapeLayout = BottomNavigationBarLandscapeLayout.centered;
  if (params.props["layout"] != null) {
    switch (params.props["layout"]) {
      case "linear":
        landscapeLayout = BottomNavigationBarLandscapeLayout.linear;
        break;
      case "spread":
        landscapeLayout = BottomNavigationBarLandscapeLayout.spread;
        break;
      default:
        landscapeLayout = BottomNavigationBarLandscapeLayout.centered;
        break;
    }
  }

  final children = <WidgetNodeSpec>[];
  if (params.widgets["children"] != null) {
    for (var childSpec in params.widgets["children"]) {
      children.add(WidgetNodeSpec.fromMap(childSpec));
    }
  }

  final items = <BottomNavigationBarItem>[];
  for (var child in children) {
    final icon = child.widgets["icon"] != null
        ? builder.buildWidget(params.context, child.widgets["icon"],
            params.state, params.parentContext)
        : Icon(IconData(parseInt(child.props["iconCode"]),
            fontFamily: "MaterialIcons"));
    final activeIcon = child.widgets["activeIcon"] != null
        ? builder.buildWidget(params.context, child.widgets["activeIcon"],
            params.state, params.parentContext)
        : child.props["activeIconCode"] != null
            ? Icon(IconData(parseInt(child.props["activeIconCode"]),
                fontFamily: "MaterialIcons"))
            : null;

    items.add(BottomNavigationBarItem(
      icon: icon,
      activeIcon: activeIcon,
      label: properties.getText(child.props["label"], "label"),
      tooltip: child.props["tooltip"] != null
          ? properties.getText(child.props["tooltip"], "label")
          : null,
      backgroundColor: tryParseColor(child.props["backgroundColor"]),
    ));
  }

  return StatefulBuilder(
    builder: (context, setState) {
      return BottomNavigationBar(
        key: properties.getKey(params.id),
        items: items,
        backgroundColor: tryParseColor(params.props["backgroundColor"]),
        elevation: tryParseDouble(params.props["elevation"]),
        type: type,
        landscapeLayout: landscapeLayout,
        currentIndex: currentIdx,
        iconSize: parseDouble(params.props["iconSize"], defaultValue: 24.0),
        selectedFontSize:
            parseDouble(params.props["selectedFontSize"], defaultValue: 13.0),
        selectedItemColor: tryParseColor(params.props["selectedItemColor"]),
        unselectedFontSize: parseDouble(params.props["unselectedFontSize"],
            defaultValue: 12.0),
        unselectedItemColor:
            tryParseColor(params.props["unselectedItemColor"]),
        onTap: (idx) {
          setState(() => currentIdx = idx);
          final spec = children[idx];
          if (spec.actions["onTap"] != null) {
            events.run(
                params.context,
                NodeSpec.fromMap(spec.actions["onTap"]),
                params.state,
                null,
                params.parentContext);
          }
        },
      );
    },
  );
}