初级 Flutter 爱好者,刚刚学习 widget 系统。想要使用开箱即用的小部件(不是插件也可以)实现自动完成文本字段 DropdownButtonFormField 非常适合我的用例,但当我尝试使用它时,编译器给我一个方法未找到错误。
Compiler message:
lib/expanding_text.dart:100:11: Error: Method not found: 'DropdownButtonFormField'.
DropdownButtonFormField(),
^^^^^^^^^^^^^^^^^^^^^^^
lib/expanding_text.dart:100:11: Error: The method 'DropdownButtonFormField' isn't defined for the class '#lib1::_TripItemState'.
Try correcting the name to the name of an existing method, or defining a method named 'DropdownButtonFormField'.
DropdownButtonFormField(),
Run Code Online (Sandbox Code Playgroud)
这是我的代码(相关部分)
import 'package:flutter/material.dart';
...
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
DropdownButtonFormField<String>(
items: [DropdownMenuItem<String>(child:Text("test"))],
),
Run Code Online (Sandbox Code Playgroud)
查看文档,似乎我可以自由地将其添加到小部件树中,而无需额外的配置。但显然,由于错误,我在这里遗漏了一些东西。
那么,为了解决发生的问题,DropdownButtonFormField 是否仍在材质库中?
我还缺少什么吗?