我有一个使用复选框和下拉菜单的应用程序屏幕。但是,我意识到我已将其编码在 StatelessWidget 中,因此在选择选项时无法更改状态。我如何让这个工作,以便当一个复选框被选中时,它会显示为被“选中”而不是空的?
我曾尝试将我的代码粘贴到有状态小部件中,但是一直遇到错误,因为我不完全确定哪些部分应该放在何处。
import 'package:carve_brace_app/model/activity.dart';
import 'package:flutter/material.dart';
class DetailPage extends StatelessWidget {
final Activity activity;
DetailPage({Key key, this.activity}) : super(key: key);
@override
Widget build(BuildContext context) {
final levelIndicator = Container(
child: Container(
child: LinearProgressIndicator(
backgroundColor: Color.fromRGBO(209, 224, 224, 0.2),
value: 2.0,
valueColor: AlwaysStoppedAnimation(Colors.green)),
),
);
final topContentText = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 120.0),
Container(
width: 90.0,
child: new Divider(color: Colors.green),
),
SizedBox(height: 10.0),
Text(
activity.activityName,
style: TextStyle(color: Colors.white, fontSize: 45.0),
),
SizedBox(height: 30.0),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: …Run Code Online (Sandbox Code Playgroud) 使用此方法使用调用方法 getRandomInt 中的随机值生成 ArrayList。我会断言什么来创建一个测试方法来测试 ArrayList 不包含重复项?
public static int getRandom(int min, int max) {
return random.nextInt((max - min) + 1) + min;
}
public static ArrayList<Integer> getRandomIntegers(int size, int min, int max) {
ArrayList<Integer> number = new ArrayList<Integer>();
while (number.size() < size) {
int random = getRandom(min, max);
if(!number.contains(random)) {
number.add(random);
}
}
return number;
}
Run Code Online (Sandbox Code Playgroud) 如何在 flutter 中向卡片添加新列?
目前,我有 2 列,但不知道如何在它们之间添加第三列,因为它们位于左侧和右侧。当我尝试添加“新列”时,它只会在第一列下创建一行新文本。
到目前为止,这是我的代码:
Widget _buildListItem(BuildContext context, Record record) {
return Card(
key: ValueKey(record.activityName),
elevation: 8.0,
margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
child: Container(
decoration: BoxDecoration(color: Color.fromRGBO(64, 75, 96, .9)),
child: ListTile(
contentPadding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
title: Text(
record.activityName,
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 23),
),
subtitle: Row(
children: <Widget>[
new Flexible(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
RichText(
text: TextSpan(
text: "Activations: "+record.activations+
"\n"+record.dateCompleted,
style: TextStyle(color: Colors.white),
),
maxLines: 2,
softWrap: true,
) …Run Code Online (Sandbox Code Playgroud) 我有一个秒表,想要一个可以暂停和启动它的按钮。我正在努力解决这个问题的逻辑。打印到控制台时,布尔值停留在 false 上,并且不允许我重新单击该按钮。
秒表.dart:
class NewStopWatch extends StatefulWidget {
@override
_NewStopWatchState createState() => new _NewStopWatchState();
}
class _NewStopWatchState extends State<NewStopWatch> {
Stopwatch watch = new Stopwatch();
Timer timer;
bool startStop = true;
String elapsedTime = '';
updateTime(Timer timer) {
if (watch.isRunning) {
setState(() {
startStop = false;
print("startstop Inside=$startStop");
elapsedTime = transformMilliSeconds(watch.elapsedMilliseconds);
});
}
}
@override
Widget build(BuildContext context) {
return new Container(
padding: EdgeInsets.all(20.0),
child: new Column(
children: <Widget>[
new Text(elapsedTime, style: new TextStyle(fontSize: 25.0)),
SizedBox(height: 20.0),
new Row( …Run Code Online (Sandbox Code Playgroud)