Flutter开发记录:输入框

Flutter开发记录:输入框

narakuyang
2022-12-11 / 0 评论 / 12 阅读 / 正在检测是否收录...
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:wormhole_jp/style/color.dart';

class comSystemInput extends StatelessWidget {
  final TextEditingController textEditingController;
  final String hintText;
  final Widget prefixIcon;
  final Widget? suffixIcon;
  final bool? readOnly;
  const comSystemInput(
      {super.key,
      required this.textEditingController,
      required this.hintText,
      required this.prefixIcon,
      this.suffixIcon,
      this.readOnly});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(left: 12, right: 12),
      child: TextFormField(
        controller: textEditingController,
        onEditingComplete: () {
          FocusScope.of(context).unfocus();
        },
        inputFormatters: [
          LengthLimitingTextInputFormatter(50),
          FilteringTextInputFormatter.allow(RegExp("[0-9.]"))
        ],
        keyboardType: TextInputType.number,
        textInputAction: TextInputAction.done,
        readOnly: readOnly != null ? readOnly! : false,
        enableInteractiveSelection: false,
        enableIMEPersonalizedLearning: false,
        toolbarOptions: ToolbarOptions(
          copy: true,
          cut: true,
          paste: true,
          selectAll: true,
        ),
        decoration: InputDecoration(
          focusedErrorBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(12),
              borderSide: BorderSide(color: Colors.red, width: 2)),
          focusedBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(12),
              borderSide: BorderSide(color: appColor.buttom, width: 2)),
          hintText: hintText,
          hintStyle:
              GoogleFonts.notoSans(color: appColor.black.withOpacity(0.3)),
          prefixIcon: prefixIcon,
          suffixIcon: suffixIcon != null ? suffixIcon : null,
          suffixIconConstraints: BoxConstraints(
            maxHeight: 35,
            maxWidth: 43,
          ),
          border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(12),
              borderSide: BorderSide(color: appColor.black.withOpacity(0.5))),
        ),
      ),
    );
  }
}
0

评论

博主关闭了所有页面的评论