Flutter 选中时,颤振中的checkboxlisttile未显示勾号
我在listview生成器中使用了checkboxlisttile。问题是,即使我点击它,也并没有记号。但当我打印值时,它会显示true。当我再次单击它时,它仍然为真(不是假),但没有勾号。 实际上,我正在动态创建列表。我有一个屏幕new_note.dart,我在note表的数据库中保存了一个note。保存的节点显示在此列表中所有选项卡下的note_info.dart中。在“已完成”选项卡中,我想显示已完成的注释,即将标记为选中的注释。我在TabBarView的容器中调用这个方法getNotecheckListFlutter 选中时,颤振中的checkboxlisttile未显示勾号,flutter,android-studio,Flutter,Android Studio,我在listview生成器中使用了checkboxlisttile。问题是,即使我点击它,也并没有记号。但当我打印值时,它会显示true。当我再次单击它时,它仍然为真(不是假),但没有勾号。 实际上,我正在动态创建列表。我有一个屏幕new_note.dart,我在note表的数据库中保存了一个note。保存的节点显示在此列表中所有选项卡下的note_info.dart中。在“已完成”选项卡中,我想显示已完成的注释,即将标记为选中的注释。我在TabBarView的容器中调用这个方法getNotec
ListView getNotecheckList() {
bool _isChecked=false;
return ListView.builder(
itemCount: count,
itemBuilder: (BuildContext context, int position) {
return Card(
color: Colors.white,
elevation: 2.0,
child: CheckboxListTile(
title: Text(this.noteList[position].note),
subtitle: Text(this.noteList[position].actn_on),
//secondary: const Icon(Icons.web),
value:_isChecked,
onChanged: (bool value) {
setState(() {
_isChecked=value;
});
},
controlAffinity: ListTileControlAffinity.leading,
),
);
},);}
我的代码中的所有内容似乎都是正确的。那是什么错误呢。
我甚至试过
_isChecked=_检查
注_info.dart
import 'dart:io';
import 'package:vers2cts/models/note_model.dart';
import 'package:vers2cts/models/customer_model.dart';
import 'package:vers2cts/services/db_service.dart';
import 'package:vers2cts/utils/db_helper.dart';
import 'package:flutter/material.dart';
import 'package:sqflite/sqflite.dart';
import 'new_note.dart';
class Note_Info extends StatefulWidget{
final String appBarTitle;
final CustomerModel customer;
Note_Info(this. customer, this.appBarTitle);
@override
State<StatefulWidget> createState() {
return Note_InfoState(this. customer,this.appBarTitle);
}
}
class Note_InfoState extends State<Note_Info> {
DBService dbService = DBService();
List<NoteModel> noteList;
int count = 0;
static final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
NoteModel note=NoteModel();
String appBarTitle;
CustomerModel customer=new CustomerModel();
Note_InfoState(this.customer, this.appBarTitle);
bool rememberMe = false;
DateTime _date = DateTime.now();
TextEditingController custfNameController = TextEditingController();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
updateListView();
if (noteList == null) {
noteList = List<NoteModel>();
updateListView();
}
TextStyle titleStyle = Theme.of(context).textTheme.subhead;
var height = MediaQuery.of(context).size.height;
var name=customer.first_name+" "+customer.last_name;
custfNameController.text = name;
return DefaultTabController(
length: 4,
child: Scaffold(
appBar: AppBar(
actions: [
IconButton(
icon: Icon(
Icons.add,
),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => NewNote(customer,note)));
},
)
],
),
body: Container(
child: Column(
children: <Widget>[
TextField(controller: custfNameController,
style: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.bold),
textAlign: TextAlign.center),
Padding(
padding: const EdgeInsets.all(15.0),
child: Row(children: [
ImageProfile(customer.cust_photo),
Padding(
padding: const EdgeInsets.only(left: 30.0),
child: IconButton(
icon: Icon(
Icons.call,
color: Colors.green,
size: 45,
),
onPressed: () {
},
),
),
],),
),
SizedBox(
height: 50,
child: AppBar(
bottom: TabBar(
tabs: [
Tab(
text: "All",
),
Tab(
text: "Pending",
),
Tab(
text: "Cancelled",
),
Tab(
text: "Completed",
),
],
),
),
),
// create widgets for each tab bar here
Expanded(
child: TabBarView(
children: [
// first tab bar view widget
Container(
child: getNotecheckList()
),
// second tab bar viiew widget
Container(
),
Container(
child: Center(
child: Text(
'Cancelled',
),
),
),
Container(
child: Center(
child: Text(
'Completed',
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 55.0,
width: 200,
child: RaisedButton(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
color: Theme
.of(context)
.primaryColorDark,
textColor: Colors.white,
child: Text('Save', textScaleFactor: 1.5,),
onPressed: () {
setState(() {
//_reset();
});
},
),
),
),
]
),
)
));
}
Widget ImageProfile(String fileName) {
return Center(
child: CircleAvatar(
radius: 80.0,
backgroundImage: fileName == null
?AssetImage('images/person_icon.jpg')
:FileImage(File(customer.cust_photo))),
);
}
Future<void> updateListView() {
final Future<Database> dbFuture = DB.init();
dbFuture.then((database) {
int cid=customer.cust_id;
Future<List<NoteModel>> noteListFuture = dbService.getCustomerNotes(cid);
noteListFuture.then((noteList) {
setState(() {
this.noteList = noteList;
this.count = noteList.length;
});
});
});
}
ListView getNotecheckList() {
return ListView.builder(
itemCount: count,
itemBuilder: (BuildContext context, int position) {
int _isChecked = -1;
return Card(
color: Colors.white,
elevation: 2.0,
child: CheckboxListTile(
title: Text(this.noteList[position].note),
subtitle: Text(this.noteList[position].actn_on),
//secondary: const Icon(Icons.web),
value: _isChecked,
onChanged: (bool value) {
setState(() {
_isChecked = value;
});
},
controlAffinity: ListTileControlAffinity.leading,
});
},
),
);
},
);
}
}
导入'dart:io';
导入“包装:vers2cts/models/note_model.dart”;
导入“包装:vers2cts/models/customer_model.dart”;
导入“包:vers2cts/services/db_service.dart”;
导入“package:vers2cts/utils/db_helper.dart”;
进口“包装:颤振/材料.省道”;
导入“包:sqflite/sqflite.dart”;
导入“new_note.dart”;
类注释\u信息扩展StatefulWidget{
最终字符串appBarTitle;
最终客户模型客户;
注释信息(this.customer,this.appBarTitle);
@凌驾
状态createState(){
返回注释_InfoState(this.customer,this.appBarTitle);
}
}
类注释\u InfoState扩展状态{
DBService DBService=DBService();
列表注释列表;
整数计数=0;
静态最终GlobalKey脚手架键=新的GlobalKey();
NoteModel note=NoteModel();
字符串appBarTitle;
CustomerModel customer=新CustomerModel();
注意:InfoState(this.customer,this.appBarTitle);
bool rememberMe=false;
DateTime _date=DateTime.now();
TextEditingController custfNameController=TextEditingController();
@凌驾
void initState(){
super.initState();
}
@凌驾
小部件构建(构建上下文){
updateListView();
如果(noteList==null){
noteList=List();
updateListView();
}
TextStyle titleStyle=Theme.of(context).textTheme.subhead;
var height=MediaQuery.of(context).size.height;
变量名称=客户。名字+“”+客户。姓氏;
custfNameController.text=名称;
返回DefaultTabController(
长度:4,
孩子:脚手架(
appBar:appBar(
行动:[
图标按钮(
图标:图标(
Icons.add,
),
已按下:(){
导航器.of(上下文).push(MaterialPageRoute(
生成器:(BuildContext上下文)=>NewNote(客户,注释));
},
)
],
),
主体:容器(
子:列(
儿童:[
TextField(控制器:custfNameController,
样式:TextStyle(
fontSize:20.0,fontWeight:fontWeight.bold),
textAlign:textAlign.center),
填充物(
填充:常数边集全部(15.0),
子对象:行(子对象:[
ImageProfile(客户照片),
填充物(
填充:仅限常量边集(左:30.0),
孩子:我的钮扣(
图标:图标(
图标。呼叫,
颜色:颜色。绿色,
尺码:45,
),
已按下:(){
},
),
),
],),
),
大小盒子(
身高:50,
孩子:AppBar(
底部:选项卡栏(
选项卡:[
标签(
文本:“全部”,
),
标签(
文本:“待定”,
),
标签(
文字:“已取消”,
),
标签(
正文:“已完成”,
),
],
),
),
),
//在此处为每个选项卡栏创建小部件
扩大(
子项:选项卡视图(
儿童:[
//第一个选项卡栏视图小部件
容器(
孩子:getNotecheckList()
),
//第二个选项卡栏视图小部件
容器(
),
容器(
儿童:中心(
子:文本(
“取消”,
),
),
),
容器(
儿童:中心(
子:文本(
"完成",,
),
),
),
],
),
),
填充物(
填充:常数边集全部(8.0),
子:容器(
身高:55.0,
宽度:200,
孩子:升起按钮(
标高:2,
形状:圆形
....
bool _isChecked=false;
@override
Widget build(BuildContext context) {
......
}
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
int _isChecked = -1;
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: 10,
itemBuilder: (BuildContext context, int position) {
return Card(
color: Colors.white,
elevation: 2.0,
child: CheckboxListTile(
title: Text("hi"),
subtitle: Text("this.noteList[position].actn_on"),
//secondary: const Icon(Icons.web),
value: position== _isChecked,
onChanged: (bool value) {
setState(() {
_isChecked = value?position:-1;
});
},
controlAffinity: ListTileControlAffinity.leading,
),
);
},
);
}
}