实现一个对话框以在 flutter 中过滤一个列表
Implementing a Dialog to filter a List in flutter
我创建了一个带有 AppBar 的 ListView,上面有一个 SearchIcon 和一个过滤器图标。
单击过滤器图标时,它会打开一个 AlertDialogue。
在此 AlertDialouge 中,我希望用户能够勾选几个过滤器选项,并通过单击显示 "okay" 的按钮将它们应用到列表视图。
我的 Listview 是一种扩展状态的类型:
class _CollectibleList<C extends Collectible> extends State<CollectibleList<C>>
现在我想将 DialogAction
添加到我的 AlertDialog
的操作中,但我收到以下错误:
The method 'DialogAction' isn't defined for the type '_CollectibleList'.Try correcting the name to the name of an existing method, or defining a method named 'DialogAction'.dart(undefined_method)
对我来说似乎缺少导入,但我找不到任何东西。
我的进口商品是:
import 'dart:async';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'collectible.dart';
...
这是代码片段:
void _showAlertDialog(){
showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: Text('Alert!'),
content: Text("content"),
actions: AlertDialog[
DialogAction("Okay")
],
);
},
);
}
你可以试试:
void _showAlertDialog(){
showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: Text('Alert!'),
content: Text("content"),
actions: <Widget>[
FlatButton(
child: Text('Okay'),
onPressed: () {
///Insert here an action, in your case should be:
/// Navigator.of(context).pop();
},
),
],
);
},
);
}
查看文档:
https://api.flutter.dev/flutter/material/AlertDialog-class.html
我创建了一个带有 AppBar 的 ListView,上面有一个 SearchIcon 和一个过滤器图标。
单击过滤器图标时,它会打开一个 AlertDialogue。
在此 AlertDialouge 中,我希望用户能够勾选几个过滤器选项,并通过单击显示 "okay" 的按钮将它们应用到列表视图。
我的 Listview 是一种扩展状态的类型:
class _CollectibleList<C extends Collectible> extends State<CollectibleList<C>>
现在我想将 DialogAction
添加到我的 AlertDialog
的操作中,但我收到以下错误:
The method 'DialogAction' isn't defined for the type '_CollectibleList'.Try correcting the name to the name of an existing method, or defining a method named 'DialogAction'.dart(undefined_method)
对我来说似乎缺少导入,但我找不到任何东西。 我的进口商品是:
import 'dart:async';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'collectible.dart';
...
这是代码片段:
void _showAlertDialog(){
showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: Text('Alert!'),
content: Text("content"),
actions: AlertDialog[
DialogAction("Okay")
],
);
},
);
}
你可以试试:
void _showAlertDialog(){
showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: Text('Alert!'),
content: Text("content"),
actions: <Widget>[
FlatButton(
child: Text('Okay'),
onPressed: () {
///Insert here an action, in your case should be:
/// Navigator.of(context).pop();
},
),
],
);
},
);
}
查看文档: https://api.flutter.dev/flutter/material/AlertDialog-class.html