55 lines
1.3 KiB
Dart
55 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
|
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
|
|
|
class CopyToClipboard extends StatelessWidget {
|
|
const CopyToClipboard({
|
|
Key key,
|
|
@required this.value,
|
|
this.child,
|
|
this.showBorder = false,
|
|
}) : super(key: key);
|
|
|
|
final Widget child;
|
|
final String value;
|
|
final bool showBorder;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if ((value ?? '').isEmpty) {
|
|
return SizedBox();
|
|
}
|
|
|
|
final widget = child == null
|
|
? Text(
|
|
value,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
)
|
|
: child;
|
|
final localization = AppLocalization.of(context);
|
|
final onTap = () {
|
|
Clipboard.setData(ClipboardData(text: value));
|
|
showToast(
|
|
localization.copiedToClipboard.replaceFirst(
|
|
':value',
|
|
value.replaceAll('\n', ' '),
|
|
),
|
|
);
|
|
};
|
|
|
|
if (showBorder) {
|
|
return ConstrainedBox(
|
|
child: OutlinedButton(onPressed: onTap, child: widget),
|
|
constraints: BoxConstraints(maxWidth: 180),
|
|
);
|
|
} else {
|
|
return InkWell(
|
|
child: widget,
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
}
|
|
}
|