Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter, Sending Form Data to Email

Tags:

I would like to create a contact form and would like to know: How to send data from a contact form to my email? I would like to see a working example. I wanted to submit a form like this:

    return new Scaffold(   appBar: new AppBar(     title: new Text(widget.title),     actions: <Widget>[       new IconButton(icon: const Icon(Icons.save), onPressed: () {})     ],   ),   body: new Column(     children: <Widget>[       new ListTile(         leading: const Icon(Icons.person),         title: new TextField(           decoration: new InputDecoration(             hintText: "Name",           ),         ),       ),       new ListTile(         leading: const Icon(Icons.phone),         title: new TextField(           decoration: new InputDecoration(             hintText: "Phone",           ),         ),       ),       new ListTile(         leading: const Icon(Icons.email),         title: new TextField(           decoration: new InputDecoration(             hintText: "Email",           ),         ),       ), 
like image 340
jamil Avatar asked May 31 '18 11:05

jamil


People also ask

How do I send a Formdata Flutter?

flutter Share on : If you want to send form data in HTTP post request in Flutter or Dart, you can use map and add data to it and pass the map variable to the body parameter of http. post() function.

How do you use forms in Flutter?

To validate a form in a flutter, we need to implement mainly three steps. Step 1: Use the Form widget with a global key. Step 2: Use TextFormField to give the input field with validator property. Step 3: Create a button to validate form fields and display validation errors.


1 Answers

You can navigate to default Email app. You can also set the following attributes from your flutter app.

  1. to mail ID,
  2. subject and
  3. body

using url_launcher plugin.

Steps:

  1. Add this to your package's pubspec.yaml file: url_launcher: "^3.0.1"

  2. main.dart file

import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart';  void main() => runApp(new MaterialApp(home: new MyApp(), debugShowCheckedModeBanner: false,));  class MyApp extends StatefulWidget {   @override   _MyAppState createState() => new _MyAppState(); }  class _MyAppState extends State<MyApp> {   @override   Widget build(BuildContext context) {     return new Scaffold(       body: new Center(         child: new RaisedButton(onPressed: () => _launchURL('[email protected]', 'Flutter Email Test', 'Hello Flutter'), child: new Text('Send mail'),),       ),     );   }    _launchURL(String toMailId, String subject, String body) async {     var url = 'mailto:$toMailId?subject=$subject&body=$body';     if (await canLaunch(url)) {       await launch(url);     } else {       throw 'Could not launch $url';     }   } } 
like image 138
Vinoth Kumar Avatar answered Sep 22 '22 02:09

Vinoth Kumar