gpt4 book ai didi

android - 如何在 flutter 中禁用 RadioListTile 小部件

转载 作者:行者123 更新时间:2023-12-04 12:20:30 29 4
gpt4 key购买 nike

我正在使用 RadioListTile我的应用程序中的小部件,我想在满足某些条件后禁用更改值。并且没有isButtonDisabled就像 Radio 中的 Prop 小部件。如何禁用此小部件(阻止值更改)?
当我写上面的声明时,我想通了,这很容易。
所以生病发布问题并将在下面回答。

import 'package:flutter/material.dart';

class Body extends StatefulWidget {
@override
_BodyState createState() => _BodyState();
}

class _BodyState extends State<Body> {
bool evaluate = false;
int value;

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
RadioListTile<int>(
value: 0,
isThreeLine: false,
title: Text(
'radio 1',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
groupValue: value,
onChanged: (value) => evaluate ? null : value = 0,
activeColor: Colors.green,
),
RadioListTile<int>(
value: 1,
isThreeLine: false,
title: Text(
'radio 2',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
groupValue: value,
onChanged: (value) => evaluate ? null : value = 1,
activeColor: Colors.green,
),
InkWell(
onTap: () {
evaluate = true;
},
child: Container(
child: Center(
child: Text(
'Submit answer',
),
),
),
)
],
);
}
}

最佳答案

每当onChange为 null 组件将被禁用。你应该能够做一些链接这个而不是:

onChanged: evaluate ? null : (value) => value = 0,
我还要重命名 evaluate为了更容易理解,例如 alreadyProvided , notAllowed , disabled或者任何有意义的事情,最重要的是真正代表它为什么不能改变。
最后它可能看起来像:
onChanged: alreadyProvided ? null : (value) => value = 0,

关于android - 如何在 flutter 中禁用 RadioListTile 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65559905/

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