import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';

class CustomTextField extends StatelessWidget {
  final String labelText;
  final String hintText;
  final TextEditingController? controller;
  final VoidCallback? onTap;
  final EdgeInsetsGeometry padding;

  const CustomTextField(
      {Key? key,
      required this.labelText,
      required this.hintText,
      this.controller,
      this.onTap,
      this.padding = const EdgeInsets.symmetric(horizontal: 0.0, vertical: 16)})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: padding,
        child: PlatformTextField(
            material: (_, __) => MaterialTextFieldData(
                  decoration: InputDecoration(
                      border: const OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(5))),
                      suffixIcon: IconButton(
                        onPressed:
                            controller != null && controller!.text.isNotEmpty
                                ? controller!.clear
                                : null,
                        icon: Icon(Icons.clear),
                      ),
                      hintText: hintText,
                      labelText: labelText),
                ),
            cupertino: (_, __) =>
                CupertinoTextFieldData(placeholder: labelText),
            controller: controller,
            onTap: onTap));
  }
}
