Flutter中如何修改TextField上下文菜单的样式?
Flutter上下文菜单样式修改问题及解决方案
我在Flutter应用里的上下文菜单样式效果很差,想要修改它的背景颜色和字体大小,但在ThemeData里配置cardTheme完全没效果,也找不到更多相关信息。
当前上下文菜单样式:
我尝试的无效代码:
return MaterialApp( title: 'Martin', theme: AppThemes.getLightTheme().copyWith( cardTheme: CardTheme( color: Colors.pink, surfaceTintColor: Colors.green, shadowColor: Colors.blue, ), ), initialRoute: RoutesList.splash, routes: getRoutes(), );
解决方案
已找到有效解决方案:修改上下文菜单样式需要在ThemeData中配置textButtonTheme字段。
示例代码:
textButtonTheme: TextButtonThemeData( style: TextButton.styleFrom( backgroundColor: Colors.white, foregroundColor: Colors.white, textStyle: customLightTextTheme.displaySmall ?.copyWith(color: Colors.black, fontSize: 16.sp), ), )
此方案已解决我的问题。
内容的提问来源于stack exchange,提问作者Martin Fenocchio
相关产品推荐
相关产品推荐

