键盘弹起 显示超出时(溢出时)加SingleChildScrollView 单独滚动组件 SingleChildScrollView
SingleChildScrollView跟listview有冲突 盒子里面有listview外面就不要用SingleChildScrollView
设置控制器才可以获取文本域的值 controller: typeController,
TextEditingController typeController =TextEditingController();
class HomePageextends StatefulWidget {
@override
_HomePageState createState() =>_HomePageState();
}
class _HomePageStateextends State {
TextEditingControllertypeController =TextEditingController();
String_showText ="hello world";
void _choiceAction() {
print("开始选择你喜欢的类型。。。。。。。。。");
if (typeController.text.toString() =='') {
showDialog(
context:context,
builder: (context) =>AlertDialog(
title:new Text("姓名不能为空"),
));
}else {
getHttp(typeController.text.toString()).then((value) {
setState(() {
_showText = value['resultInfo']['message'];
});
});
}
}
@override
Widget build(BuildContext context) {
return Container(
child:Scaffold(
appBar:AppBar(
title:new Text(KString.mainTitle),
),
// 键盘弹起 显示超出时(溢出时)加SingleChildScrollView 单独滚动组件
body:SingleChildScrollView(
child:Container(
child:Column(
children: [
TextField(
// 设置控制器才可以获取文本域的值
controller:typeController,
// 修饰文本框
decoration:InputDecoration(
contentPadding:EdgeInsets.all(10.0),
labelText:'姓名',
helperText:'请输入您的姓名'),
autofocus:false,
),
RaisedButton(
onPressed: _choiceAction,
child:Text("填写完毕"),
),
Container(
child:Text(
_showText,
// 外面没有container 用overflow控制一下
overflow: TextOverflow.ellipsis,
),
margin:EdgeInsets.only(bottom:500.0),
)
],
),
),
)),
);
}
Future getHttp(String TypeText)async {
try {
Response response;
var data = {'name': TypeText};
response =await Dio()
.post(servicePath['homePageContent'], queryParameters: data);
return response.data;
}catch (e) {}
}
}
网友评论