CopyButton
Copy a value to the clipboard and confirm the copy briefly.
Copy a value to the clipboard and confirm the copy briefly.
Contract
| Axis | Contract |
|---|---|
| Status | Starts at TRCopyButtonStatus.idle, switches to copied after the clipboard write succeeds, and returns to idle after resetDelay. |
| Repeated presses | Each press restarts the reset timer, so the last press decides when the label returns to idleLabel. |
| Label width | Both labels stay laid out, so the button keeps the width of the wider label instead of resizing on copy. |
| Clipboard failure | When the platform rejects the clipboard write, the button stays on idleLabel and onStatusChange does not fire. |
| Appearance | appearance, intent, and uiSize are forwarded to the underlying TRButton. |
Keep value to what the reader expects on the clipboard, such as a command or an identifier. Watch onStatusChange when a surrounding surface needs to react to the copy.
Install
Add the package, then import its public library.
flutter pub add tinyrack_uiimport 'package:tinyrack_ui/tinyrack_ui.dart';Playground
Usage
import 'package:material_ui/material_ui.dart';
import 'package:tinyrack_ui/tinyrack_ui.dart';
class InstallCommand extends StatefulWidget {
const InstallCommand({super.key});
@override
State<InstallCommand> createState() => _InstallCommandState();
}
class _InstallCommandState extends State<InstallCommand> {
TRCopyButtonStatus status = TRCopyButtonStatus.idle;
@override
Widget build(BuildContext context) => Row(
mainAxisSize: MainAxisSize.min,
spacing: TRSpacing.small,
children: [
const TRCode('flutter pub add tinyrack_ui'),
TRCopyButton(
value: 'flutter pub add tinyrack_ui',
onStatusChange: (next) => setState(() => status = next),
),
],
);
}Examples
Contextual labels permalink
Name what gets copied so the confirmation still reads clearly when several copy buttons share a screen.
Inherited Button combinations permalink
`appearance`, `intent`, and `uiSize` reach the underlying `TRButton`, and `resetDelay` shortens or extends the confirmation.
API
Copy behavior
| Prop | Type / default | Purpose |
|---|---|---|
value | String (required) | The text written to the clipboard. |
idleLabel | String = 'Copy' | The label shown before a copy and after the reset delay. |
copiedLabel | String = 'Copied' | The confirmation label shown while the status is copied. |
resetDelay | Duration = Duration(seconds: 2) | How long the confirmation stays before the label returns to idleLabel. |
onStatusChange | ValueChanged<TRCopyButtonStatus>? | Called with copied after a successful copy and with idle when the delay ends. |
Appearance
| Prop | Type / default | Purpose |
|---|---|---|
appearance | TRAppearance = TRAppearance.solid | Chooses the solid, outline, or ghost button surface. |
intent | TRIntent = TRIntent.neutral | Applies the semantic color intent shared with TRButton. |
uiSize | TRUiSize = TRUiSize.md | Sets the control height and typography to md or lg. |