1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Flutter 1.22.6 - url_launcher - Sending HTML email

Discussão em 'Mobile' iniciado por Stack, Outubro 25, 2024 às 05:22.

  1. Stack

    Stack Membro Participativo

    I have two problems with the url_launcher: ^5.7.10 First Problem: When I try to send an email with html tag, on a real device, if I use Gmail application the body of my email is not well formated. I see the HTML tags. I tried with or without HTML5 doctype Second Problem: When I try to send an email with an Href tag the email body is cut at the equal sign.

    My code is

    import 'dart:async';

    import 'package:flutter/material.dart';
    import 'package:url_launcher/url_launcher.dart';

    void main() {
    runApp(MyApp());
    }

    class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return MaterialApp(
    title: 'URL Launcher',
    theme: ThemeData(
    primarySwatch: Colors.blue,
    ),
    home: MyHomePage(title: 'URL Launcher'),
    );
    }
    }

    class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);
    final String title;

    @override
    _MyHomePageState createState() => _MyHomePageState();
    }

    class _MyHomePageState extends State<MyHomePage> {

    Future<void> _sendMailHtml(String url) async {
    if (await canLaunch(url)) {
    await launch(
    url
    );
    } else {
    throw 'Could not launch $url';
    }
    }

    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    title: Text(widget.title),
    ),
    body: ListView(
    children: <Widget>[
    Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[

    RaisedButton(
    onPressed: () => setState(() {
    _launched = _sendMailHtml('mailto:smith@example.org?subject=News&body=<h1>Header 1</h1><p>Paragraph</p>');
    }),
    child: const Text('Send Mail HTML'),
    ),
    RaisedButton(
    onPressed: () => setState(() {
    _launched = _sendMailHtml('mailto:smith@example.org?subject=News&body=<h1>Header 1</h1><p>Paragraph</p><a href="https://google.com">Link</a><p>End of mail</p>');
    }),
    child: const Text('Send Mail HTML With HREF'),
    ),
    ],
    ),
    ],
    ),
    );
    }
    }



    My pubspec.yaml is

    name: flutter_app
    description: A new Flutter application.

    publish_to: 'none' # Remove this line if you wish to publish to pub.dev

    version: 1.0.0+1

    environment:
    sdk: ">=2.7.0 <3.0.0"

    dependencies:
    flutter:
    sdk: flutter
    url_launcher: ^5.7.10
    cupertino_icons: ^1.0.0

    dev_dependencies:
    flutter_test:
    sdk: flutter

    # The following section is specific to Flutter.
    flutter:

    uses-material-design: true



    I did not try with flutter 2 because my app is in production and I have some dependencies errors.

    For the first problem if I try with another email app, I can see the good formatting.

    On Android 10...

    screenshots :

    first problem on Gmail app

    on other email app

    Second problem with Gmail and anchor tag

    Continue reading...

Compartilhe esta Página