import 'package:baseproject/core/theme/custom_color.dart';
import 'package:baseproject/core/theme/text_style.dart';
import 'package:flutter/material.dart';

// ignore: must_be_immutable
class FormControl extends StatelessWidget {
  FormControl({
    Key? key,
    this.isShowTextRequire = false,
    required this.child,
    this.labelText = "",
    this.labelTextStyle,
  }) : super(key: key);
  final String labelText;
  final bool isShowTextRequire;
  TextStyle? labelTextStyle;
  final Widget child;
  @override
  Widget build(BuildContext context) {
    return _buildBody();
  }

  Widget _buildBody() {
    labelTextStyle ??= textStyleBodySmall;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        labelText.isNotEmpty
            ? Container(
                padding: const EdgeInsets.only(bottom: 2),
                color: Colors.white,
                child: RichText(
                  text: TextSpan(
                      text: labelText,
                      style: labelTextStyle!.copyWith(color: CustomColor.textGray),
                      children: <InlineSpan>[
                        // if (isShowTextRequire)
                        //   TextSpan(text: ' * ', style: style?.copyWith(color: Colors.red)),
                        TextSpan(
                          text: isShowTextRequire ? ' *' : '',
                          style: labelTextStyle!.copyWith(color: CustomColor.redText),
                        ),
                      ]),
                ),
              )
            : const SizedBox(),
        child,
      ],
    );
  }
}
