如何设置 PopupMenuDivider 颜色样式?

Dol*_*rma 1 flutter flutter-layout

在这个简单的实现代码中,我在 actions 参数PopupMenuButton中添加了一些项目AppBar,现在我想要设置PopupMenuDivider具有默认颜色的样式颜色。

我尝试使用ThemeData但出现错误:

ThemeData(
  child: const PopupMenuDivider(
    height: 10,
  ),
),
Run Code Online (Sandbox Code Playgroud)

我的代码:

PopupMenuButton<int>(
  onSelected: null,
  icon: const Icon(Icons.more_vert),
  color: const Color(0xFF32313C).withOpacity(0.9),
  elevation: 8.0,
  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
  itemBuilder: (context) {
    final list = <PopupMenuEntry<int>>[];
    list.add(
      PopupMenuItem(
        child: Row(
          children: [
            Icon(Icons.add, color: Colors.white),
            Text(
              "InduceSmile.com",
              style: TextStyle(color: Colors.white),
            ).pl(16.0),
          ],
        ),
      ),
    );
    list.add(
      const PopupMenuDivider(
        height: 10,
      ),
    );
    return list;
  },
offset: Offset(0, 100),
)
Run Code Online (Sandbox Code Playgroud)

Cop*_*oad 6

将您的DividerThemeData内部包裹MaterialApp起来ThemeData并设置dividerColor您选择的。

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
        dividerTheme: DividerThemeData( 
          color: Colors.black
        )
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)