程序员家族。我是编程新手,我很难将数据从屏幕传输到列表,用户可以在列表中查看发送的消息。抱歉,这个问题很愚蠢,但我已经在图书馆,视频等中尝试过。但是我没有找到解决方案,请问有人可以帮我吗?谢谢!(我已经被这个问题困扰了好几天了)。
我的代码:
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:animated_button/animated_button.dart';
import 'package:giffy_dialog/giffy_dialog.dart';
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server/gmail.dart';
import 'package:ouvidoria_mvl/main.dart';
// ignore: must_be_immutable
class PaginadeBoasVindasAN extends StatelessWidget {
String _localAn;
String _problemaAn;
File _imagemAn;
File _imagemGaleriaAn;
PaginadeBoasVindasAN(
this._localAn,
this._problemaAn,
this._imagemAn,
this._imagemGaleriaAn,
);
final _formKey = GlobalKey<FormState>();
// Aqui vamos criar o e-mail - smtp
enviarMensagem() async {
String username = '@gmail.com';
String password = '4#';
final smtpServer = gmail(username, password);
// Use the SmtpServer class to configure an SMTP server:
// final smtpServer = SmtpServer('smtp.domain.com');
// See the named arguments of SmtpServer for further configuration
// options.
// Create our message.
final message = Message()
..from = Address('', '')
..recipients.add('@gmail.com')
..ccRecipients.addAll(['destCc1@gmail.com', 'destCc1@gmail.com'])
..bccRecipients.add(Address('destCc1@gmail.com'))
..subject = '$_localAn :: ${DateTime.now()}'
..text = 'LOCAL DA OCORRÊNCIA: $_localAn,n\ OCORRÊNCIA: $_problemaAn';
if ((_imagemAn != null) && (_imagemAn != ""))
message.attachments.add(FileAttachment(_imagemAn,));
if ((_imagemGaleriaAn!= null) && (_imagemGaleriaAn!= ""))
message.attachments.add(FileAttachment(_imagemGaleriaAn,));
try {
final sendReport = await send(message, smtpServer);
print('Mensagem enviada: ' + sendReport.toString());
} on MailerException catch (e) {
print('Mensagem não enviada.');
for (var p in e.problems) {
print('Problema: ${p.code}: ${p.msg}');
}
}
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
}
// HERE THE APP CONFIGURATION IS ENDED
// The Function below blocks the screen rotation, thus allowing the app to stay in vertical mode
void blockgiro() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitDown, DeviceOrientation.portraitUp]);
}
@override
Widget build(BuildContext context) {
blockgiro();
return Stack(children: <Widget>[
Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
padding: EdgeInsets.only(bottom: 20),
child: Container(
margin: EdgeInsets.all(10),
color: Colors.transparent,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 10,
),
padding: EdgeInsets.all(10),
height: 200,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 0,
color: Colors.white,
offset: Offset(0, 0))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child:
Image.asset("Assets/image/enviando-loading.gif")),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.only(
bottom: 30, right: 1, left: 1, top: 20),
),
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 5,
),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 2,
color: Colors.black54,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 250.0,
child: TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
speed: Duration(milliseconds: 100),
onTap: () {
print("Tap Event");
},
text: ['The location is this: $_localAn'],
textStyle: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.start,
),
),
),
),
Container(
margin: EdgeInsets.only(
left: 1,
bottom: 10,
top: 10,
),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 4,
color: Colors.black54,
offset: Offset(2, 2))
],
borderRadius: BorderRadius.circular(13),
color: Colors.white),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 1000.0,
child: TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
onTap: () {
print("Tap Event");
},
text: [
'Its occurrence: $_problemaAn',
],
textStyle: TextStyle(
color: Colors.black,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.justify,
curve: Curves.linear),
),
)),
Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
child: _imagemAn != null
? Image.file(
_imagemAn,
fit: BoxFit.scaleDown,
)
: Center(
child: Text(
'',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400),
),
),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 1,
color: Colors.transparent,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(30),
color: Colors.transparent),
),Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
child: _imagemGaleriaAn != null
? Image.file(
_imagemGaleriaAn,
fit: BoxFit.scaleDown,
)
: Center(
child: Text(
'Capture a photo',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w400),
),
),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
blurRadius: 1,
color: Colors.transparent,
offset: Offset(1, 1))
],
borderRadius: BorderRadius.circular(30),
color: Colors.transparent),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TypewriterAnimatedTextKit(
pause: Duration(minutes: 10),
onTap: () {
print("Select below");
},
text: [
'Need to edit your message?',
],
textStyle: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.lightBlueAccent,
fontSize: 20.0,
fontFamily: "Agne"),
textAlign: TextAlign.center,
curve: Curves.linear),
],
),
//INICIO DOS BOTOES SIM E NAO
Container(
padding: EdgeInsets.only(bottom: 50),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(
bottom: 2, top: 2, right: 55),
alignment: Alignment.centerLeft,
child: AnimatedButton(
shape: BoxShape.rectangle,
child: Text(
'Edit',
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
onPressed: () {
Navigator.pop(context);
},
width: 70,
height: 40,
color: Theme.of(context).primaryColor,
shadowDegree: ShadowDegree.dark,
enabled: true,
),
),
//ACIMA SIM, ABAIXO NÃO
Container(
margin: EdgeInsets.only(
bottom: 2, top: 2, left: 55),
alignment: Alignment.centerRight,
child: AnimatedButton(
child: const Text(
'Send',
style: TextStyle(
fontSize: 19,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
onPressed: () {
enviarMensagem();
showDialog(
context: context,
builder: (_) => AssetGiffyDialog(
image: Image.asset(
'Assets/image/Correta.gif'),
title: Text(
'Success',
style: TextStyle(
fontSize: 22.0,
fontWeight:
FontWeight.w600),
),
description: Text(
'Hi, we received your message',
style: TextStyle(),
),
entryAnimation:
EntryAnimation.BOTTOM_RIGHT,
onlyCancelButton: false,
onOkButtonPressed: () async {
final result =
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
splashScreen()));
},
onlyOkButton: true,
));
},
width: 70,
height: 40,
color: Theme.of(context).primaryColor,
shadowDegree: ShadowDegree.dark,
enabled: true,
),
)
],
),
],
),
Container(
padding: EdgeInsets.only(bottom: 50),
),
]))),
)
]);
}
}