flutter - 在颤动中使用 AlertDialog 从数据库中显示选定的数据
问题描述
嗨,我正在尝试使用警报对话框显示数据库中的特定或选定数据,但是我想显示的数据不会显示到 alertDialog,因为我为我的数据库使用 floor 的方式是我非常感谢任何建议或想法.
这是我的代码
Widget buildAboutDialog(BuildContext context,
AddContactCallback _contactscreen, bool isEdit, ContactObject _contactObject) {
final databases = $FloorContactDatabase.databaseBuilder('Contacts.cb').build();
if(contactObject != null) {
this.contactObject = _contactObject;
tfirstname.text = _contactObject.firstname;
tlastname.text = _contactObject.lastname;
tbirthday.text = _contactObject.birthday;
tcontactnumber = _contactObject.contactnumber as TextEditingController ;
tprofilepicture = _contactObject.profilepicture as File;
} else {
print('ERROR');
print(tfirstname.value);
}
return new AlertDialog(
title: new Text(isEdit ? 'Contact!' : 'Contact'),
content: new SingleChildScrollView(
child: new Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10.0,
),
Align(
alignment: Alignment.center,
child: CircleAvatar(
radius: 70,
backgroundColor: Color(0xff476cfb),
child: ClipOval(
child: new SizedBox(
width: 180.0,
height: 180.0,
child: (_image != null) ? Image.file(_image, // Image.file(File('${_contactsDao.profilepicture}'),
fit: BoxFit.fill,
) : Image.network(
"https://images.unsplash.com/photo-1502164980785-f8aa41d53611?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60",
fit: BoxFit.fill,
),
),
),
),
),
getTextFieled("First Name", tfirstname),
getTextFieled("Last Name", tlastname),
getTextFieled("Birth day", tbirthday),
getTextFieled("Contact No", tcontactnumber),
],
),
),
);
}
这是函数和实例
Widget getTextFieled(
String inputData, TextEditingController inputTextController) {
var btm = new Padding(
padding: const EdgeInsets.all(5.0),
child: new TextFormField(
controller: inputTextController,
decoration: new InputDecoration(
hintText: inputData,
),
),
);
return btm;
}
Widget getAppButton (String buttonLabel, EdgeInsets margin){
var btm = new Container(
margin: margin,
padding: EdgeInsets.all(8.0),
alignment: FractionalOffset.center,
decoration: new BoxDecoration(
border: Border.all(color: const Color(0xFF28324E)),
borderRadius: new BorderRadius.all(const Radius.circular(6.0)),
),
child: new Text(
buttonLabel,
style: new TextStyle(
color: const Color(0xFF28324E),
fontSize: 20.0,
fontWeight: FontWeight.w300,
letterSpacing: 0.3,
),
),
);
return btm;
}
ContactObject getdata(bool isEdit) {
return new ContactObject(
firstname: tfirstname.text,
lastname: tfirstname.text,
birthday: tbirthday.text,
contactnumber: int.parse(tcontactnumber.text),
profilepicture: tprofilepicture.readAsStringSync(),
);
}
onTap(bool isEdit, AddContactCallback addContactCallback, BuildContext context) {
if(isEdit) {
addContactCallback.updateContacts(getdata(isEdit));
Navigator.of(context).pop();
print('ANG PUMASOK');
print(tfirstname);
} else {
Fluttertoast.showToast(
msg: 'ERROR ERROR',
toastLength: Toast.LENGTH_SHORT,
timeInSecForIosWeb: 1,
gravity: ToastGravity.BOTTOM
);
}
}
}
abstract class AddContactCallback {
void updateContacts(ContactObject contactObject);
}
这是我的想法的截图
解决方案
TextFormField
我认为在设置它之后 需要将值设置TextEditingController
为。
在返回小部件之前尝试,设置一个值;
Widget getTextFieled(
String inputData, TextEditingController inputTextController) {
var btm = new Padding(
padding: const EdgeInsets.all(5.0),
child: new TextFormField(
controller: inputTextController,
decoration: new InputDecoration(
hintText: inputData,
),
),
);
inputTextController.text = "Some Value Test";
return btm;
}
推荐阅读
- python-3.x - 在 OpenSUSE 上的 Python 中不显示绘图
- python - 将 2 个数据框与检查 id 进行比较,列值在其他数据框列中。如果值在那里,则更改相应的列
- node.js - 用 sinon 和 chai 测试函数时的问题
- xcode - XCode 没有编译文件并冻结系统
- firebase - 如何设置 pubsub 以便 firebase 可以通过云功能 pubsub 触发器接收?
- php - 如果 !empty 多行
- python - 对数据框中的一列求和并将结果返回为 int
- javascript - 如何从 php json 获取 jquery 变量
- php - 为什么 php 代码无法使用数据库中的文件和 longblob 上传图像?
- css - Bootstrap 4轮播不适用于AngularJS UI-Bootstrap