主应用程序屏幕没有这个问题,所有的文本显示他们应该。
然而,在新屏幕中,所有的文本部件下面都有一些奇怪的黄线/双线。
你知道为什么会这样吗?
主应用程序屏幕没有这个问题,所有的文本显示他们应该。
然而,在新屏幕中,所有的文本部件下面都有一些奇怪的黄线/双线。
你知道为什么会这样吗?
当前回答
您只需要添加Material根小部件。
@override
Widget build(BuildContext context) {
return Material(
child: new Container(),
);
}
其他回答
只是给这些答案加上了另一种方式。
将根小部件包装在DefaultTextStyle小部件周围。这里不需要修改每个Text小部件。
DefaultTextStyle(
style: TextStyle(decoration: TextDecoration.none),
child : Your_RootWidget
)
希望它能帮助到别人。
您所需要做的就是提供一个Material小部件,或者一个内部覆盖这个小部件的Scaffold。你可以通过以下方法做到这一点:
使用材料(简单且更好): 材料( 颜色:颜色。transparent, // <——如果需要,添加这个 孩子:文本(“你好”), ) 设置文本。样式属性: 文本( “你好”, style: TextStyle(decoration: TextDecoration.none), //设置 ) 提供支架: 支架(身体:文本('你好'))
修复使用英雄时黄色文本的问题:
就像aaronvargas提到的,当你在两边使用Hero时,你可以把你的child包在Material中。例如:
Hero(
tag: 'fooTag',
child: Material( // <--- Provide Material
type: MaterialType.transparency,
child: YourWidget(),
),
);
文本样式有一个可以设置为none的装饰参数
Text("My Text",
style: TextStyle(
decoration: TextDecoration.none,
)
);
另外,正如其他人提到的,如果你的文本小部件在脚手架或材料小部件的树中,你就不需要装饰文本样式了。
您只需要添加Material根小部件。
@override
Widget build(BuildContext context) {
return Material(
child: new Container(),
);
}
我推荐这种方法,因为你可以做一次,它将覆盖你的整个应用程序。
在MaterialApp的构建器下添加DefaultTextStyle,如下所示:
child: MaterialApp(
...
...
theme: yourThemeData,
builder: (context, child) => DefaultTextStyle(
style: yourThemeData.textTheme.bodyText1,
child: child,
),
),
通过这样做,我们不需要每次使用showDialog或Overlay时都指定样式或使用DefaultTextTheme。