@@ -103,11 +103,12 @@ class Tooltip extends StatefulWidget {
103103 this .excludeFromSemantics,
104104 this .decoration,
105105 this .textStyle,
106+ this .textAlign,
106107 this .waitDuration,
107108 this .showDuration,
108- this .child,
109109 this .triggerMode,
110110 this .enableFeedback,
111+ this .child,
111112 }) : assert ((message == null ) != (richMessage == null ), 'Either `message` or `richMessage` must be specified' ),
112113 assert (
113114 richMessage == null || textStyle == null ,
@@ -197,6 +198,13 @@ class Tooltip extends StatefulWidget {
197198 /// used with [Colors.black] .
198199 final TextStyle ? textStyle;
199200
201+ /// How the message of the tooltip is aligned horizontally.
202+ ///
203+ /// If this property is null, then [TooltipThemeData.textAlign] is used.
204+ /// If [TooltipThemeData.textAlign] is also null, the default value is
205+ /// [TextAlign.start] .
206+ final TextAlign ? textAlign;
207+
200208 /// The length of time that a pointer must hover over a tooltip's widget
201209 /// before the tooltip will be shown.
202210 ///
@@ -298,6 +306,7 @@ class Tooltip extends StatefulWidget {
298306 properties.add (DiagnosticsProperty <Duration >('show duration' , showDuration, defaultValue: null ));
299307 properties.add (DiagnosticsProperty <TooltipTriggerMode >('triggerMode' , triggerMode, defaultValue: null ));
300308 properties.add (FlagProperty ('enableFeedback' , value: enableFeedback, ifTrue: 'true' , showName: true ));
309+ properties.add (DiagnosticsProperty <TextAlign >('textAlign' , textAlign, defaultValue: null ));
301310 }
302311}
303312
@@ -317,12 +326,14 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
317326 static const bool _defaultExcludeFromSemantics = false ;
318327 static const TooltipTriggerMode _defaultTriggerMode = TooltipTriggerMode .longPress;
319328 static const bool _defaultEnableFeedback = true ;
329+ static const TextAlign _defaultTextAlign = TextAlign .start;
320330
321331 late double _height;
322332 late EdgeInsetsGeometry _padding;
323333 late EdgeInsetsGeometry _margin;
324334 late Decoration _decoration;
325335 late TextStyle _textStyle;
336+ late TextAlign _textAlign;
326337 late double _verticalOffset;
327338 late bool _preferBelow;
328339 late bool _excludeFromSemantics;
@@ -570,6 +581,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
570581 onExit: _mouseIsConnected ? (_) => _handleMouseExit () : null ,
571582 decoration: _decoration,
572583 textStyle: _textStyle,
584+ textAlign: _textAlign,
573585 animation: CurvedAnimation (
574586 parent: _controller,
575587 curve: Curves .fastOutSlowIn,
@@ -691,6 +703,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
691703 _excludeFromSemantics = widget.excludeFromSemantics ?? tooltipTheme.excludeFromSemantics ?? _defaultExcludeFromSemantics;
692704 _decoration = widget.decoration ?? tooltipTheme.decoration ?? defaultDecoration;
693705 _textStyle = widget.textStyle ?? tooltipTheme.textStyle ?? defaultTextStyle;
706+ _textAlign = widget.textAlign ?? tooltipTheme.textAlign ?? _defaultTextAlign;
694707 _waitDuration = widget.waitDuration ?? tooltipTheme.waitDuration ?? _defaultWaitDuration;
695708 _showDuration = widget.showDuration ?? tooltipTheme.showDuration ?? _defaultShowDuration;
696709 _hoverShowDuration = widget.showDuration ?? tooltipTheme.showDuration ?? _defaultHoverShowDuration;
@@ -786,6 +799,7 @@ class _TooltipOverlay extends StatelessWidget {
786799 this .margin,
787800 this .decoration,
788801 this .textStyle,
802+ this .textAlign,
789803 required this .animation,
790804 required this .target,
791805 required this .verticalOffset,
@@ -800,6 +814,7 @@ class _TooltipOverlay extends StatelessWidget {
800814 final EdgeInsetsGeometry ? margin;
801815 final Decoration ? decoration;
802816 final TextStyle ? textStyle;
817+ final TextAlign ? textAlign;
803818 final Animation <double > animation;
804819 final Offset target;
805820 final double verticalOffset;
@@ -826,6 +841,7 @@ class _TooltipOverlay extends StatelessWidget {
826841 child: Text .rich (
827842 richMessage,
828843 style: textStyle,
844+ textAlign: textAlign,
829845 ),
830846 ),
831847 ),
0 commit comments