How to Create Copy to Clipboard Event on Flutter?


Currently i want to make event for “Copy to Clipboard” on user device.

When user click to “List view leading icon.content copy” then text should be store on his device clipboard.

Please can anyone help me?

Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
    final record = Record.fromSnapshot(data);

    return Padding(
      key: ValueKey(,
      padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(color: Colors.grey),
          borderRadius: BorderRadius.circular(5.0),
        child: ListTile(
          leading: Icon(Icons.content_copy),
          title: Text(,
          subtitle: Text(,
          // can anyone help me how to create event on onTap action.
          // When user click then text copy to clipboard on his device. 
             onTap: () {
             debugPrint ("Tapped");

class Record {
  final String name;
  final String group;
  final DocumentReference reference;

  Record.fromMap(Map<String, dynamic> map, {this.reference})
      : assert(map['name'] != null),
        assert(map['group'] != null),
        name = map['name'],
        group = map['group'];

  Record.fromSnapshot(DocumentSnapshot snapshot)
      : this.fromMap(, reference: snapshot.reference);

  String toString() => "Record<$name:$group>";


import 'package:flutter/services.dart';

inside your onTap add the following:

   Clipboard.setData(new ClipboardData(text:;
     (content: Text('text copied')));

Answered By – Sami Kanafani

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *