Implementing a Dialog to filter a List in flutter

Issue

I created a ListView with an AppBar with a SearchIcon and a filter Icon on it.
When the filter Icon is clicked, it opens an AlertDialogue.
In this AlertDialouge I want the user to be able to tick off several filter options and apply them to the listview via clicking on a button that says “okay”.
My Listview is a type that extends a State:
class _CollectibleList<C extends Collectible> extends State<CollectibleList<C>>

Now I want to add a DialogAction to the actions of my AlertDialog, but I get the following error:
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)

To me it seems like an Import is missing, but I can’t find anything.
My Imports are:

import 'dart:async';
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'collectible.dart';
...

This is the codesnippet:

void _showAlertDialog(){
    showDialog(
      context: context,
      builder: (BuildContext context){
        return AlertDialog(
          title: Text('Alert!'),
          content: Text("content"),
          actions: AlertDialog[
            DialogAction("Okay")
          ],
        );
      },
    );
  }

Solution

You could try:

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();
        },
      ),
    ],
    );
  },
);

}

See the documentation:
https://api.flutter.dev/flutter/material/AlertDialog-class.html

Answered By – Marco Medri

Answer Checked By – David Goodson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *