-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create and use a custom SelectableText in vm table and details page
- Loading branch information
Showing
5 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:flutter/material.dart' as fl; | ||
|
||
class SelectableText extends fl.StatelessWidget { | ||
final String text; | ||
final fl.TextStyle? style; | ||
final fl.TextAlign? textAlign; | ||
final int? maxLines; | ||
|
||
const SelectableText( | ||
this.text, { | ||
super.key, | ||
this.style, | ||
this.textAlign, | ||
this.maxLines, | ||
}); | ||
|
||
@override | ||
fl.Widget build(fl.BuildContext context) { | ||
final textButtonStyle = fl.Theme.of(context).textButtonTheme.style?.copyWith( | ||
backgroundColor: const fl.WidgetStatePropertyAll(fl.Colors.transparent), | ||
); | ||
|
||
return fl.SelectableText( | ||
text, | ||
style: style?.copyWith(overflow: fl.TextOverflow.ellipsis) ?? | ||
const fl.TextStyle(overflow: fl.TextOverflow.ellipsis), | ||
textAlign: textAlign, | ||
maxLines: maxLines, | ||
contextMenuBuilder: (context, editableTextState) { | ||
return fl.TapRegion( | ||
onTapOutside: (_) => fl.ContextMenuController.removeAny(), | ||
child: fl.TextButtonTheme( | ||
data: fl.TextButtonThemeData(style: textButtonStyle), | ||
child: fl.AdaptiveTextSelectionToolbar.buttonItems( | ||
anchors: editableTextState.contextMenuAnchors, | ||
buttonItems: editableTextState.contextMenuButtonItems, | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters