大家好,所有可以帮助我计算代码的人,
import 'package:flutter/material.dart';
import 'package:survey/widgets/widgetlist.dart';
import 'dart:ui' as ui;
class Item {
Item(this.name);
String name;
}
class createnewsurv extends StatefulWidget {
@override
_createnewsurvState createState() => _createnewsurvState();
}
class _createnewsurvState extends State<createnewsurv> {
TextEditingController _textcontroller = new TextEditingController();
int surveyquestionnum = 1;
Item selectedUser;
List<Item> users = <Item>[
Item('Sample 1'),
Item('Sample 2'),
Item('Sample 3'),
Item('Sample 4'),
];
List<Item> users2 = <Item>[
Item('Sample EMOJI 1'),
Item('Sample EMOJI 2'),
Item('Sample EMOJI 3'),
Item('Sample EMOJI 4'),
];
@override
Widget _dropdownbutton (List<Item> userlist){
return Container(
padding: EdgeInsets.all(1),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(
Radius.circular(15.0)
),
),
child: DropdownButton<Item>(
underline: SizedBox(),
isExpanded: true,
icon: Icon(Icons.arrow_drop_down),
hint: Text(" SELECT FROM DROPDOWN"),
value: selectedUser,
onChanged: (Item Value) {
setState(() {
selectedUser = Value;
});
},
items: userlist.map((Item user) {
return DropdownMenuItem<Item>(
value: user,
child: Row(
children: <Widget>[
SizedBox(width: 10,),
Text(
user.name,
style: TextStyle(color: Colors.black),
),
],
),
);
}).toList(),
),
);
}
Widget build(BuildContext context) {
final ui.Size logicalSize = MediaQuery.of(context).size;
final double _height = logicalSize.height;
return SafeArea(
child: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("CREATE A NEW SURVEY ",style: txtttitsize),
SizedBox(height: 10),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(" SURVEY TITLE",style: txtttitsize),
),
_dropdownbutton(users),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(" SELECT EMOJI SET",style: txtttitsize),
),
_dropdownbutton(users2),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(" SURVEY QUESTION #$surveyquestionnum",style: txtttitsize),
),
TextFormField(
autocorrect: true,
controller: _textcontroller,
maxLines: 10,
onSaved: (value){
},
validator: (val){
if(val.isEmpty){
return "This page Cannot be Blank!";
}else{
return null;
}
},
decoration: InputDecoration(
labelText: "QUESTION",
fillColor: Colors.white,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25)
)
),
)
]
),
),
)),
);
}
}
这是一个不完整的代码,但如果你注意到并尝试运行它,它会显示 2 个下拉小部件,当我选择它时由于某种原因它崩溃显示''应该只有一个项目具有 [DropDownButton] 的值:错误,
下一个是 textform 字段,我希望当我将它包装在 singlescrollview 上时,当有人键入它应该或让视口在键入时将其屏幕聚焦到文本框,但它已经在第三行并且它已经被阻止键盘,
我可能错了,但我怎样才能正确使用 singlescrollview 呢?或者如果有一个替代小部件可以让这个文本框有机会在用户键入时被用户正确查看?
更新
单击任何下拉按钮后会出现此错误。我用建议的答案更新了代码,对我来说还是一样。