【发布时间】:2020-09-02 13:47:28
【问题描述】:
我正在构建一个颤振应用程序,它有一个联系表格。填写联系表格后,当用户在没有第三方的情况下按下提交时,我希望用户提供的数据从联系表格发送到我的电子邮件地址(或我将提供的电子邮件地址)。我的表单有预定义的字段,这些字段将由用户填写。提交后,我希望将表单发送到管理员的电子邮件地址。 我不是在谈论在我的应用中发送邮件
我已经完成了此处提出的附加问题,看起来很相似,但它没有回答我的问题。我曾尝试使用 url_launcher 包,但这也无济于事。
Flutter, Sending Form Data to Email
下面是我的表单截图。
**下面是我的代码摘录**
return Scaffold(
backgroundColor: Color(0xFF56ccf2),
body: SafeArea(
top: false,
bottom: false,
child: SingleChildScrollView(
child: Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.only(
top: 10.0, bottom: 5.0, left: 15.0, right: 15.0),
child: Card(
elevation: 6,
child: Form(
key: _formKey,
autovalidate: _autoValidate,
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.symmetric(horizontal: 20.0),
children: <Widget>[
//===> Student Number Text Input starts from here <===
Padding(
padding: EdgeInsets.only(
top: 10.0, bottom: 6.0, left: 1.0, right: 1.0),
child: TextFormField(
autofocus: false,
focusNode: myFocusNodeEmail,
controller: studentNumberController,
keyboardType: TextInputType.emailAddress,
style: TextStyle(
fontSize: 16.0,
color: Colors.black),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
labelText: 'Student Number',
),
validator: validateStudentNumber,
onSaved: (String val) {
_stNumber = val;
},
),
),
//===> Email Address Text Input starts from here <===
Padding(
padding: EdgeInsets.only(
top: 1.0, bottom: 6.0, left: 1.0, right: 1.0),
child: TextFormField(
validator: validateStudentEmailAddress,
onSaved: (String val) {
_stEmail = val;
},
controller: studentEmailController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
labelText: 'Student Email',
),
keyboardType: TextInputType.emailAddress,
style: TextStyle(
fontSize: 16.0,
color: Colors.black),
),
),
//===> Phone Number Text Input starts from here <===
Padding(
padding: EdgeInsets.only(
top: 1.0, bottom: 6.0, left: 1.0, right: 1.0),
child: TextFormField(
validator: validateStudentPhoneNumber,
onSaved: (String val) {
_stPhone = val;
},
controller: studentPhoneNumberController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
labelText: 'Phone Number',
),
keyboardType: TextInputType.phone,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'^[()\d -]{1,15}$')),
],
style: TextStyle(
fontSize: 16.0,
color: Colors.black),
),
),
//===> Drop Down Menu starts from here <===
Padding(
padding: EdgeInsets.only(top: 1.0, bottom: 6.0, left: 1.0, right: 1.0),
child: FormField(
builder: (FormFieldState state) {
return InputDecorator(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
labelText: 'Semester',
hintText: ("Semester"),
),
isEmpty: _semester == '',
child: Padding(
padding: EdgeInsets.only(left: 1.0, right: 130 , ),
child: Container(
width: MediaQuery.of(context).size.width,
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton(
value: _semester,
isDense: true,
elevation: 5,
isExpanded: true,
onChanged: (String value) {
setState(() {
_semester = value;
state.didChange(value);
});
},
items: _semesters.map((String value) {
return DropdownMenuItem(
value: value,
child: Text(value ?? '',
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
maxLines: 1,
softWrap: true,
),
);
}).toList(),
),
),
),
),
),
);
},
),
),
//===> Query Text Input starts from here <===
TextFormField(
validator: validateStudentQuery,
onSaved: (String val) {
_query = val;
},
controller: queryController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
labelText: 'Your Query',
),
keyboardType: TextInputType.text,
style: TextStyle(
fontSize: 16.0,
color: Colors.black),
maxLines: 3,
),
Container(
margin: EdgeInsets.only(top: 6.0, bottom: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Color(0xFF008ECC),
offset: Offset(0.0, 0.0),
//blurRadius: 20.0,
),
BoxShadow(
color: Color(0xFF008ECC),
offset: Offset(0.0, 0.0),
//blurRadius: 20.0,
),
],
gradient: LinearGradient(
colors: [
Color(0xFF008ECC), //Colors is Olympic blue
Color(0xFF008ECC),
],
begin: FractionalOffset(0.2, 0.2),
end: FractionalOffset(1.0, 1.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp),
),
child: MaterialButton(
onPressed: validateAndSubmit,
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 10.0, horizontal: 65.0),
child: Text(
"Submit",
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
),
),
),
)),
],
)),
),
),
],
),
),
)),
);
【问题讨论】:
-
您需要澄清“我希望将数据发送到我的电子邮件地址”是什么意思,您是否想要: a) 通过意图打开默认邮件应用程序; b) 通过 SMTP 直接从您的应用程序发送电子邮件; c) 别的东西(请详细说明)。哦,顺便说一句:a) 和 b) 包含在您发布的链接问题中,您只需向下滚动一点。
-
我想要的是在用户填写表格后,我希望将数据直接发送到我的电子邮件地址。 @Uroš
-
没有@ChristopherMoore