using System ;
using Unity.UIWidgets.animation ;
using Unity.UIWidgets.async ;
using Unity.UIWidgets.cupertino ;
using Unity.UIWidgets.foundation ;
using Unity.UIWidgets.gestures ;
using TextStyle = Unity . UIWidgets . painting . TextStyle ;
namespace Unity.UIWidgets.material {
public static class SelectableTextUtils {
internal const int iOSHorizontalOffset = - 2 ;
}
D . assert ( textSpan ! = null ) ;
_textSpan = textSpan ;
}
public override TextSpan buildTextSpan ( TextStyle style = null , bool withComposing = false ) {
public override TextSpan buildTextSpan ( TextStyle style = null , bool withComposing = false ) {
set {
}
set { }
}
}
) : base ( _delegate : state ) {
_state = state ;
}
public readonly _SelectableTextState _state ;
protected override void onForcePressStart ( ForcePressDetails details ) {
protected override void onSingleLongTapMoveUpdate ( LongPressMoveUpdateDetails details ) {
if ( _delegate . selectionEnabled ) {
switch ( Theme . of ( _state . context ) . platform ) {
case RuntimePlatform . IPhonePlayer :
case RuntimePlatform . IPhonePlayer :
case RuntimePlatform . OSXEditor :
case RuntimePlatform . OSXPlayer :
renderEditable . selectPositionAt (
editableText . hideToolbar ( ) ;
if ( _delegate . selectionEnabled ) {
switch ( Theme . of ( _state . context ) . platform ) {
case RuntimePlatform . IPhonePlayer :
case RuntimePlatform . IPhonePlayer :
case RuntimePlatform . OSXEditor :
case RuntimePlatform . OSXPlayer :
renderEditable . selectWordEdge ( cause : SelectionChangedCause . tap ) ;
break ;
}
}
if ( _state . widget . onTap ! = null )
_state . widget . onTap ( ) ;
}
switch ( Theme . of ( _state . context ) . platform ) {
case RuntimePlatform . IPhonePlayer :
case RuntimePlatform . IPhonePlayer :
case RuntimePlatform . OSXEditor :
case RuntimePlatform . OSXPlayer :
renderEditable . selectPositionAt (
}
public class SelectableText : StatefulWidget {
public SelectableText (
string data ,
Key key = null ,
GestureTapCallback onTap = null ,
ScrollPhysics scrollPhysics = null ,
TextWidthBasis ? textWidthBasis = null
) : this (
) : this (
data : data ,
textSpan : null ,
key : key ,
onTap : onTap ,
scrollPhysics : scrollPhysics ,
textWidthBasis : textWidthBasis
) {
) {
SelectableText (
string data ,
TextSpan textSpan ,
GestureTapCallback onTap = null ,
ScrollPhysics scrollPhysics = null ,
TextWidthBasis ? textWidthBasis = null
) : base ( key : key ) {
) : base ( key : key ) {
D . assert ( maxLines = = null | | maxLines > 0 ) ;
D . assert ( minLines = = null | | minLines > 0 ) ;
D . assert (
selectAll : true ,
copy : true
) ;
this . data = data ;
this . textSpan = textSpan ;
this . focusNode = focusNode ;
textSpan ! = null ,
( ) = > "A non-null TextSpan must be provided to a SelectableText.rich widget."
) ;
return new SelectableText (
data : null ,
textSpan : textSpan ,
onTap : onTap ,
scrollPhysics : scrollPhysics ,
textWidthBasis : textWidthBasis
) ;
) ;
public readonly string data ;
public readonly string data ;
public readonly TextSpan textSpan ;
public readonly FocusNode focusNode ;
public readonly TextSpan textSpan ;
public readonly TextStyle style ;
public readonly StrutStyle strutStyle ;
public readonly FocusNode focusNode ;
public readonly TextAlign ? textAlign ;
public readonly TextStyle style ;
public readonly TextDirection ? textDirection ;
public readonly StrutStyle strutStyle ;
public readonly float? textScaleFactor ;
public readonly bool autofocus ;
public readonly int? minLines ;
public readonly int? maxLines ;
public readonly TextAlign ? textAlign ;
public readonly bool showCursor ;
public readonly TextDirection ? textDirection ;
public readonly float? textScaleFactor ;
public readonly float cursorWidth ;
public readonly bool autofocus ;
public readonly int? minLines ;
public readonly Radius cursorRadius ;
public readonly int? maxLines ;
public readonly Color cursorColor ;
public readonly bool showCursor ;
public readonly float cursorWidth ;
public readonly bool enableInteractiveSelection ;
public readonly Radius cursorRadius ;
public readonly Color cursorColor ;
public readonly DragStartBehavior dragStartBehavior ;
public readonly bool enableInteractiveSelection ;
public readonly ToolbarOptions toolbarOptions ;
public readonly DragStartBehavior dragStartBehavior ;
public readonly ToolbarOptions toolbarOptions ;
internal bool selectionEnabled {
get { return enableInteractiveSelection ; }
}
public readonly GestureTapCallback onTap ;
internal bool selectionEnabled {
get { return enableInteractiveSelection ; }
}
public readonly GestureTapCallback onTap ;
public readonly ScrollPhysics scrollPhysics ;
public readonly ScrollPhysics scrollPhysics ;
public readonly TextWidthBasis ? textWidthBasis ;
public readonly TextWidthBasis ? textWidthBasis ;
public override State createState ( ) = > new _SelectableTextState ( ) ;
public override State createState ( ) = > new _SelectableTextState ( ) ;
public override void debugFillProperties ( DiagnosticPropertiesBuilder properties ) {
base . debugFillProperties ( properties ) ;
properties . add ( new DiagnosticsProperty < string > ( "data" , data , defaultValue : null ) ) ;
properties . add ( new DiagnosticsProperty < FocusNode > ( "focusNode" , focusNode , defaultValue : null ) ) ;
properties . add ( new DiagnosticsProperty < TextStyle > ( "style" , style , defaultValue : null ) ) ;
properties . add ( new DiagnosticsProperty < bool > ( "autofocus" , autofocus , defaultValue : false ) ) ;
properties . add ( new DiagnosticsProperty < bool > ( "showCursor" , showCursor , defaultValue : false ) ) ;
properties . add ( new IntProperty ( "minLines" , minLines , defaultValue : null ) ) ;
properties . add ( new IntProperty ( "maxLines" , maxLines , defaultValue : null ) ) ;
properties . add ( new EnumProperty < TextAlign ? > ( "textAlign" , textAlign , defaultValue : null ) ) ;
properties . add ( new EnumProperty < TextDirection ? > ( "textDirection" , textDirection , defaultValue : null ) ) ;
properties . add ( new FloatProperty ( "textScaleFactor" , textScaleFactor , defaultValue : null ) ) ;
properties . add ( new FloatProperty ( "cursorWidth" , cursorWidth , defaultValue : 2.0f ) ) ;
properties . add ( new DiagnosticsProperty < Radius > ( "cursorRadius" , cursorRadius , defaultValue : null ) ) ;
properties . add ( new DiagnosticsProperty < Color > ( "cursorColor" , cursorColor , defaultValue : null ) ) ;
properties . add ( new FlagProperty ( "selectionEnabled" , value : selectionEnabled , defaultValue : true , ifFalse : "selection disabled" ) ) ;
properties . add ( new DiagnosticsProperty < ScrollPhysics > ( "scrollPhysics" , scrollPhysics , defaultValue : null ) ) ;
}
public override void debugFillProperties ( DiagnosticPropertiesBuilder properties ) {
base . debugFillProperties ( properties ) ;
properties . add ( new DiagnosticsProperty < string > ( "data" , data , defaultValue : null ) ) ;
properties . add ( new DiagnosticsProperty < FocusNode > ( "focusNode" , focusNode , defaultValue : null ) ) ;
properties . add ( new DiagnosticsProperty < TextStyle > ( "style" , style , defaultValue : null ) ) ;
properties . add ( new DiagnosticsProperty < bool > ( "autofocus" , autofocus , defaultValue : false ) ) ;
properties . add ( new DiagnosticsProperty < bool > ( "showCursor" , showCursor , defaultValue : false ) ) ;
properties . add ( new IntProperty ( "minLines" , minLines , defaultValue : null ) ) ;
properties . add ( new IntProperty ( "maxLines" , maxLines , defaultValue : null ) ) ;
properties . add ( new EnumProperty < TextAlign ? > ( "textAlign" , textAlign , defaultValue : null ) ) ;
properties . add ( new EnumProperty < TextDirection ? > ( "textDirection" , textDirection , defaultValue : null ) ) ;
properties . add ( new FloatProperty ( "textScaleFactor" , textScaleFactor , defaultValue : null ) ) ;
properties . add ( new FloatProperty ( "cursorWidth" , cursorWidth , defaultValue : 2.0f ) ) ;
properties . add ( new DiagnosticsProperty < Radius > ( "cursorRadius" , cursorRadius , defaultValue : null ) ) ;
properties . add ( new DiagnosticsProperty < Color > ( "cursorColor" , cursorColor , defaultValue : null ) ) ;
properties . add ( new FlagProperty ( "selectionEnabled" , value : selectionEnabled , defaultValue : true ,
ifFalse : "selection disabled" ) ) ;
properties . add ( new DiagnosticsProperty < ScrollPhysics > ( "scrollPhysics" , scrollPhysics , defaultValue : null ) ) ;
}
_TextSpanEditingController _controller ;
FocusNode _focusNode ;
get { return _forcePressEnabled ; }
set { _forcePressEnabled = value ; }
}
bool _forcePressEnabled ;
public GlobalKey < EditableTextState > editableTextKey {
textSpan : widget . textSpan ? ? new TextSpan ( text : widget . data )
) ;
}
if ( _effectiveFocusNode . hasFocus & & _controller . selection . isCollapsed ) {
_showSelectionHandles = false ;
}
_focusNode ? . dispose ( ) ;
base . dispose ( ) ;
}
setState ( ( ) = > {
_showSelectionHandles = willShowSelectionHandles ;
} ) ;
setState ( ( ) = > { _showSelectionHandles = willShowSelectionHandles ; } ) ;
}
switch ( Theme . of ( context ) . platform ) {
if ( cause = = SelectionChangedCause . longPress ) {
_editableText ? . bringIntoView ( selection . basePos ) ;
}
// Do nothing.
break ;
// Do nothing.
break ;
bool _shouldShowSelectionHandles ( SelectionChangedCause cause ) {
if ( ! _selectionGestureDetectorBuilder . shouldShowSelectionToolbar )
return false ;
}
protected override bool wantKeepAlive = > true ;
Widget build ( BuildContext context ) {
base . build ( context ) ;
D . assert ( ( ) = > {
return _controller . _textSpan . visitChildren ( ( InlineSpan span ) = > span is TextSpan ) ;
} , ( ) = > "SelectableText only supports TextSpan; Other type of InlineSpan is not allowed" ) ;
D . assert ( WidgetsD . debugCheckHasMediaQuery ( context ) ) ;
D . assert ( WidgetsD . debugCheckHasDirectionality ( context ) ) ;
D . assert (
! ( widget . style ! = null & & widget . style . inherit = = false & &
( widget . style . fontSize = = null | | widget . style . textBaseline = = null ) ) ,
( ) = > "inherit false style must supply fontSize and textBaseline"
) ;
public override Widget build ( BuildContext context ) {
base . build ( context ) ;
D . assert ( ( ) = > { return _controller . _textSpan . visitChildren ( ( InlineSpan span ) = > span is TextSpan ) ; } ,
( ) = > "SelectableText only supports TextSpan; Other type of InlineSpan is not allowed" ) ;
D . assert ( WidgetsD . debugCheckHasMediaQuery ( context ) ) ;
D . assert ( WidgetsD . debugCheckHasDirectionality ( context ) ) ;
D . assert (
! ( widget . style ! = null & & widget . style . inherit = = false & &
( widget . style . fontSize = = null | | widget . style . textBaseline = = null ) ) ,
( ) = > "inherit false style must supply fontSize and textBaseline"
) ;
ThemeData themeData = Theme . of ( context ) ;
FocusNode focusNode = _effectiveFocusNode ;
ThemeData themeData = Theme . of ( context ) ;
FocusNode focusNode = _effectiveFocusNode ;
TextSelectionControls textSelectionControls ;
bool paintCursorAboveText ;
bool cursorOpacityAnimates ;
Offset cursorOffset = Offset . zero ;
Color cursorColor = widget . cursorColor ;
Radius cursorRadius = widget . cursorRadius ;
TextSelectionControls textSelectionControls ;
bool paintCursorAboveText ;
bool cursorOpacityAnimates ;
Offset cursorOffset = Offset . zero ;
Color cursorColor = widget . cursorColor ;
Radius cursorRadius = widget . cursorRadius ;
switch ( themeData . platform ) {
case RuntimePlatform . IPhonePlayer :
case RuntimePlatform . OSXEditor :
case RuntimePlatform . OSXPlayer :
forcePressEnabled = true ;
textSelectionControls = CupertinoTextFieldUtils . cupertinoTextSelectionControls ;
paintCursorAboveText = true ;
cursorOpacityAnimates = true ;
cursorColor = cursorColor ? ? CupertinoTheme . of ( context ) . primaryColor ;
cursorRadius = cursorRadius ? ? Radius . circular ( 2.0f ) ;
cursorOffset = new Offset ( SelectableTextUtils . iOSHorizontalOffset / MediaQuery . of ( context ) . devicePixelRatio , 0 ) ;
break ;
switch ( themeData . platform ) {
case RuntimePlatform . IPhonePlayer :
case RuntimePlatform . OSXEditor :
case RuntimePlatform . OSXPlayer :
forcePressEnabled = true ;
textSelectionControls = CupertinoTextFieldUtils . cupertinoTextSelectionControls ;
paintCursorAboveText = true ;
cursorOpacityAnimates = true ;
cursorColor = cursorColor ? ? CupertinoTheme . of ( context ) . primaryColor ;
cursorRadius = cursorRadius ? ? Radius . circular ( 2.0f ) ;
cursorOffset =
new Offset ( SelectableTextUtils . iOSHorizontalOffset / MediaQuery . of ( context ) . devicePixelRatio ,
0 ) ;
break ;
default :
forcePressEnabled = false ;
textSelectionControls = _MaterialTextSelectionControls . materialTextSelectionControls ;
paintCursorAboveText = false ;
cursorOpacityAnimates = false ;
cursorColor = cursorColor ? ? themeData . cursorColor ;
break ;
}
default :
forcePressEnabled = false ;
textSelectionControls = _MaterialTextSelectionControls . materialTextSelectionControls ;
paintCursorAboveText = false ;
cursorOpacityAnimates = false ;
cursorColor = cursorColor ? ? themeData . cursorColor ;
break ;
}
DefaultTextStyle defaultTextStyle = DefaultTextStyle . of ( context ) ;
TextStyle effectiveTextStyle = widget . style ;
if ( widget . style = = null | | widget . style . inherit )
effectiveTextStyle = defaultTextStyle . style . merge ( widget . style ) ;
if ( MediaQuery . boldTextOverride ( context ) )
effectiveTextStyle = effectiveTextStyle . merge ( new TextStyle ( fontWeight : FontWeight . bold ) ) ;
Widget child = new RepaintBoundary (
child : new EditableText (
key : editableTextKey ,
style : effectiveTextStyle ,
readOnly : true ,
textWidthBasis : widget . textWidthBasis ? ? defaultTextStyle . textWidthBasis ,
showSelectionHandles : _showSelectionHandles ,
showCursor : widget . showCursor ,
controller : _controller ,
focusNode : focusNode ,
strutStyle : widget . strutStyle ? ? new StrutStyle ( ) ,
textAlign : widget . textAlign ? ? defaultTextStyle . textAlign ? ? TextAlign . start ,
textDirection : widget . textDirection ,
textScaleFactor : widget . textScaleFactor ,
autofocus : widget . autofocus ,
forceLine : false ,
toolbarOptions : widget . toolbarOptions ,
minLines : widget . minLines ,
maxLines : widget . maxLines ? ? defaultTextStyle . maxLines ,
selectionColor : themeData . textSelectionColor ,
selectionControls : widget . selectionEnabled ? textSelectionControls : null ,
onSelectionChanged : _handleSelectionChanged ,
onSelectionHandleTapped : _handleSelectionHandleTapped ,
rendererIgnoresPointer : true ,
cursorWidth : widget . cursorWidth ,
cursorRadius : cursorRadius ,
cursorColor : cursorColor ,
cursorOpacityAnimates : cursorOpacityAnimates ,
cursorOffset : cursorOffset ,
paintCursorAboveText : paintCursorAboveText ,
backgroundCursorColor : CupertinoColors . inactiveGray ,
enableInteractiveSelection : widget . enableInteractiveSelection ,
dragStartBehavior : widget . dragStartBehavior ,
scrollPhysics : widget . scrollPhysics
)
) ;
DefaultTextStyle defaultTextStyle = DefaultTextStyle . of ( context ) ;
TextStyle effectiveTextStyle = widget . style ;
if ( widget . style = = null | | widget . style . inherit )
effectiveTextStyle = defaultTextStyle . style . merge ( widget . style ) ;
if ( MediaQuery . boldTextOverride ( context ) )
effectiveTextStyle = effectiveTextStyle . merge ( new TextStyle ( fontWeight : FontWeight . bold ) ) ;
return _selectionGestureDetectorBuilder . buildGestureDetector (
behavior : HitTestBehavior . translucent ,
child : child
) ;
Widget child = new RepaintBoundary (
child : new EditableText (
key : editableTextKey ,
style : effectiveTextStyle ,
readOnly : true ,
textWidthBasis : widget . textWidthBasis ? ? defaultTextStyle . textWidthBasis ,
showSelectionHandles : _showSelectionHandles ,
showCursor : widget . showCursor ,
controller : _controller ,
focusNode : focusNode ,
strutStyle : widget . strutStyle ? ? new StrutStyle ( ) ,
textAlign : widget . textAlign ? ? defaultTextStyle . textAlign ? ? TextAlign . start ,
textDirection : widget . textDirection ,
textScaleFactor : widget . textScaleFactor ,
autofocus : widget . autofocus ,
forceLine : false ,
toolbarOptions : widget . toolbarOptions ,
minLines : widget . minLines ,
maxLines : widget . maxLines ? ? defaultTextStyle . maxLines ,
selectionColor : themeData . textSelectionColor ,
selectionControls : widget . selectionEnabled ? textSelectionControls : null ,
onSelectionChanged : _handleSelectionChanged ,
onSelectionHandleTapped : _handleSelectionHandleTapped ,
rendererIgnoresPointer : true ,
cursorWidth : widget . cursorWidth ,
cursorRadius : cursorRadius ,
cursorColor : cursorColor ,
cursorOpacityAnimates : cursorOpacityAnimates ,
cursorOffset : cursorOffset ,
paintCursorAboveText : paintCursorAboveText ,
backgroundCursorColor : CupertinoColors . inactiveGray ,
enableInteractiveSelection : widget . enableInteractiveSelection ,
dragStartBehavior : widget . dragStartBehavior ,
scrollPhysics : widget . scrollPhysics
)
) ;
return _selectionGestureDetectorBuilder . buildGestureDetector (
behavior : HitTestBehavior . translucent ,
child : child
) ;
}
}
}