gpt4 book ai didi

dart - 使用 CheckBox 对齐文本

转载 作者:IT王子 更新时间:2023-10-29 07:14:09 26 4
gpt4 key购买 nike

我有下面的代码来显示带复选框的文本,我需要文本在最左边,复选框在最右边,我正确地得到了复选框,但文本已经如图所示对齐到它的一侧,我希望结果显示它们之间有很大的差距!

  var _valueC = false;
void onChecked(bool value) {
setState(() {
_valueC = value;
print('value: $value');
});
}

new Card(
child: new Container(
// height: 100.0,
child: new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
new Text("Agree"),
new Checkbox(value: _valueC,
onChanged: onChecked,
),
],
),
),
),

enter image description here

我有以下案例,它与我一起使用 Switch 及其使用 Kotlin 的文本完美地工作:

class Switchy : RelativeLayout {
constructor(context: Context) : super(context) {
init(context)
}

private fun init(context: Context) {
val colorOn = -0xcdc1ba

val trackStates = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf()),
intArrayOf(Color.LTGRAY, colorOn)
)

this.apply {
layoutParams = android.widget.RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)

addView(Switch(context).apply {
background = ContextCompat.getDrawable(context, R.drawable.card)
text = "active or not is it ?"
isChecked = true
showText = true
textOn = "Active"
textOff = "Not Active"
trackTintList = trackStates
thumbTintList = trackStates
}, LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT))
}
}
}

最佳答案

使用

mainAxisAlignment: MainAxisAlignment.spaceBetween,

代替

mainAxisAlignment: MainAxisAlignment.end,

关于dart - 使用 CheckBox 对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49815816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com