颤振:文本:将新行与上一行对齐(缩进)

时间:2018-08-31 07:55:56

标签: flutter newline indentation

基本上我的文字是这样的:

enter image description here

此文本是使用以下代码制作的:

child: Text(
            "1)    Persons with burns, skin infections\n2)    Primary or secondary immunodeficiencies (HIV)\n3)    Previous tuberculosis infection\n4)    Untreated active tuberculosis\n5)    History of close contact with tuberculosis patient\n6)    Immunosupressed individuals (i.e. HIV infected, leukemia, lymphoma, malignancy)\n7)    People receiving immunosuppressive medications (including high-dose steroids\n8)    Pregnancy",
          ),

我希望6)和7)中的第二行与文本开头对齐,而不与数字对齐。有什么办法可以扑扑吗?

我不想添加其他空格,因为它可能会随着不同的移动屏幕而改变。在其他情况下,它涉及多于2行。谢谢您的回答!

1 个答案:

答案 0 :(得分:5)

我假设您创建了这样的内容:

return new ListView(
  shrinkWrap: true,
  children: <Widget>[
   const Text('1) I\'m dedicating every day to you'),
   const Text('2) Domestic life was never quite my style'),
   const Text('3) When you smile, you knock me out, I fall apart'),
   const Text('4) And I thought I was so smart')
  ]
);

但是,您可以使用Row Widget来获得所需的结果:

return new ListView(shrinkWrap: true, children: <Widget>[
  new Row(children: <Widget>[
    Text('1) '),
    Expanded(child: Text('I\'m dedicating every day to you'))
  ], crossAxisAlignment: CrossAxisAlignment.start),
  new Row(children: <Widget>[
    Text('2) '),
    Expanded(child: Text('Domestic life was never quite my style'))
  ], crossAxisAlignment: CrossAxisAlignment.start),
  new Row(children: <Widget>[
    Text('3) '),
    Expanded(child: Text('When you smile, you knock me out, I fall apart blablabla'))
  ], crossAxisAlignment: CrossAxisAlignment.start),
  new Row(children: <Widget>[
    Text('4) '),
    Expanded(child: Text('And I thought I was so smart')),
  ], crossAxisAlignment: CrossAxisAlignment.start)
]);

当然有点丑陋,但是我希望它会为您指明正确的方向。

Screenshot