Реализация диалога для фильтрации списка во флаттере - PullRequest
0 голосов
/ 01 мая 2020

Я создал ListView с AppBar с SearchIcon и значком фильтра на нем. При щелчке значка фильтра открывается диалог AlertDialogue. В этом AlertDialouge я хочу, чтобы пользователь мог пометить несколько опций фильтра и применить их к просмотру списка, нажав кнопку с надписью «все в порядке». Мой ListView - это тип, который расширяет State: 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")
          ],
        );
      },
    );
  }

1 Ответ

1 голос
/ 01 мая 2020

Вы можете попробовать:

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

...