我希望有人可以帮助我吗?!
我试图弄清楚如何从我创建的sqflite表中提取数据,该应用程序要求用户可以从IT部门借用他需要的内容,然后将其作为电子邮件发送,并通过他选择的详细信息进行发送,我的问题,我无法获取要发送的电子邮件正文上的数据 我实际上已经设法使用以下代码在控制台中打印结果:
import 'package:flutter_email_sender/flutter_email_sender.dart';
class Mail extends StatefulWidget {
@override
_MailState createState() => _MailState();
}
class _MailState extends State<Mail> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
Future<void> send() async {
final Email email = Email(
subject: subjectController.text,
recipients: [emailController.text],
//attachmentPaths: attachments,
isHTML:true ,
body:_bodyController.text,
);
String platformResponse;
try {
await FlutterEmailSender.send(email);
platformResponse = 'success';
} catch (error) {
platformResponse = error.toString();
}
if (!mounted) return;
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(platformResponse),
));
}
这是电子邮件的正文,但我无法设置controller.text 输出3个表。
@override
var dbHelper = DBHelper();
final message='''
First Name:[lnumber]
''';
TextEditingController emailController = TextEditingController();
TextEditingController subjectController = TextEditingController();
TextEditingController _bodyController = TextEditingController();
String type,cpu,ram,hdd,win,office;
String fn,ln,email,dp ;
String lnumber,pnumber,screen,keyboard,mouse,printer,cable,headset;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Send Email'),
),
body: Column(
children: <Widget>[
TextField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
hintText: 'Email',
),
),
TextField(
controller: subjectController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: 'Subject',
),
),
new FutureBuilder<List<Employee>>(
future: fetchEmployeesFromDatabase(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return new ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
fn = snapshot.data[index].firstName;
ln = snapshot.data[index].lastName;
email =snapshot.data[index].emailId;
dp = snapshot.data[index].dep;
return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(fn, style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text(ln, style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text(email, style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text(dp, style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
]);
});
} else if (snapshot.hasError) {
return new Text("${snapshot.error}");
}
return new Container(alignment: AlignmentDirectional.center,
child: new CircularProgressIndicator(),);
},
),
Divider(),
new FutureBuilder<List<Computer>>(
future: fetchTypFromDatabase(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
type=snapshot.data[index].type;
cpu= snapshot.data[index].CPU;
ram=snapshot.data[index].RAM;
hdd=snapshot.data[index].HDD;
win=snapshot.data[index].windows;
office=snapshot.data[index].office;
//_bodyController.text=type;
return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text('Device Type:$type', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('CPU:$cpu', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('RAM:$ram', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('HDD:$hdd', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('Windows:$win', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('office:$office', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
],
);
}
);
}
else if (snapshot.hasError) {
return new Text("${snapshot.error}");
}
return new Container(alignment: AlignmentDirectional.center,
child: new CircularProgressIndicator(),);
},
),
Divider(),
new FutureBuilder<List<Accessory>>(
future: fetchAccessoryFromDatabase(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
lnumber= snapshot.data[index].laptopNumber;
pnumber= snapshot.data[index].pcNumber;
screen =snapshot.data[index].screen;
headset= snapshot.data[index].headsetNumber;
keyboard = snapshot.data[index].keyboardNumber;
mouse = snapshot.data[index].mouseNumber;
printer = snapshot.data[index].printerNumber;
cable = snapshot.data[index].cableNumber;
return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text('Laptop Number:$lnumber', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('Computer Number:$pnumber', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('Screen Number:$screen', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('Headset Number:$headset', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('Keybourd Number: $keyboard', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('Mouse Number: $mouse', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('Printer Number:$printer', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
new Text('Cable Number:$cable', style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
]);
}
);
}
else if (snapshot.hasError) {
return new Text("${snapshot.error}");
}
return new Container(alignment: AlignmentDirectional.center,
child: new CircularProgressIndicator(),);
},
),
RaisedButton(
child: Text('Send Email'),
color: Colors.red,
onPressed: send,
),
],
),
);
}
}
Future<List<Employee>> fetchEmployeesFromDatabase() async {
var dbHelper = DBHelper();
Future<List<Employee>> employees = dbHelper.getlastEmployees();
return employees;
}
Future<List<Computer>> fetchTypFromDatabase() async {
var dbHelper = DBHelper();
Future<List<Computer>> typ = dbHelper.getlastComputer();
return typ;
}
Future<List<Accessory>> fetchAccessoryFromDatabase() async {
var dbHelper = DBHelper();
Future<List<Accessory>> employees = dbHelper.getAccessory();
return employees;
}