【发布时间】:2022-12-23 19:02:20
【问题描述】:
我尝试在 Flutter 中构建一个复杂的 From。该应用程序将在 Windows 和 Web 上运行。但是现在我遇到了 DropdownButtonFormField 的问题。我希望它只需要那么宽。但是即使我将 isExpanded 设置为 false 也会扩展。 我哪里错了?
这里的代码:
class FormOne extends StatefulWidget {
const FormOne({Key? key}) : super(key: key);
@override
State<FormOne> createState() => _FormOneState();
}
class _FormOneState extends State<FormOne> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {Padding(
padding: EdgeInsets.only(top: 15),
child: Form(
key: _formKey,
child: Column(
children: [
Text("Headline"),
const SizedBox(height: 10),
Container(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
color: Colors.white,
child: DropdownButtonFormField<String>(
items: [
DropdownMenuItem<String>(
child: BbnText.paragraphContrast("test 1"),
value: "test 1",
),
DropdownMenuItem<String>(
child: BbnText.paragraphContrast("test 100000"),
value: "test 100000",
)
],
value: "test 100000",
onChanged: (String? value) {},
onSaved: (value) => null,
isExpanded: false,
style: context.textTheme.paragraphContrast,
icon: Icon(Icons.arrow_drop_down, color: Colors.black,),
iconSize: 25,
dropdownColor: context.textFieldBackground,
borderRadius: BorderRadius.circular(5),
decoration: InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.never,
isCollapsed: true,
border: InputBorder.none,
),
),
)
],
),
),
);
}
_saveForm(){
if(_formKey.currentState?.validate() ?? false){
_formKey.currentState!.save();
}
}
}
【问题讨论】:
标签: flutter forms drop-down-menu