You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.7 KiB
Dart
135 lines
3.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
class JdText extends StatefulWidget {
|
|
final String text;
|
|
final String title;
|
|
bool password;
|
|
final Object onChanged;
|
|
final int maxLines;
|
|
final double height;
|
|
TextEditingController controller;
|
|
final String endBtn;
|
|
|
|
JdText(
|
|
{Key key,
|
|
this.text = "输入内容",
|
|
this.title = '标题',
|
|
this.password = false,
|
|
this.onChanged,
|
|
this.maxLines = 1,
|
|
this.height = 68,
|
|
this.controller,
|
|
this.endBtn})
|
|
: super(key: key);
|
|
|
|
_JdTextState createState() => _JdTextState();
|
|
}
|
|
|
|
class _JdTextState extends State<JdText> {
|
|
Icon ShowHiddenIcon = Icon(Icons.more_horiz);
|
|
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
alignment: Alignment(0, -1),
|
|
padding: EdgeInsets.only(top: 0),
|
|
height: ScreenUtil().setHeight(widget.height),
|
|
decoration:
|
|
BoxDecoration(border: Border(bottom: BorderSide(width: 1, color: Colors.black12))),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Container(
|
|
alignment: Alignment(0, 0),
|
|
child: Container(
|
|
padding: EdgeInsets.only(top: 0, bottom: 0),
|
|
child: Text(
|
|
widget.title,
|
|
style: TextStyle(
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
//Flutter中Row中不能直接使用textfield控件
|
|
Expanded(
|
|
child: TextField(
|
|
textAlignVertical: TextAlignVertical(y: 1.0),
|
|
controller: widget.controller,
|
|
maxLines: 1,
|
|
obscureText: widget.password,
|
|
decoration: InputDecoration(
|
|
//contentPadding: EdgeInsets.only(bottom: 16),
|
|
hintText: widget.text,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(30), borderSide: BorderSide.none),
|
|
),
|
|
onChanged: widget.onChanged,
|
|
),
|
|
),
|
|
getBtn(),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget getBtn() {
|
|
Widget btn;
|
|
switch (widget.endBtn) {
|
|
case 'ClearBtn':
|
|
widget.controller = new TextEditingController();
|
|
btn = Container(
|
|
// alignment: Alignment(0, -1),
|
|
// padding: EdgeInsets.only(bottom: 23),
|
|
child: IconButton(
|
|
icon: Icon(Icons.highlight_off),
|
|
onPressed: () {
|
|
setState(() {
|
|
widget.controller.clear();
|
|
});
|
|
}),
|
|
);
|
|
break;
|
|
case 'ShowHiddenBtn':
|
|
btn = Container(
|
|
// alignment: Alignment(0, -1),
|
|
// padding: EdgeInsets.only(bottom: 23),
|
|
child: IconButton(
|
|
icon: ShowHiddenIcon,
|
|
onPressed: () {
|
|
widget.password = !widget.password;
|
|
setState(() {
|
|
ShowHiddenIcon =
|
|
widget.password ? Icon(Icons.more_horiz) : Icon(Icons.remove_red_eye);
|
|
});
|
|
}),
|
|
);
|
|
break;
|
|
case 'OutlineButton':
|
|
btn = Container(
|
|
child: OutlineButton(
|
|
borderSide: BorderSide(color: Colors.blue),
|
|
onPressed: () {},
|
|
child: Container(
|
|
child: Text("获取验证码"),
|
|
),
|
|
),
|
|
);
|
|
break;
|
|
default:
|
|
btn = SizedBox.shrink();
|
|
break;
|
|
}
|
|
return btn;
|
|
}
|
|
}
|