【发布时间】:2020-12-13 17:40:15
【问题描述】:
我认为这可能并不太复杂,但是我是编码新手并且不明白这一点,我在网上也找不到我能理解的解释。
在我的应用中,我的 AppBar 包含标题和底部,标题只是文本,底部是用户用来搜索我的数据库的 TextFormField。
最近我将标题更新为 DropdownButton,我想使用用户在那里选择的内容来更改我的 TextFormField 中的搜索参数(以便它可以搜索我数据库中的不同列)。
我在单独的文档中构建了 DropdownButton,然后将其插入到标题中。找到如何使用它更加棘手。
我构建了某种回调,可以在我的控制台中打印,但我不知道如何将信息传递到我的 TextFormField。
class HomePage extends StatelessWidget {
HomePage({Key key, this.title}) : super(key: key);
_handleValueReturned(value) {
if (value == 1) {print('This works');} if (value == 2) {print('This works not');} else {return null;}
}
...
appBar: AppBar(
title: DropDownButton(
valueReturned: _handleValueReturned,
),
bottom:...
...
我是否必须使用某种提供程序或“of”或包,如 Eventifier 或 ChangeNotifier?我无法弄清楚所有这些事情是如何运作的。
【问题讨论】:
-
听起来您需要使用 setState 或 Bloc 之类的状态管理策略来根据用户在下拉菜单中选择的选项进行更改。
标签: flutter provider dropdownbutton flutter-change-notifier textformfield