如何设置PopupMenuDivider颜色的样式?

时间:2020-10-15 06:13:32

标签: flutter flutter-layout

在此简单的实现代码中,我向PopupMenuButton动作参数中添加了AppBar项,现在我想对具有默认颜色的PopupMenuDivider颜色进行样式设置。

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

ThemeData(
  child: const PopupMenuDivider(
    height: 10,
  ),
),

我的代码:

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),
)

1 个答案:

答案 0 :(得分:1)

DividerThemeDataMaterialApp包裹在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
        )
      ),
    );
  }
}