用这个代码
Center(
child: Text(
'hello 你好',
style: TextStyle(backgroundColor: Colors.red, fontSize: 24),
),
)
中国人的身高似乎会比英语高吗?我能让他们有一个相同的高度吗?
发布于 2021-09-03 02:56:37
不同的文本高度是由不同的字体系列造成的。
您会更改支持中文和英文的字体吗?
或者,如果您想使文本高度相同,下面是示例。
在文本中使用“strutStyle”参数,虽然不方便,但可以修改每个文本的高度是相同的。
https://medium.com/@najeira/control-text-height-using-strutstyle-4b9b5151668b https://github.com/flutter/flutter/issues/38875
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget _buildBody() {
return Column(
children: [
Center(
child: Text(
'hello 你好',
style: TextStyle(backgroundColor: Colors.red, fontSize: 24),
),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Text(
"hello",
style: TextStyle(
fontSize: 24,
),
strutStyle: StrutStyle(
height: 1.5,
fontSize: 24,
),
),
color: Colors.red,
),
Container(
child: Text(
"你好",
style: TextStyle(
fontSize: 24,
),
strutStyle: StrutStyle(
height: 1.5,
fontSize: 24,
),
),
color: Colors.red,
),
],
),
],
);
}
}
https://stackoverflow.com/questions/69038351
复制相似问题