import 'package:flutter/material.dart';
import 'package:xm_test_demo/utils/color.dart';
class LoginInput extends StatefulWidget {
final String title;
final String tip;
final ValueChanged<String> onChanged;
final ValueChanged<bool> focusChanged;
TextInputType keyboardType;
LoginInput(this.title, this.tip, this.onChanged, this.focusChanged,
{this.keyboardType = TextInputType.phone});
@override
State<LoginInput> createState() => _LoginInputState();
}
class _LoginInputState extends State<LoginInput> {
final _focusNode = FocusNode();
@override
void initState() {
super.initState();
_focusNode.addListener(() {
print("光标:== ${_focusNode.hasFocus}");
if (widget.focusChanged != null) {
widget.focusChanged(_focusNode.hasFocus);
}
});
}
@override
void dispose() {
_focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Row(
children: [
Container(
padding: EdgeInsets.only(left: 20),
width: 100,
child: Text(
widget.title,
style: TextStyle(fontSize: 16),
),
),
_input(),
],
),
Divider(
height: 0,
thickness: 1,
indent: 20,
)
],
);
}
_input() {
return Expanded(
child: TextField(
focusNode: _focusNode,
onChanged: this.widget.onChanged,
keyboardType: widget.keyboardType,
cursorColor: primayColor,
style: TextStyle(
color: Colors.green, fontSize: 16, fontWeight: FontWeight.normal),
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 0, right: 20),
border: InputBorder.none,
hintText: widget.tip ?? "",
hintStyle: TextStyle(
color: Colors.grey, fontSize: 14, fontWeight: FontWeight.normal)),
));
}
}
```