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", ), ), ),
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.
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.
You can navigate to default Email app
. You can also set the following attributes from your flutter app.
to mail ID
,subject
andbody
using url_launcher
plugin.
Steps:
Add this to your package's pubspec.yaml file: url_launcher: "^3.0.1"
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'; } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With