Alexis Olveres
Alexis Olveres

Reputation: 301

How can I access the Clipboard?

I am trying to access the Clipboard in Flutter, but I encounter the following error:

Class or object does not exist.

Am I missing an import?

I tried the following:

import 'package:flutter/material.dart';

Clipboard.setData(); 

Upvotes: 1

Views: 920

Answers (2)

Houssem
Houssem

Reputation: 7548

Answer Updated :
Import :

import 'package:flutter/services.dart';

And implement this :

IconButton(
    icon: Icon(
        Icons.content_copy,
        color: Colors.blue,
    ),
    onPressed: () {
        Clipboard.setData(ClipboardData(text: "your text"));
    }
),

Upvotes: 3

creativecreatorormaybenot
creativecreatorormaybenot

Reputation: 126734

You need to import flutter/services.dart:

import 'package:flutter/services.dart';

Now, you can access Clipboard.setData.

Upvotes: 1

Related Questions