0

我创建了一个带有 AppBar 的 ListView,上面有一个 SearchIcon 和一个过滤器图标。单击过滤器图标时,它会打开一个 AlertDialogue。在这个 AlertDialouge 中,我希望用户能够勾选几个过滤器选项,并通过单击“好的”按钮将它们应用到列表视图。我的 Listview 是一种扩展状态的类型: class _CollectibleList<C extends Collectible> extends State<CollectibleList<C>>

现在我想将 a 添加DialogAction到 my 的操作中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")
          ],
        );
      },
    );
  }
4

1 回答 1

1

你可以试试:

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

于 2020-05-01T12:59:10.003 回答