This is my card

每当选中时,我都会突出显示此卡的边框,这样用户就会看到特定的卡已被选中.

推荐答案

试试这个!

结果是: demo

"守则":

import 'package:flutter/material.dart';

void main() => runApp(
      new MaterialApp(
        home: new MyApp(),
      ),
    );

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("NonstopIO"),
      ),
      body: new ListView.builder(
        itemCount: 5,
        itemBuilder: (BuildContext context, int index) {
          return new MyCustomWidget(
            title: "Title $index",
            subtitle: "$index",
          );
        },
      ),
    );
  }
}

class MyCustomWidget extends StatefulWidget {
  final String title;
  final String subtitle;

  const MyCustomWidget({Key key, this.title, this.subtitle}) : super(key: key);

  @override
  _MyCustomWidgetState createState() => _MyCustomWidgetState();
}

class _MyCustomWidgetState extends State<MyCustomWidget> {
  bool selected = false;

  @override
  Widget build(BuildContext context) {
    return new Card(
      shape: selected
          ? new RoundedRectangleBorder(
              side: new BorderSide(color: Colors.blue, width: 2.0),
              borderRadius: BorderRadius.circular(4.0))
          : new RoundedRectangleBorder(
              side: new BorderSide(color: Colors.white, width: 2.0),
              borderRadius: BorderRadius.circular(4.0)),
      child: new Padding(
        padding: const EdgeInsets.all(4.0),
        child: new Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            new Text(widget.title),
            new Text(widget.subtitle),
            new Checkbox(
                value: selected,
                onChanged: (value) {
                  setState(() {
                    selected = value;
                  });
                })
          ],
        ),
      ),
    );
  }
}

Dart相关问答推荐

DART列表由以奇怪方式链接的列表(即二维数组)组成

如何在flutter中加载数据之前显示进度对话框?

dart 中 call() 的实现是什么?

我需要在使用之前将我的 Dart 包发布到 pub.dartlang.org 吗?

从列表中删除项目后更新 UI

自定义声音推送通知不起作用

Flutter热重新加载和热重启不工作

Flutter 如何移动文件

如何在仍然引用来自 pub.dartlang.org 的包的同时运行私有 pub 服务器?

Flutter 从asset文件夹中读取所有文件

Flutter-在屏幕上绘制图形

为什么这个文件会自动创建自己 generate_plugin_registrant.dart

如何在 URL 中获取查询参数

Dart 工厂构造函数 - 它与const构造函数有何不同

如何创建类型别名

Dart:如何判断变量类型是否为字符串

我如何知道 websockets 的连接是否有效?

Cancel stream onData

如何在 Dart 中为 Completer.CompleteException(exception, stackTrace) 获取当前堆栈跟踪;

如何在 Dart 中将 double 转换为 int?