import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/constants/bg_color.dart';
import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout_controller.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';

class ZtNumberInput extends StatelessWidget {
  final TextEditingController textController;
  final VoidCallback? onTap;
  final Function(String)? onChanged;

  final bool isRequired;
  final String labelText;
  final String? hint;
  const ZtNumberInput(
      {super.key,
      required this.textController,
      this.onTap,
      this.onChanged,
      this.hint,
      this.isRequired = false,
      this.labelText = ''});
  @override
  Widget build(BuildContext context) {
    return TextFormField(
      controller: textController,
      onTapOutside: (event) {
        FocusScope.of(context).unfocus();
      },
      onChanged: onChanged ?? (_) {},
      onTap: onTap ?? () {},
      textAlign: TextAlign.center,
      keyboardType: TextInputType.number,
      inputFormatters: <TextInputFormatter>[
        // 限制输入内容只能是数字和小数点不限制位数
        FilteringTextInputFormatter.allow(RegExp(r'^\d+\.?\d{0,10}')),
      ],
      decoration: InputDecoration(
        // contentPadding: EdgeInsets.symmetric(vertical: ScreenAdaper.height(18)),
        floatingLabelBehavior: FloatingLabelBehavior.always,
        label: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: [
              if (isRequired)
                Text(
                  "*",
                  style: TextStyle(
                      color: Colors.red, fontSize: ScreenAdaper.sp(30)),
                ),
              Text(
                labelText,
                style: TextStyle(fontSize: ScreenAdaper.sp(30)),
              ),
            ]),
        focusedBorder: OutlineInputBorder(
            borderSide:
                const BorderSide(color: AppTheme.primaryColorLight, width: 2),
            borderRadius: BorderRadius.circular(ScreenAdaper.sp(15))),
        hintText: hint ?? '请输入',
      ),
    );
  }
}
