sl_clipboard_manager 1.0.0
sl_clipboard_manager: ^1.0.0 copied to clipboard
A flutter plugin to copy text to clipboard.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:sl_clipboard_manager/sl_clipboard_manager.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool copiedSuccessfully = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Clipboard Demo',
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Builder(
builder: (context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Your coupon is xYZ1234AB'),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
final result = await ClipboardManager.copyToClipBoard(
'xYZ1234AB',
);
if (!mounted) return;
setState(() {
copiedSuccessfully = result;
});
final snackBar = SnackBar(
content: Text(
copiedSuccessfully
? 'Copied to Clipboard'
: 'Error copying to Clipboard',
),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
// aqui você pode implementar algo se quiser desfazer
},
),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: const Text('Copy to Clipboard'),
),
],
),
);
},
),
),
);
}
}