mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-22 19:40:10 +08:00
50 lines
1.2 KiB
Dart
50 lines
1.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class SelectionText extends StatelessWidget {
|
|
const SelectionText(
|
|
String this.data, {
|
|
super.key,
|
|
this.style,
|
|
this.textAlign,
|
|
this.contextMenuBuilder = _defaultContextMenuBuilder,
|
|
}) : textSpan = null;
|
|
|
|
const SelectionText.rich(
|
|
InlineSpan this.textSpan, {
|
|
super.key,
|
|
this.style,
|
|
this.textAlign,
|
|
this.contextMenuBuilder = _defaultContextMenuBuilder,
|
|
}) : data = null;
|
|
|
|
final String? data;
|
|
final InlineSpan? textSpan;
|
|
final TextStyle? style;
|
|
final TextAlign? textAlign;
|
|
final SelectableRegionContextMenuBuilder? contextMenuBuilder;
|
|
|
|
static Widget _defaultContextMenuBuilder(
|
|
BuildContext context,
|
|
SelectableRegionState selectableRegionState,
|
|
) {
|
|
return AdaptiveTextSelectionToolbar.selectableRegion(
|
|
selectableRegionState: selectableRegionState,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SelectionArea(
|
|
contextMenuBuilder: contextMenuBuilder,
|
|
child: Text.rich(
|
|
style: style,
|
|
textAlign: textAlign,
|
|
TextSpan(
|
|
text: data,
|
|
children: textSpan != null ? <InlineSpan>[textSpan!] : null,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|