attach method

  1. @override
Widget? attach(
  1. BuildContext context,
  2. DropdownViewController<T> controller
)
override

Implementation

@override
Widget? attach(BuildContext context, DropdownViewController<T> controller) {
  return LayoutBuilder(
    builder: (context, constraints) {
      return DropdownMenu<T>(
        width: constraints.maxWidth,
        initialSelection: controller.selectedItem,
        textStyle: controller.textStyle,
        leadingIcon: controller.leadingIconVisible
            ? Builder(
                builder: (context) {
                  if (leadingIconBuilder != null) {
                    return leadingIconBuilder!(context);
                  } else {
                    return RawIconView(
                      icon: controller.leadingIcon,
                      tint: controller.leadingIconTint,
                      size: controller.leadingIconSize ?? 18,
                    );
                  }
                },
              )
            : null,
        trailingIcon: controller.trailingIconVisible
            ? Builder(
                builder: (context) {
                  if (trailingIconBuilder != null) {
                    return trailingIconBuilder!(context);
                  } else {
                    return RawIconView(
                      icon: controller.trailingIcon ??
                          Icons.keyboard_arrow_down,
                      tint: controller.trailingIconTint,
                      size: controller.trailingIconSize ?? 18,
                    );
                  }
                },
              )
            : const SizedBox(),
        selectedTrailingIcon: controller.trailingSelectedIconVisible
            ? Builder(
                builder: (context) {
                  if (trailingSelectedIconBuilder != null) {
                    return trailingSelectedIconBuilder!(context);
                  } else {
                    return RawIconView(
                      icon: controller.trailingSelectedIcon ??
                          Icons.keyboard_arrow_up,
                      tint: controller.trailingSelectedIconTint,
                      size: controller.trailingSelectedIconSize ?? 18,
                    );
                  }
                },
              )
            : const SizedBox(),
        inputDecorationTheme: InputDecorationTheme(
          isDense: true,
          border: InputBorder.none,
          constraints: BoxConstraints(
            minWidth: constraints.minWidth,
            minHeight: constraints.minHeight,
            maxWidth: constraints.maxWidth,
            maxHeight: constraints.maxHeight,
          ),
          contentPadding: EdgeInsets.zero,
        ),
        menuStyle: MenuStyle(
          padding: MaterialStateProperty.all(EdgeInsets.zero),
        ),
        dropdownMenuEntries: items.map((e) {
          return DropdownMenuEntry<T>(
            value: e.value,
            label: e.name,
          );
        }).toList(),
        onSelected: onItemSelected,
      );
    },
  );
}