Reputation: 479
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
),
Upvotes: 0
Views: 90
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) {
},
),
Maybe you can check your theme data.
Also, try to do flutter clean
and run again. It works most of the time.
Upvotes: 1