Pannam T
Pannam T

Reputation: 479

Icons doesn't show under DropdownMenuItem

It's a simple DropdownMenuItem where I want to show an exit Icon beside the logout text, I can get the text but just can't show the icon. Icon(Icons.exit_to_app)

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Chap App'),
        actions: [
          //for logout
          DropdownButton(
            icon: Icon(Icons.more_vert,
                color: Theme.of(context).primaryIconTheme.color),
            items: [
              DropdownMenuItem(
                child: Container(
                  child: Row(
                    //mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      Icon(Icons.exit_to_app),
                      SizedBox(
                        width: 8,
                      ),
                      Text('Logout')
                    ],
                  ),
                ),
                value: 'logout',
              ),
            ],
            onChanged: (itemIdentifier) {
              //to check which value was pressed by looking  at the itemIdentifier
              if (itemIdentifier == 'logout') {
                //logout
                FirebaseAuth.instance.signOut();
              }
            },
          )
        ],
      ),

Theme Data

Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Chat App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        backgroundColor: Colors.blue,
        accentColor: Colors.deepPurple,
        accentColorBrightness: Brightness.dark,
        buttonTheme: ButtonTheme.of(context).copyWith(
          buttonColor: Colors.blue,
          textTheme: ButtonTextTheme.primary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20),
          ),
        ), //create a default buton theme
      ),

enter image description here

Upvotes: 0

Views: 90

Answers (1)

immadisairaj
immadisairaj

Reputation: 656

I try to put up the same code in dartpad and check if the code works. And, it works fine

DropdownButton(
  icon: Icon(Icons.more_vert,
             color: Theme.of(context).primaryIconTheme.color),
  items: [
    DropdownMenuItem(
      child: Container(
        child: Row(
          //mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            Icon(Icons.exit_to_app, color: Colors.black), // choose appropriate color
            SizedBox(
              width: 8,
            ),
            Text('Logout')
          ],
        ),
      ),
      value: 'logout',
    ),
  ],
  onChanged: (itemIdentifier) {
  },
),

dartpad output

Maybe you can check your theme data.

Also, try to do flutter clean and run again. It works most of the time.

Upvotes: 1

Related Questions