Ruben
Ruben

Reputation: 337

In Flutter, how to share the text using share_plus in a the format that I want

I'm currently building a password manager using Flutter. I have used share_plus.dart package , to share the passwords stored by the user. I have 4 text fields in my password, they are : title, email, password(userpassword), and url.

When I share them, they get displayed in a not good looking format. So,I want to display, the text shared using the share button on my flutter app in a particular format.

The format, I want:

Title: value
Email: value
Password: value
url: value

My code:

          IconButton(
            onPressed: () async {
              final text = _titleController.text + _emailController.text + _userPasswordController.text + _urlController.text;
              if (_password == null || text.isEmpty) {
                await showCannotShareEmptyPasswordDialog(context);
              } else {
                Share.share(text);
              }
            },
            icon: const Icon(Icons.share),
          ),

Upvotes: 0

Views: 2459

Answers (2)

André
André

Reputation: 93

Multi-line triple strings

do

Share.share('''
Title: $Title 
Email: $value
''');

String class https://api.flutter.dev/flutter/dart-core/String-class.html

Upvotes: 0

AlishanMuhammadAmin
AlishanMuhammadAmin

Reputation: 310

Share.share("Title: $Title"\n Email: $value" \n);

Try using this, this might help you

in my case i did like this

ShareClass.shareMethod(
        message:
        "Join me on App! It is an awesome and secure app we can use to connect with each other Download it at: ${Platform.isAndroid ? "https://play.google.com/store/apps/details?id" : "https://apps.apple.com/us/app/app"}");
  }

Upvotes: 1

Related Questions