import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class FormItemComponent extends StatelessWidget {
  const FormItemComponent({
    Key? key,
    this.leadingText = '',
    this.must = false,
    this.child,
    this.crossAxisAlignment = CrossAxisAlignment.center,
  }) : super(key: key);
  final String? leadingText;
  final bool? must;
  final Widget? child;
  final CrossAxisAlignment? crossAxisAlignment;
  @override
  Widget build(BuildContext context) {
    return Wisdom.row(
      mainAxisAlignment: MainAxisAlignment.end,
      crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.center,
      padding: EdgeInsets.only(bottom: 10.pt),
      children: [
        Wisdom.rich(
          alignment: Alignment.centerRight,
          width: 80.pt,
          children: [
            if (must == true)
              TextSpan(
                text: '*',
                style: TextStyle(color: Color(0XFFFF495E)),
              ),
            TextSpan(
              text: leadingText,
              style: TextStyle(
                fontSize: 15.pt,
                fontWeight: FontWeight.w600,
              ),
            ),
          ],
        ),
        SizedBox(width: 10.pt),
        if (child != null) child!.asExpanded()
      ],
    );
  }
}
