launchers 0.4.6 copy "launchers: ^0.4.6" to clipboard
launchers: ^0.4.6 copied to clipboard

outdated

A Flutter plugin that makes it easy to link into native apps or websites

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:launchers/launchers.dart';
import 'package:logging/logging.dart';
import 'package:logging_config/logging_config.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String attachment;

  @override
  void initState() {
    super.initState();
    configureLogging(
        LogConfig(logLevels: {"": Level.FINE}, handler: LoggingHandler.dev()));
  }

  final _recipientController = TextEditingController(
    text: 'example@example.com',
  );

  final _subjectController = TextEditingController(text: 'The subject');

  final _bodyController = TextEditingController(
    text: 'Mail body.',
  );

  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

  Future<void> send() async {
    final Email email = Email(
      body: _bodyController.text,
      subject: _subjectController.text,
      recipients: [_recipientController.text],
      attachmentPath: attachment,
    );

    Iterable<String> platformResponse;

    try {
      final results =
          await LaunchService().launch(composeEmailOperation, email);
      print(results);
      platformResponse = results.allAttempts.entries.map((entry) {
        return "Provider = ${entry.key}\nResult = ${entry.value}";
      });
    } catch (error, stack) {
      print(error);
      print(stack);
      platformResponse = ["Error: $error"];
    }

    if (!mounted) return;

    platformResponse.forEach((message) {
      print(message);
      print("-------------");
      _scaffoldKey.currentState.showSnackBar(SnackBar(
        content: Text("$platformResponse"),
        duration: Duration(seconds: 5),
      ));
    });
  }

  @override
  Widget build(BuildContext context) {
    final Widget imagePath = Text(attachment ?? '');
    return MaterialApp(
      theme: ThemeData(primaryColor: Colors.red),
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: Text('Plugin example app'),
          actions: <Widget>[
            IconButton(
              onPressed: send,
              icon: Icon(Icons.send),
            )
          ],
        ),
        body: SingleChildScrollView(
          child: Center(
            child: Padding(
              padding: EdgeInsets.all(8.0),
              child: Column(
                mainAxisSize: MainAxisSize.max,
                // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.all(8.0),
                    child: TextField(
                      controller: _recipientController,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(),
                        labelText: 'Recipient',
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(8.0),
                    child: TextField(
                      controller: _subjectController,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(),
                        labelText: 'Subject',
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(8.0),
                    child: TextField(
                      controller: _bodyController,
                      maxLines: 10,
                      decoration: InputDecoration(
                          labelText: 'Body', border: OutlineInputBorder()),
                    ),
                  ),
                  imagePath,
                ],
              ),
            ),
          ),
        ),
        floatingActionButton: FloatingActionButton.extended(
          icon: Icon(Icons.camera),
          label: Text('Add Image'),
          onPressed: _openImagePicker,
        ),
      ),
    );
  }

  void _openImagePicker() async {
    File pick = await ImagePicker.pickImage(source: ImageSource.gallery);
    setState(() {
      attachment = pick.path;
    });
  }
}
8
likes
30
pub points
40%
popularity

Publisher

verified publishersunnyapp.co

A Flutter plugin that makes it easy to link into native apps or websites

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

equatable, flutter, logging, logging_config, pedantic, url_launcher

More

Packages that depend on launchers