主应用程序屏幕没有这个问题,所有的文本显示他们应该。
然而,在新屏幕中,所有的文本部件下面都有一些奇怪的黄线/双线。
你知道为什么会这样吗?
主应用程序屏幕没有这个问题,所有的文本显示他们应该。
然而,在新屏幕中,所有的文本部件下面都有一些奇怪的黄线/双线。
你知道为什么会这样吗?
当前回答
之前
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Text(
"21:34",
style: TextStyle(fontSize: 50),
),
),
Center(
child: Text(
"Wakey - wakey",
style: TextStyle(fontSize: 20),
),
)
],
);
}
后(解决方案):
这里用脚手架小部件包装当前顶部或父小部件
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Text(
"21:34",
style: TextStyle(fontSize: 50),
),
),
Center(
child: Text(
"Wakey - wakey",
style: TextStyle(fontSize: 20),
),
)
],
),
);
}
完整代码:Dartpad或Live代码
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: sta()));
class sta extends StatefulWidget {
const sta({Key? key}) : super(key: key);
@override
State<sta> createState() => _staState();
}
var isShow = false;
class _staState extends State<sta> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Text(
"21:34",
style: TextStyle(fontSize: 50),
),
),
Center(
child: Text(
"Wakey - wakey",
style: TextStyle(fontSize: 20),
),
)
],
),
);
}
}
其他回答
之前
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Text(
"21:34",
style: TextStyle(fontSize: 50),
),
),
Center(
child: Text(
"Wakey - wakey",
style: TextStyle(fontSize: 20),
),
)
],
);
}
后(解决方案):
这里用脚手架小部件包装当前顶部或父小部件
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Text(
"21:34",
style: TextStyle(fontSize: 50),
),
),
Center(
child: Text(
"Wakey - wakey",
style: TextStyle(fontSize: 20),
),
)
],
),
);
}
完整代码:Dartpad或Live代码
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: sta()));
class sta extends StatefulWidget {
const sta({Key? key}) : super(key: key);
@override
State<sta> createState() => _staState();
}
var isShow = false;
class _staState extends State<sta> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Text(
"21:34",
style: TextStyle(fontSize: 50),
),
),
Center(
child: Text(
"Wakey - wakey",
style: TextStyle(fontSize: 20),
),
)
],
),
);
}
}
文本样式有一个可以设置为none的装饰参数
Text("My Text",
style: TextStyle(
decoration: TextDecoration.none,
)
);
另外,正如其他人提到的,如果你的文本小部件在脚手架或材料小部件的树中,你就不需要装饰文本样式了。
你也可以使用装饰:TextDecoration。无删除下划线
你也可以把你的脚手架作为你的MaterialApp的家。这对我很管用。
return MaterialApp(
home: Scaffold(
body: Container(
child: SingleChildScrollView(child: Text('Test')),
),
),
);
使用DefaultTextStyle()小部件设置文本的文本样式。
DefaultTextStyle(
style: kTempTextStyle,
child: Text('Hello world'),
)
你可以给你自己的文本样式,因为你想。
const kTempTextStyle = TextStyle(
fontFamily: 'Spartan MB',
fontSize: 100.0,
decoration: null,
);