我想在同一行上有 2 个文本,一个左对齐,另一个右对齐。
这两个文本都在一个Flexible
小部件内,并且overflow
可以在用户调整屏幕大小的情况下进行选择(这是一个颤动的 Web 项目)。
到目前为止,这是我的代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Text(
'First text looong looooooooooooooooooong looooooooooooooooooooooooooooong',
overflow: TextOverflow.fade,
),
),
Flexible(
child: Text(
'Second text',
overflow: TextOverflow.fade,
),
),
],
),
),
),
),
);
}
}
问题是使用灵活的文本,即使其他文本非常小并且实际上有足够的空间容纳第一个文本,文本也只占据屏幕最大值的 50%:
我想要的是让文本随心所欲地增长,只要它们之间有一些空间。但是如果文本太长而不能放在同一行,它们都应该是宽度的 50%:
------------------------------------------------------
|Short first text Short second text|
------------------------------------------------------
------------------------------------------------------
|Looooooooooooooooong first text Short second text| // <- First text is more than 50% of the width
------------------------------------------------------
------------------------------------------------------
|Very looooooooooooooooong first... Short second text| // <- First text is more than 50% of the width and overflows
------------------------------------------------------
------------------------------------------------------
|Short first text Loooooooooooooooooong second text| // <- Second text is more than 50% of the width
------------------------------------------------------
------------------------------------------------------
|Short first text Very looooooooooooooooong second...| // <- Second text is more than 50% of the width and overflows
------------------------------------------------------
------------------------------------------------------
|Looooooooooooong first... Looooooooooooong second...| // <- First and Second texts are 50% of the width
------------------------------------------------------
我怎样才能做到这一点?