131 lines
3.9 KiB
Dart
131 lines
3.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../../../global/const/common_color.dart';
|
|
|
|
class SkyTextField extends StatefulWidget {
|
|
|
|
const SkyTextField({
|
|
super.key,
|
|
this.controller,
|
|
this.focusNode,
|
|
this.borderRadius = const BorderRadius.all(Radius.circular(7)),
|
|
this.padding = const EdgeInsets.only(left: 10, right: 10, top: 2, bottom: 2),
|
|
this.placeholder,
|
|
this.clearButtonMode = OverlayVisibilityMode.never,
|
|
this.prefix,
|
|
this.suffix,
|
|
this.keyboardType,
|
|
this.fontSize,
|
|
this.maxLines = 1,
|
|
this.maxLength,
|
|
this.onChanged,
|
|
this.inputFormatters,
|
|
this.height = 40.0,
|
|
this.width,
|
|
this.obscureText = false,
|
|
this.bgColor,
|
|
this.textInputAction,
|
|
this.onSubmitted,
|
|
this.onTap,
|
|
this.readOnly,
|
|
this.border,
|
|
this.onEditingComplete,
|
|
this.textColor,
|
|
this.showBottomBorder,
|
|
});
|
|
|
|
final Function()? onEditingComplete;
|
|
final Color? textColor;
|
|
final double? width;
|
|
final bool? readOnly;
|
|
final GestureTapCallback? onTap;
|
|
final ValueChanged<String>? onSubmitted;
|
|
final TextInputAction? textInputAction;
|
|
final TextEditingController? controller;
|
|
final FocusNode? focusNode;
|
|
|
|
final BorderRadius borderRadius;
|
|
final Border? border;
|
|
final EdgeInsetsGeometry padding;
|
|
final String? placeholder;
|
|
// final Color? placeholderColor;
|
|
final OverlayVisibilityMode clearButtonMode;
|
|
final Widget? prefix;
|
|
final Widget? suffix;
|
|
final TextInputType? keyboardType;
|
|
final double? fontSize;
|
|
final int? maxLines;
|
|
final int? maxLength;
|
|
final ValueChanged<String>? onChanged;
|
|
final List<TextInputFormatter>? inputFormatters;
|
|
final double? height;
|
|
final bool obscureText;
|
|
final Color? bgColor;
|
|
final bool? showBottomBorder;
|
|
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
return _ComTextFieldState();
|
|
}
|
|
}
|
|
|
|
class _ComTextFieldState extends State<SkyTextField> {
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return Container(
|
|
height: widget.height, width: widget.width,
|
|
decoration: BoxDecoration(
|
|
color: widget.bgColor ?? Colors.white,
|
|
borderRadius: widget.borderRadius,
|
|
border: widget.border
|
|
),
|
|
padding: widget.padding,
|
|
child: Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: CupertinoTextField(
|
|
controller: widget.controller,
|
|
readOnly: widget.readOnly ?? false,
|
|
focusNode: widget.focusNode,
|
|
decoration: widget.showBottomBorder==true ? BoxDecoration(
|
|
border: Border(
|
|
bottom: BorderSide(
|
|
color: Colors.grey.shade400,
|
|
width: 0.5,
|
|
),
|
|
),
|
|
) : BoxDecoration(),
|
|
placeholder: widget.placeholder,
|
|
placeholderStyle: TextStyle(
|
|
fontSize: widget.fontSize ?? 14,
|
|
color: CommonColor.withValue('#707488'),
|
|
),
|
|
style: TextStyle(
|
|
fontSize: widget.fontSize ?? 14,
|
|
color: widget.textColor ?? Colors.black,
|
|
),
|
|
prefix: widget.prefix,
|
|
clearButtonMode: widget.clearButtonMode,
|
|
keyboardType: widget.keyboardType,
|
|
maxLines: widget.maxLines,
|
|
maxLength: widget.maxLength,
|
|
onChanged: widget.onChanged,
|
|
inputFormatters: widget.inputFormatters,
|
|
obscureText: widget.obscureText,
|
|
textInputAction: widget.textInputAction ?? TextInputAction.done,
|
|
onSubmitted: widget.onSubmitted,
|
|
onTap: widget.onTap,
|
|
onEditingComplete: widget.onEditingComplete,
|
|
)),
|
|
if (widget.suffix != null) widget.suffix!,
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |