- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个字符串列表:
List _choice = ["Europe","Asia","Africa"];
String answer = "Europe";
Widget build(BuildContext context) {
List<String> _choice = <String>["Europe","Asia","Africa"];
String answer = "Europe";
int NumberChoice = _choice.length;
//RaisedButtons
for (var i = 0; i < NumberChoice; i++)
new RaisedButton(
color: _colorButton,
child: new Text(
_choice[i],
style: new TextStyle(
fontSize: 20.0, color: Colors.white),
),
onPressed: () {
setState(() {
if (_choice[i] == answer) {
print("--------------- Corect ----------------");
_colorButton = Colors.greenAccent;
scoreResult = 1;
} else {
print("--------------- False ------------------------");
_colorButton = Colors.redAccent;
scoreResult = 0;
}
});
},
),
最佳答案
我终于解决了你的案子这需要大量的努力,但最后,我们就在那里。
我所做的是,我按了并按了一下按钮,就重新构建了小部件,并更改了RaisedButton()的颜色键本身的颜色
我知道这听起来会有些复杂,但是在研究了解决方案之后,您将得到它。
在转向解决方案之前,这里是演示。默认情况下,按钮是粉红色的,一旦我按下任何按钮,结果就会显示出来,错误答案=红色,右边=绿色
class RadioButtonPage extends StatefulWidget {
@override
RadioButtonPageState createState() => RadioButtonPageState();
}
class RadioButtonPageState extends State<RadioButtonPage> {
List<String> _choice = ["Europe","Asia","Africa"];
String answer = "Europe";
var score;
//this bool does the real magic since you want the result to be seen on the press of the button, so here you go, this keeps track of the pressed button whether it is pressed once or not
bool isPressedOnce = false;
List<Widget> getButtons(){
List<Widget> _listWidget = [];
for(int i=0; i< _choice.length; i++){
_listWidget.add(
RaisedButton(
//Everytime it builds up, it will work according to this situation, hence works
color: isPressedOnce ? (_choice[i] == answer ? Colors.greenAccent : Colors.red) : Colors.pink,
child: Text(_choice[i]),
onPressed: (){
//Changes the state of bool to true, since any button is pressed
setState(() {
this.isPressedOnce = true;
if(_choice[i] == this.answer) score = 1;
else score = 0;
});
//Rebuilding the widget again, and now with the current condition I have put on that color key, it will finally work as per the requirements
this.getButtons();
}
)
);
}
return _listWidget;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Welcome'),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: this.getButtons()
)
)
);
}
}
关于flutter - 如何更改独特的RaisedButton的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57843157/
我正在构建我的第一个应用程序来计算我工作所需的值。 我已经在 Python 中进行了这项工作,但这确实不同。 我有一个 textformfield,我在其中输入了“我需要的数据”。 成功后,我从“on
如何将图标添加到右侧的 RaisedButton Padding( padding: const EdgeInsets.only(top: 15.0), child:
我正在使用 firebase_auth 在 flutter 中创建一个应用。 我有一个用于 View 的“登录”类和用于按钮和输入的其他“元素”类。我试图在 Elements 类的一个按钮上的 Log
tl;dr 当我没有明确设置任何按钮时,为什么两个按钮之间会出现空格? 我正在尝试制作如下所示的布局: 但是,两个按钮之间出现了大约 16px 的空间,我不知道它是从哪里来的。 我起初以为 Colum
所以我试图移除 raisedButton 的底部边距,这样它看起来就好像与它下面的卡片合并了一样。这是它的样子 这是我的代码 Expanded( child: Card(
Flutter 按钮似乎都没有提供更改按钮矩形角半径的方法。有一个形状属性,但我不知道如何使用它。 最佳答案 您可以从 shape 属性更改半径,并给它一个 RoundedRectangleBorde
RaisedButton( onPressed: null, child: Text('Get in'), // change it to sign-in
我尝试从 themeData 更改我所有 RaisedButtons 的颜色,但它拒绝工作。所有其他属性,例如 fontSize 和 fontWeight 已成功更改。仅当 themeData 的亮度
我希望能够在将对象作为参数传递时按下按钮导航到另一个屏幕。该对象是使用不同 dart 文件中的 getPlayer() 函数创建的;因此,异步功能。每当我运行代码时,我都会收到错误: 错误:此表达式的
我读到的所有内容都表明您可以使用 SetState 完成这项工作。这是我一直在使用的,它不会重绘。 class ServerSelectionState extends State { bool
我很乐意从 RaisedButton 调用 Future fetchPost 或者换句话说,我不希望 FutureBuilder 在我点击按钮之前做任何事情,我尝试从按钮调用 fetchPost 但它
我的应用程序中有一个 TextField,紧接着是一个 RaisedButton。 当我输入 TextField 时,按钮会向上移动到键盘上方。如果我在 TextField 中一直向下滚动,我可以看到
我在一个列内有一个 RaisedButton,它在一个堆栈内 Stack( children: [ PageView( children: [...],
我正在尝试切换凸起按钮的颜色。最初按钮应该是蓝色的,当它被按下时它会变成灰色。现在我有一个名为 pressAttention 的 bool 值,它被设置为 false。我正在使用它来最初将其设置为 f
如何使 RaisedButton 成为选中状态,就像切换按钮选中状态一样? 如何使 RaisedButton 不占用额外的宽度,即虾皮包裹标签文本。 最佳答案 我相信我已经设法在不使用 RaisedB
对于上下文:https://dartpad.dev/c9689b40a5402e12538c726b5c0380ff 我有一个 GestureDetector(具有一些特定的业务逻辑),它监听单击并有
我有一个通用的按钮小部件,它将图标值作为构造函数。有时我希望小部件没有可见的图标。我如何将该逻辑放在看起来像这样的小部件中? const SocialAuthBtn({this.action, thi
我正在尝试使用 backgroundColor: '#fb933c' 使用内联样式自定义来更改 material-ui RaisedButton 的颜色,但它仍然显示默认颜色。 最佳答案 您可以使用内
我一直在尝试通过单击 RaisedButton 为 RadioListTile 提供背景颜色,并创建一个函数将该颜色分配给 RadioListTile包含特定的 value,例如 value: 2。我
我正在构建一个测验应用程序,它会在用户提交他们选择的答案后显示对正确答案的解释。 布局上有两个按钮——“下一个问题”和“提交答案”。 在初始状态下,“下一个问题”按钮很微妙,因为它不可点击,只有“提交
我是一名优秀的程序员,十分优秀!