import 'package:flutter/material.dart';

class Responsive {
  final BuildContext context;

  Responsive(this.context);

  Widget builder(
      {required final Widget mobile,
      required final Widget desktop,
      final Widget? tablet,
      final bool tabletAndMobileSame = false}) {
    if (isMobile() || (isTablet() && tabletAndMobileSame)) {
      return mobile;
    } else if (isTablet() && tablet != null) {
      return tablet;
    } else {
      return desktop;
    }
  }

  Widget maxWidthInDesktop(
      {final double maxWidth = 600,
      required final Widget Function(
        BuildContext contxet,
        double mw,
      ) child}) {
    if (isDesktop() || isTablet()) {
      return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ConstrainedBox(
            constraints: BoxConstraints(maxWidth: maxWidth),
            child: child(context, maxWidth),
          ),
        ],
      );
    } else {
      return child(context, MediaQuery.sizeOf(context).width);
    }
  }

  bool isMobile() => MediaQuery.sizeOf(context).width < 904;
  bool isTablet() =>
      MediaQuery.sizeOf(context).width < 1280 &&
      MediaQuery.sizeOf(context).width >= 904;
  bool isDesktop() => MediaQuery.sizeOf(context).width >= 1280;
}
