visibleOn method

Widget visibleOn({
  1. bool mobile = true,
  2. bool tablet = true,
  3. bool desktop = true,
})

Show/hide based on screen width

Implementation

Widget visibleOn({
  bool mobile = true,
  bool tablet = true,
  bool desktop = true,
}) {
  return LayoutBuilder(
    builder: (context, constraints) {
      final isMobile = constraints.maxWidth < 800;
      final isTablet = constraints.maxWidth >= 800 && constraints.maxWidth < 1200;
      final isDesktop = constraints.maxWidth >= 1200;

      if ((isMobile && mobile) || (isTablet && tablet) || (isDesktop && desktop)) {
        return this;
      }
      return const SizedBox.shrink();
    },
  );
}