【发布时间】:2022-01-11 06:03:53
【问题描述】:
好吧,基本上我的复选框有这个问题,我实际上构建了一个 todolist 应用程序,所以我需要一个复选框小部件来检查您完成的所有活动。 但是有一个问题,当我想检查一个活动时,所有活动都同时检查。 我已经阅读了小部件颤动页面上的所有内容,但我不明白我可以在没有事先定义的情况下检查一个项目。 如果您能帮我解决这个问题,我将非常感激。
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
List todos = [];
String input = "";
@override
bool checkedValue = false;
void initState() {
super.initState();
todos.add("Item1");
todos.add("Item2");
todos.add("Item3");
todos.add("Item4");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("TASKS",style: TextStyle(
fontFamily: "BaksoSapi",
),),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
showDialog(context: context, builder: (BuildContext context){
return AlertDialog(
title: Text("Add Todolist !"),
content: TextField(
onChanged: (String value){
input = value;
},
),
actions: <Widget>[
FlatButton(onPressed: (){setState(() {
todos.add(input);
});
}, child: Text("Add"))
],
);
});
},
child: Icon(Icons.add,
color: Colors.white,
),
),
body: ListView.builder(
itemCount: todos.length,
itemBuilder:(BuildContext context,int index){
return Dismissible(key: Key(todos[index]),
child: Card(
elevation: 4,
margin: EdgeInsets.all(8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(8)
),
child: CheckboxListTile(
title: Text(todos[index]),
controlAffinity: ListTileControlAffinity.leading,
activeColor: Colors.redAccent,
value: checkedValue,onChanged: (newValue){
setState(() {
checkedValue = newValue!;
});
},
),
),);
},
)
);
【问题讨论】:
标签: android database firebase flutter dart