Search code examples
fluttercolorsflutter-alertdialog

How to put a colour listview in an alertdialog, with the leading as the colour


Hello my problem is about building a good alertdialog.

i have a Listtile Listtile where the leading is a color and the title is the name of the colour. on tap the Listtile shows a alert dialog with colour options.

this is what i am expecting to archieve.

enter image description here enter image description here

i found this solution from a page but the code was really hard to scale.

i am expecting to archieve this result by using a map on the colours and printing them as Listview on the alert dialog. thanks in advance for the help


Solution

  • Isn't this question how to send something to another page ?

    Based on comment, you want to pass color with their names. So it could be pass to the second screen like this.

    The first page,

    var colors = {};
    colors['color_x'] = 'COLORX';
    colors['color_y'] = 'COLORY';
    
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => SecondScreen(colors: colors),
      ),
    );
    

    In the second page,

    class SecondScreen extends StatelessWidget {
      final Map colors;
    
      SecondScreen({Key key, @required this.colors}) : super(key: key);
      ...
    }