Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
2.6 kB
2
Indexable
Never
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

class CustomButton extends StatelessWidget {
  final Color background;
  final Text text;
  final double? width, height;
  final double borderRadius;
  final bool shadow;
  final EdgeInsets padding;
  final VoidCallback onTap;
  final Widget? icon;
  final bool? spaceBetween, iconFirst;

  CustomButton(
      {required this.background,
      required this.text,
      required this.borderRadius,
      required this.padding,
      required this.shadow,
      required this.onTap,
      this.width,
      this.height,
      this.spaceBetween,
      this.iconFirst,
      this.icon});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: onTap,
        child: Container(
          width: width ?? Get.width * 0.8,
          height: height,
          padding: padding,
          decoration: BoxDecoration(
            color: background,
            borderRadius: BorderRadius.circular(borderRadius),
          ),
          child: icon == null
              ? Center(child: text)
              : iconFirst != false
                  ? spaceBetween == true
                      ? Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          mainAxisSize: MainAxisSize.min,
                          children: [icon!, text],
                        )
                      : Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          mainAxisSize: MainAxisSize.min,
                          children: [
                              icon!,
                              const SizedBox(
                                width: 10.0,
                              ),
                              text,
                            ])
                  : spaceBetween == true
                      ? Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          mainAxisSize: MainAxisSize.min,
                          children: [text, icon!],
                        )
                      : Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          mainAxisSize: MainAxisSize.min,
                          children: [
                              text,
                              const SizedBox(
                                width: 10.0,
                              ),
                              icon!
                            ]),
        ));
  }
}