使用时更改主题属性

Changing theme attribute when usage

我创造了popupMenuTheme。我需要使用它两次。第一个是典型的主题,第二个有点fontWeight的区别,所以我需要继承除fontWeight属性之外的所有属性,但是当我这样做时,弹出菜单转换为白色容器。

主题代码:

 popupMenuTheme: theme.popupMenuTheme.copyWith(
                color: const Color(pagesBackgroundColor),
                elevation: 3,
                textStyle: TextStyle(
                  color: const Color(accentColor),
                  fontFamily:
                      Localizations.localeOf(context).languageCode == 'ar'
                          ? 'almasry'
                          : 'patrick',
                  fontSize: 3.5.h,
                  fontWeight: FontWeight.w700,
                ),
              ),

更新主题代码:

Theme(
  data: Theme.of(context).copyWith(
    popupMenuTheme:const PopupMenuThemeData(
      textStyle: TextStyle(
    fontWeight: FontWeight.w900,
  ))),
  child: PopupMenuButton(
    itemBuilder: (context) => const [
      PopupMenuItem(child: Text("update")),
      PopupMenuItem(child: Text("delete")),
    ],
    icon: const Icon(
      Icons.more_vert,
      color: Color(accentColor),
    ),
  ),
),

您可以像下面这样使用它

Theme(
  data: Theme.of(context).copyWith(
    popupMenuTheme: PopupMenuTheme.of(context).copyWith(
      textStyle: PopupMenuTheme.of(context).textStyle.copyWith(
            fontWeight: FontWeight.bold,
          ),
    ),
  ),
  child: PopupMenuButton(
    itemBuilder: (context) => const [
      PopupMenuItem(child: Text("update")),
      PopupMenuItem(child: Text("delete")),
    ],
    icon: const Icon(
      Icons.more_vert,
      color: Color(accentColor),
    ),
  ),
),