通常不需要负边距,但有些情况下它确实很有用.例如:为什么要使用负边距?
现在,当我将容器的边距设置为负值时,我收到以下错误:
I/flutter ( 3173): 'package:flutter/src/widgets/container.dart': Failed assertion: line 251: 'margin == null ||
I/flutter ( 3173): margin.isNonNegative': is not true.
Run Code Online (Sandbox Code Playgroud) 例如,我可能在当前的小部件树中有一个RichText,看起来像
new RichText(
text: new TextSpan(
text: 'Hello ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
new TextSpan(text: 'bold', style: new TextStyle(fontWeight: FontWeight.bold)),
new TextSpan(text: ' world!'),
],
),
)
Run Code Online (Sandbox Code Playgroud)
我尝试使用,find.text('Hello bold world!')但因为它不是文本,所以无法使用。
在android中,我们可以为文本视图设置最大行数,如下所示:
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="5" />
Run Code Online (Sandbox Code Playgroud)
但是在颤动中,我们可以通过添加最大高度限制来做到这一点,但是我们需要知道确切的高度是多少。
有什么方法可以轻松指定Text / RichText的最大行数?
flutter ×3