Home > Enterprise >  How to set divider and divider color with PopupMenu Item in flutter?
How to set divider and divider color with PopupMenu Item in flutter?

Time:09-23

in this simple implementation code i added some PopupMenuButton items into AppBar actions argument and now i want to styling PopupMenuDivider color which that have default color.

CodePudding user response:

You can use PopupMenuItem child and assign Column like

 PopupMenuItem<WhyFarther>(
              value: WhyFarther.harder,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('Working a lot harder'),
                  Divider(
                    color: Colors.grey,
                  )
                ],
              ),
            ),

CodePudding user response:

You can do this very easily using the Theme class, using which you can change the icon color, text color and PopupMenuDivider color.

Again, you can easily do this on Divider at PopupMenuItem using PopupMenuDivider.

appBar: AppBar(
    title: Text("PopUpMenu Flutter"),
    centerTitle: true,
    actions: [
      Theme(
        data: Theme.of(context).copyWith(
          dividerTheme: DividerThemeData(
            color: Colors.black,
          ),
          iconTheme: IconThemeData(color: Colors.white),
          textTheme: TextTheme().apply(bodyColor: Colors.white),
        ),
        child: PopupMenuButton<int>(
          color: Colors.indigo,
          //onSelected: (item) => onSelected(context, item),
          itemBuilder: (context) => [
            PopupMenuItem<int>(
              value: 0,
              child: Text('Settings'),
            ),
            PopupMenuDivider(),
            PopupMenuItem<int>(
              value: 1,
              child: Text('Share'),
            ),
            PopupMenuDivider(),
            PopupMenuItem<int>(
              value: 2,
              child: Row(
                children: [
                  Icon(Icons.logout),
                  const SizedBox(width: 8),
                  Text('Sign Out'),
                ],
              ),
            ),
          ],
        ),
      ),
    ],
  ),
  • Related