squareTile method

Widget squareTile(
  1. BuildContext context, {
  2. IconData? icon,
  3. required String? title,
  4. dynamic onTap()?,
  5. dynamic onInfoTap()?,
  6. String? value,
  7. String? subtitle,
  8. bool selected = false,
})

Implementation

Widget squareTile(
  BuildContext context, {
  IconData? icon,
  required String? title,
  Function()? onTap,
  Function()? onInfoTap,
  String? value,
  String? subtitle,
  bool selected = false,
}) {
  if (value == null) {
    var backgroundColor = selected
        ? Theme.of(context).colorScheme.background.calculateLuminance()
        : Theme.of(context).colorScheme.background;
    return InkWell(
      onTap: () {
        if (onTap != null) {
          onTap();
        }
      },
      child: Container(
          constraints: BoxConstraints(
            maxWidth: MediaQuery.of(context).size.width / 2,
          ),
          padding: EdgeInsets.all(DUI.spacing.lateralPaddingValue),
          decoration: BoxDecoration(
            color: backgroundColor,
            border: Border.all(
                color: Theme.of(context).colorScheme.background,
                width: DUI.spacing.borderWidth),
            borderRadius: BorderRadius.circular(DUI.spacing.borderRadius),
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Expanded(
                      child: GestureDetector(
                    onTap: onInfoTap != null
                        ? () {
                            onInfoTap();
                          }
                        : null,
                    child: Container(
                      width: double.infinity,
                      color: Colors.transparent,
                      child: Row(
                        children: [
                          Flexible(
                            child: DUI.text.regular(context, title,
                                bold: true,
                                color: backgroundColor.calculateLuminance(),
                                maxLines: 1),
                          ),
                          DUI.spacing.hSpacer(small: true),
                          onInfoTap != null
                              ? Icon(Icons.info_outline_rounded,
                                  size: 12,
                                  color: backgroundColor.calculateLuminance())
                              : SizedBox.shrink(),
                        ],
                      ),
                    ),
                  )),
                  icon == null
                      ? SizedBox.shrink()
                      : Icon(icon,
                          color: backgroundColor.calculateLuminance()),
                ],
              ),
              subtitle != null
                  ? DUI.text.xs(context, subtitle,
                      color: backgroundColor.calculateLuminance())
                  : SizedBox.shrink(),
            ],
          )),
    );
  }
  return InkWell(
    onTap: () {
      if (onTap != null) {
        onTap();
      }
    },
    child: Container(
        constraints: BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width / 2,
        ),
        padding: EdgeInsets.all(DUI.spacing.lateralPaddingValue),
        decoration: BoxDecoration(
          color: Theme.of(context).colorScheme.background,
          border: Border.all(
              color: Theme.of(context).colorScheme.background,
              width: DUI.spacing.borderWidth),
          borderRadius: BorderRadius.circular(DUI.spacing.borderRadius),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Expanded(
                  child: DUI.text.title1(context, value),
                ),
                icon == null ? SizedBox.shrink() : Icon(icon),
              ],
            ),
            DUI.spacing.spacer(small: true),
            GestureDetector(
              onTap: onInfoTap != null
                  ? () {
                      onInfoTap();
                    }
                  : null,
              child: Container(
                width: double.infinity,
                color: Colors.transparent,
                child: Row(
                  children: [
                    Flexible(
                      child: DUI.text.regular(context, title,
                          bold: true,
                          color:
                              Theme.of(context).textTheme.bodyMedium!.color,
                          maxLines: 1),
                    ),
                    DUI.spacing.hSpacer(small: true),
                    onInfoTap != null
                        ? Icon(
                            Icons.info_outline_rounded,
                            size: 12,
                          )
                        : SizedBox.shrink(),
                  ],
                ),
              ),
            )
          ],
        )),
  );
}