Tinyrack

CopyButton

Copy a value to the clipboard and confirm the copy briefly.

Copy a value to the clipboard and confirm the copy briefly.

Contract

AxisContract
StatusStarts at TRCopyButtonStatus.idle, switches to copied after the clipboard write succeeds, and returns to idle after resetDelay.
Repeated pressesEach press restarts the reset timer, so the last press decides when the label returns to idleLabel.
Label widthBoth labels stay laid out, so the button keeps the width of the wider label instead of resizing on copy.
Clipboard failureWhen the platform rejects the clipboard write, the button stays on idleLabel and onStatusChange does not fire.
Appearanceappearance, 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_ui
import '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

PropType / defaultPurpose
valueString (required)The text written to the clipboard.
idleLabelString = 'Copy'The label shown before a copy and after the reset delay.
copiedLabelString = 'Copied'The confirmation label shown while the status is copied.
resetDelayDuration = Duration(seconds: 2)How long the confirmation stays before the label returns to idleLabel.
onStatusChangeValueChanged<TRCopyButtonStatus>?Called with copied after a successful copy and with idle when the delay ends.

Appearance

PropType / defaultPurpose
appearanceTRAppearance = TRAppearance.solidChooses the solid, outline, or ghost button surface.
intentTRIntent = TRIntent.neutralApplies the semantic color intent shared with TRButton.
uiSizeTRUiSize = TRUiSize.mdSets the control height and typography to md or lg.