copy_from_clipboard 1.0.0
copy_from_clipboard: ^1.0.0 copied to clipboard
A Flutter package that provides a simple widget to copy dynamic text to the system clipboard with user feedback.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:copy_from_clipboard/copy_from_clipboard.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: HomePage());
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int count = 1;
String pastedText = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Copy & Paste Test')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('CODE-$count'),
const SizedBox(height: 10),
CopyToClipboardButton(
valueBuilder: () => 'CODE-$count',
snackbarMessage: 'Text copied!',
),
const SizedBox(height: 20),
PasteFromClipboardButton(
onPasted: (text) {
setState(() {
pastedText = text ?? 'No text found';
});
},
snackbarMessage: 'Text pasted!',
),
const SizedBox(height: 20),
Text('Pasted: $pastedText'),
],
),
),
);
}
}