sqlite - 使用 DropdownButton 值
问题描述
我在我的颤振应用程序中构建了一个漂亮的 DropdownButton,但很难找到如何实际使用它。
如何提取选定的值?
我想用它来更新我的搜索栏的设置。当用户选择“1”时,搜索栏应该搜索我的 Sqlite 数据库中的特定列,当他们选择“2”时,它应该搜索其他列。在我提取值之后,最好将 if/else 语句放在搜索栏上方或在我的代码中告诉如何搜索数据库的部分?
解决方案
尝试这个:
search_page.dart
class SearchingPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MyBeautifulDropdownPage(
myIfElseFunction: (value) {
print('selected value is $value');
if(value =='1'){
_searchASpecificColumnInMySqliteDb();
}else if (value == '2'){
_searchTheOtherColumnInMySqliteDb();
}
},,
);
}
}
my_beautiful_dropdown.dart
class MyBeautifulDropdownPage extends StatelessWidget {
final Function(String) myIfElseFunction;
const MyBeautifulDropdownPage({Key key, this.myIfElseFunction}) : super(key: key);
@override
Widget build(BuildContext context) {
return new DropdownButton<String>(
items: <String>['1', '2'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: myIfElseFunction
),
}
}
onChanged
在下拉列表中,您可以使用属性获取所选列的值。在那里你可以把你的 if 语句
推荐阅读
- reactjs - 如何在 React 中将“功能组件”转换为“类组件”?
- c++ - Win32 在应用程序内使用资源字体
- html - html 表中的列周围的边框,某些行具有 collspan
- java - 我总共有 3 个测试用例,父类中有 2 个测试用例,子类中有 1 个测试用例,当我从头等舱运行脚本测试用例运行两次时
- angular - Angular 如何在 git 库的请求更改中提取更改?
- php - 模型 [App\Product] 没有查询结果 36
- javascript - 如何通过编写少量代码在 React 中创建大量变量
- spring-boot - 使用 Springboot @Conditional 动态加载数据类型
- reactjs - 在 GatsbyJS React 站点上输出未转义的 JSON+LD
- mesh - 如何使用 CGAL 为水平集表面的一部分生成网格?