update flutter widgets

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-11-19 13:39:01 +08:00
parent 1fb798db4e
commit 725d7055bf
80 changed files with 493 additions and 455 deletions

View File

@@ -21,9 +21,6 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
// Examples can assume:
// late BuildContext context;
abstract class _ParentInkResponseState {
void markChildInkResponsePressed(
_ParentInkResponseState childState,
@@ -144,6 +141,7 @@ class InkResponse extends StatelessWidget {
this.onTapCancel,
this.onDoubleTap,
this.onLongPress,
this.onLongPressUp,
this.onSecondaryTap,
this.onSecondaryTapUp,
this.onSecondaryTapDown,
@@ -197,6 +195,19 @@ class InkResponse extends StatelessWidget {
/// Called when the user long-presses on this part of the material.
final GestureLongPressCallback? onLongPress;
/// Called when the user lifts their finger after a long press on the button.
///
/// This callback is triggered at the end of a long press gesture, specifically
/// after the user holds a long press and then releases it. It does not include
/// position details.
///
/// Common use cases include performing an action only after the long press completes,
/// such as displaying a context menu or confirming a held gesture.
///
/// See also:
/// * [onLongPress], which is triggered when the long press gesture is first recognized.
final GestureLongPressUpCallback? onLongPressUp;
/// Called when the user taps this part of the material with a secondary button.
///
/// See also:
@@ -237,7 +248,7 @@ class InkResponse extends StatelessWidget {
/// become highlighted and false if this part of the material has stopped
/// being highlighted.
///
/// If all of [onTap], [onDoubleTap], and [onLongPress] become null while a
/// If all of [onTap], [onDoubleTap], [onLongPress], and [onLongPressUp] become null while a
/// gesture is ongoing, then [onTapCancel] will be fired and
/// [onHighlightChanged] will be fired with the value false _during the
/// build_. This means, for instance, that in that scenario [State.setState]
@@ -493,6 +504,7 @@ class InkResponse extends StatelessWidget {
onTapCancel: onTapCancel,
onDoubleTap: onDoubleTap,
onLongPress: onLongPress,
onLongPressUp: onLongPressUp,
onSecondaryTap: onSecondaryTap,
onSecondaryTapUp: onSecondaryTapUp,
onSecondaryTapDown: onSecondaryTapDown,
@@ -550,6 +562,7 @@ class _InkResponseStateWidget extends StatefulWidget {
this.onTapCancel,
this.onDoubleTap,
this.onLongPress,
this.onLongPressUp,
this.onSecondaryTap,
this.onSecondaryTapUp,
this.onSecondaryTapDown,
@@ -588,6 +601,7 @@ class _InkResponseStateWidget extends StatefulWidget {
final GestureTapCallback? onTapCancel;
final GestureTapCallback? onDoubleTap;
final GestureLongPressCallback? onLongPress;
final GestureLongPressUpCallback? onLongPressUp;
final GestureTapCallback? onSecondaryTap;
final GestureTapUpCallback? onSecondaryTapUp;
final GestureTapDownCallback? onSecondaryTapDown;
@@ -628,6 +642,7 @@ class _InkResponseStateWidget extends StatefulWidget {
if (onTap != null) 'tap',
if (onDoubleTap != null) 'double tap',
if (onLongPress != null) 'long press',
if (onLongPressUp != null) 'long press up',
if (onTapDown != null) 'tap down',
if (onTapUp != null) 'tap up',
if (onTapCancel != null) 'tap cancel',
@@ -1099,6 +1114,12 @@ class _InkResponseState extends State<_InkResponseStateWidget>
}
}
void handleLongPressUp() {
_currentSplash?.confirm();
_currentSplash = null;
widget.onLongPressUp?.call();
}
void handleSecondaryTap() {
_currentSplash?.confirm();
_currentSplash = null;
@@ -1140,6 +1161,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
return widget.onTap != null ||
widget.onDoubleTap != null ||
widget.onLongPress != null ||
widget.onLongPressUp != null ||
widget.onTapUp != null ||
widget.onTapDown != null;
}
@@ -1276,6 +1298,9 @@ class _InkResponseState extends State<_InkResponseStateWidget>
onLongPress: widget.onLongPress != null
? handleLongPress
: null,
onLongPressUp: widget.onLongPressUp != null
? handleLongPressUp
: null,
onSecondaryTapDown: _secondaryEnabled
? handleSecondaryTapDown
: null,
@@ -1387,6 +1412,7 @@ class InkWell extends InkResponse {
super.onTap,
super.onDoubleTap,
super.onLongPress,
super.onLongPressUp,
super.onTapDown,
super.onTapUp,
super.onTapCancel,

View File

@@ -914,10 +914,7 @@ class ListTile extends StatelessWidget {
WidgetState.disabled,
};
final MouseCursor effectiveMouseCursor =
WidgetStateProperty.resolveAs<MouseCursor?>(
mouseCursor,
mouseStates,
) ??
WidgetStateProperty.resolveAs<MouseCursor?>(mouseCursor, mouseStates) ??
tileTheme.mouseCursor?.resolve(mouseStates) ??
WidgetStateMouseCursor.clickable.resolve(mouseStates);
@@ -1330,12 +1327,7 @@ class _RenderListTile extends RenderBox
@override
Iterable<RenderBox> get children {
final RenderBox? title = childForSlot(_ListTileSlot.title);
return <RenderBox>[
?leading,
?title,
?subtitle,
?trailing,
];
return <RenderBox>[?leading, ?title, ?subtitle, ?trailing];
}
bool get isDense => _isDense;

View File

@@ -19,13 +19,14 @@ library;
import 'dart:async';
import 'dart:math' as math;
import 'package:PiliPlus/common/widgets/flutter/page/scrollable_helpers.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart' hide Scrollable, ScrollableState;
import 'package:flutter/material.dart'
hide Scrollable, ScrollableState, EdgeDraggingAutoScroller;
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
export 'package:flutter/physics.dart' show Tolerance;
@@ -933,7 +934,7 @@ class CustomScrollableState extends State<CustomScrollable>
if (_animController.value * _maxWidth +
(_isRTL ? (_maxWidth - dx) : dx) >=
100) {
Get.back();
Navigator.pop(context);
} else {
_animController.reverse();
}
@@ -1937,7 +1938,7 @@ class _RenderScrollSemantics extends RenderProxyBox {
if (child.isTagged(RenderViewport.excludeFromScrolling)) {
excluded.add(child);
} else {
if (!child.hasFlag(SemanticsFlag.isHidden)) {
if (!child.flagsCollection.isHidden) {
firstVisibleIndex ??= child.indexInParent;
}
included.add(child);
@@ -1982,222 +1983,3 @@ class _RestorableScrollOffset extends RestorableValue<double?> {
@override
bool get enabled => value != null;
}
// 2D SCROLLING
/// Specifies how to configure the [DragGestureRecognizer]s of a
/// [TwoDimensionalScrollable].
// TODO(Piinks): Add sample code, https://github.com/flutter/flutter/issues/126298
enum DiagonalDragBehavior {
/// This behavior will not allow for any diagonal scrolling.
///
/// Drag gestures in one direction or the other will lock the input axis until
/// the gesture is released.
none,
/// This behavior will only allow diagonal scrolling on a weighted
/// scale per gesture event.
///
/// This means that after initially evaluating the drag gesture, the weighted
/// evaluation (based on [kTouchSlop]) stands until the gesture is released.
weightedEvent,
/// This behavior will only allow diagonal scrolling on a weighted
/// scale that is evaluated throughout a gesture event.
///
/// This means that during each update to the drag gesture, the scrolling
/// axis will be allowed to scroll diagonally if it exceeds the
/// [kTouchSlop].
weightedContinuous,
/// This behavior allows free movement in any and all directions when
/// dragging.
free,
}
/// An auto scroller that scrolls the [scrollable] if a drag gesture drags close
/// to its edge.
///
/// The scroll velocity is controlled by the [velocityScalar]:
///
/// velocity = (distance of overscroll) * [velocityScalar].
class EdgeDraggingAutoScroller {
/// Creates a auto scroller that scrolls the [scrollable].
EdgeDraggingAutoScroller(
this.scrollable, {
this.onScrollViewScrolled,
required this.velocityScalar,
});
/// The [CustomScrollable] this auto scroller is scrolling.
final CustomScrollableState scrollable;
/// Called when a scroll view is scrolled.
///
/// The scroll view may be scrolled multiple times in a row until the drag
/// target no longer triggers the auto scroll. This callback will be called
/// in between each scroll.
final VoidCallback? onScrollViewScrolled;
/// {@template flutter.widgets.EdgeDraggingAutoScroller.velocityScalar}
/// The velocity scalar per pixel over scroll.
///
/// It represents how the velocity scale with the over scroll distance. The
/// auto-scroll velocity = (distance of overscroll) * velocityScalar.
/// {@endtemplate}
final double velocityScalar;
late Rect _dragTargetRelatedToScrollOrigin;
/// Whether the auto scroll is in progress.
bool get scrolling => _scrolling;
bool _scrolling = false;
double _offsetExtent(Offset offset, Axis scrollDirection) {
return switch (scrollDirection) {
Axis.horizontal => offset.dx,
Axis.vertical => offset.dy,
};
}
double _sizeExtent(Size size, Axis scrollDirection) {
return switch (scrollDirection) {
Axis.horizontal => size.width,
Axis.vertical => size.height,
};
}
AxisDirection get _axisDirection => scrollable.axisDirection;
Axis get _scrollDirection => axisDirectionToAxis(_axisDirection);
/// Starts the auto scroll if the [dragTarget] is close to the edge.
///
/// The scroll starts to scroll the [scrollable] if the target rect is close
/// to the edge of the [scrollable]; otherwise, it remains stationary.
///
/// If the scrollable is already scrolling, calling this method updates the
/// previous dragTarget to the new value and continues scrolling if necessary.
void startAutoScrollIfNecessary(Rect dragTarget) {
final Offset deltaToOrigin = scrollable.deltaToScrollOrigin;
_dragTargetRelatedToScrollOrigin = dragTarget.translate(
deltaToOrigin.dx,
deltaToOrigin.dy,
);
if (_scrolling) {
// The change will be picked up in the next scroll.
return;
}
assert(!_scrolling);
_scroll();
}
/// Stop any ongoing auto scrolling.
void stopAutoScroll() {
_scrolling = false;
}
Future<void> _scroll() async {
final RenderBox scrollRenderBox =
scrollable.context.findRenderObject()! as RenderBox;
final Rect globalRect = MatrixUtils.transformRect(
scrollRenderBox.getTransformTo(null),
Rect.fromLTWH(
0,
0,
scrollRenderBox.size.width,
scrollRenderBox.size.height,
),
);
assert(
globalRect.size.width >= _dragTargetRelatedToScrollOrigin.size.width &&
globalRect.size.height >=
_dragTargetRelatedToScrollOrigin.size.height,
'Drag target size is larger than scrollable size, which may cause bouncing',
);
_scrolling = true;
double? newOffset;
const double overDragMax = 20.0;
final Offset deltaToOrigin = scrollable.deltaToScrollOrigin;
final Offset viewportOrigin = globalRect.topLeft.translate(
deltaToOrigin.dx,
deltaToOrigin.dy,
);
final double viewportStart = _offsetExtent(
viewportOrigin,
_scrollDirection,
);
final double viewportEnd =
viewportStart + _sizeExtent(globalRect.size, _scrollDirection);
final double proxyStart = _offsetExtent(
_dragTargetRelatedToScrollOrigin.topLeft,
_scrollDirection,
);
final double proxyEnd = _offsetExtent(
_dragTargetRelatedToScrollOrigin.bottomRight,
_scrollDirection,
);
switch (_axisDirection) {
case AxisDirection.up:
case AxisDirection.left:
if (proxyEnd > viewportEnd &&
scrollable.position.pixels > scrollable.position.minScrollExtent) {
final double overDrag = math.min(proxyEnd - viewportEnd, overDragMax);
newOffset = math.max(
scrollable.position.minScrollExtent,
scrollable.position.pixels - overDrag,
);
} else if (proxyStart < viewportStart &&
scrollable.position.pixels < scrollable.position.maxScrollExtent) {
final double overDrag = math.min(
viewportStart - proxyStart,
overDragMax,
);
newOffset = math.min(
scrollable.position.maxScrollExtent,
scrollable.position.pixels + overDrag,
);
}
case AxisDirection.right:
case AxisDirection.down:
if (proxyStart < viewportStart &&
scrollable.position.pixels > scrollable.position.minScrollExtent) {
final double overDrag = math.min(
viewportStart - proxyStart,
overDragMax,
);
newOffset = math.max(
scrollable.position.minScrollExtent,
scrollable.position.pixels - overDrag,
);
} else if (proxyEnd > viewportEnd &&
scrollable.position.pixels < scrollable.position.maxScrollExtent) {
final double overDrag = math.min(proxyEnd - viewportEnd, overDragMax);
newOffset = math.min(
scrollable.position.maxScrollExtent,
scrollable.position.pixels + overDrag,
);
}
}
if (newOffset == null ||
(newOffset - scrollable.position.pixels).abs() < 1.0) {
// Drag should not trigger scroll.
_scrolling = false;
return;
}
final Duration duration = Duration(
milliseconds: (1000 / velocityScalar).round(),
);
await scrollable.position.animateTo(
newOffset,
duration: duration,
curve: Curves.linear,
);
onScrollViewScrolled?.call();
if (_scrolling) {
await _scroll();
}
}
}

View File

@@ -0,0 +1,210 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// @docImport 'package:flutter/material.dart';
///
/// @docImport 'overscroll_indicator.dart';
/// @docImport 'viewport.dart';
// ignore_for_file: dangling_library_doc_comments
import 'dart:math' as math;
import 'package:PiliPlus/common/widgets/flutter/page/scrollable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
/// An auto scroller that scrolls the [scrollable] if a drag gesture drags close
/// to its edge.
///
/// The scroll velocity is controlled by the [velocityScalar]:
///
/// velocity = (distance of overscroll) * [velocityScalar].
class EdgeDraggingAutoScroller {
/// Creates a auto scroller that scrolls the [scrollable].
EdgeDraggingAutoScroller(
this.scrollable, {
this.onScrollViewScrolled,
required this.velocityScalar,
});
/// The [CustomScrollable] this auto scroller is scrolling.
final CustomScrollableState scrollable;
/// Called when a scroll view is scrolled.
///
/// The scroll view may be scrolled multiple times in a row until the drag
/// target no longer triggers the auto scroll. This callback will be called
/// in between each scroll.
final VoidCallback? onScrollViewScrolled;
/// {@template flutter.widgets.EdgeDraggingAutoScroller.velocityScalar}
/// The velocity scalar per pixel over scroll.
///
/// It represents how the velocity scale with the over scroll distance. The
/// auto-scroll velocity = (distance of overscroll) * velocityScalar.
/// {@endtemplate}
final double velocityScalar;
late Rect _dragTargetRelatedToScrollOrigin;
/// Whether the auto scroll is in progress.
bool get scrolling => _scrolling;
bool _scrolling = false;
double _offsetExtent(Offset offset, Axis scrollDirection) {
return switch (scrollDirection) {
Axis.horizontal => offset.dx,
Axis.vertical => offset.dy,
};
}
double _sizeExtent(Size size, Axis scrollDirection) {
return switch (scrollDirection) {
Axis.horizontal => size.width,
Axis.vertical => size.height,
};
}
AxisDirection get _axisDirection => scrollable.axisDirection;
Axis get _scrollDirection => axisDirectionToAxis(_axisDirection);
/// Starts the auto scroll if the [dragTarget] is close to the edge.
///
/// The scroll starts to scroll the [scrollable] if the target rect is close
/// to the edge of the [scrollable]; otherwise, it remains stationary.
///
/// If the scrollable is already scrolling, calling this method updates the
/// previous dragTarget to the new value and continues scrolling if necessary.
void startAutoScrollIfNecessary(Rect dragTarget) {
final Offset deltaToOrigin = scrollable.deltaToScrollOrigin;
_dragTargetRelatedToScrollOrigin = dragTarget.translate(
deltaToOrigin.dx,
deltaToOrigin.dy,
);
if (_scrolling) {
// The change will be picked up in the next scroll.
return;
}
assert(!_scrolling);
_scroll();
}
/// Stop any ongoing auto scrolling.
void stopAutoScroll() {
_scrolling = false;
}
Future<void> _scroll() async {
final RenderBox scrollRenderBox =
scrollable.context.findRenderObject()! as RenderBox;
final Matrix4 transform = scrollRenderBox.getTransformTo(null);
final Rect globalRect = MatrixUtils.transformRect(
transform,
Rect.fromLTWH(
0,
0,
scrollRenderBox.size.width,
scrollRenderBox.size.height,
),
);
final Rect transformedDragTarget = MatrixUtils.transformRect(
transform,
_dragTargetRelatedToScrollOrigin,
);
assert(
(globalRect.size.width + precisionErrorTolerance) >=
transformedDragTarget.size.width &&
(globalRect.size.height + precisionErrorTolerance) >=
transformedDragTarget.size.height,
'Drag target size is larger than scrollable size, which may cause bouncing',
);
_scrolling = true;
double? newOffset;
const double overDragMax = 20.0;
final Offset deltaToOrigin = scrollable.deltaToScrollOrigin;
final Offset viewportOrigin = globalRect.topLeft.translate(
deltaToOrigin.dx,
deltaToOrigin.dy,
);
final double viewportStart = _offsetExtent(
viewportOrigin,
_scrollDirection,
);
final double viewportEnd =
viewportStart + _sizeExtent(globalRect.size, _scrollDirection);
final double proxyStart = _offsetExtent(
_dragTargetRelatedToScrollOrigin.topLeft,
_scrollDirection,
);
final double proxyEnd = _offsetExtent(
_dragTargetRelatedToScrollOrigin.bottomRight,
_scrollDirection,
);
switch (_axisDirection) {
case AxisDirection.up:
case AxisDirection.left:
if (proxyEnd > viewportEnd &&
scrollable.position.pixels > scrollable.position.minScrollExtent) {
final double overDrag = math.min(proxyEnd - viewportEnd, overDragMax);
newOffset = math.max(
scrollable.position.minScrollExtent,
scrollable.position.pixels - overDrag,
);
} else if (proxyStart < viewportStart &&
scrollable.position.pixels < scrollable.position.maxScrollExtent) {
final double overDrag = math.min(
viewportStart - proxyStart,
overDragMax,
);
newOffset = math.min(
scrollable.position.maxScrollExtent,
scrollable.position.pixels + overDrag,
);
}
case AxisDirection.right:
case AxisDirection.down:
if (proxyStart < viewportStart &&
scrollable.position.pixels > scrollable.position.minScrollExtent) {
final double overDrag = math.min(
viewportStart - proxyStart,
overDragMax,
);
newOffset = math.max(
scrollable.position.minScrollExtent,
scrollable.position.pixels - overDrag,
);
} else if (proxyEnd > viewportEnd &&
scrollable.position.pixels < scrollable.position.maxScrollExtent) {
final double overDrag = math.min(proxyEnd - viewportEnd, overDragMax);
newOffset = math.min(
scrollable.position.maxScrollExtent,
scrollable.position.pixels + overDrag,
);
}
}
if (newOffset == null ||
(newOffset - scrollable.position.pixels).abs() < 1.0) {
// Drag should not trigger scroll.
_scrolling = false;
return;
}
final Duration duration = Duration(
milliseconds: (1000 / velocityScalar).round(),
);
await scrollable.position.animateTo(
newOffset,
duration: duration,
curve: Curves.linear,
);
onScrollViewScrolled?.call();
if (_scrolling) {
await _scroll();
}
}
}

View File

@@ -1,3 +1,12 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: uri_does_not_exist_in_doc_import
/// @docImport 'color_scheme.dart';
library;
import 'dart:async';
import 'dart:math' as math;
@@ -6,25 +15,10 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show clampDouble;
import 'package:flutter/material.dart' hide RefreshIndicator;
Widget refreshIndicator({
required RefreshCallback onRefresh,
required Widget child,
}) {
return RefreshIndicator(
displacement: displacement,
onRefresh: onRefresh,
child: child,
);
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
double displacement = Pref.refreshDisplacement;
// The over-scroll distance that moves the indicator to its maximum
// displacement, as a percentage of the scrollable's container extent.
double displacement = Pref.refreshDisplacement;
double kDragContainerExtentPercentage = Pref.refreshDragPercentage;
// How much the scroll's drag gesture can overshoot the RefreshIndicator's
@@ -762,3 +756,14 @@ class RefreshIndicatorState extends State<RefreshIndicator>
);
}
}
Widget refreshIndicator({
required RefreshCallback onRefresh,
required Widget child,
}) {
return RefreshIndicator(
displacement: displacement,
onRefresh: onRefresh,
child: child,
);
}

View File

@@ -9,7 +9,6 @@
/// @docImport 'editable.dart';
library;
import 'dart:collection';
import 'dart:math' as math;
import 'dart:ui'
as ui
@@ -46,6 +45,15 @@ typedef _TextBoundaryAtPositionInText =
const String _kEllipsis = '\u2026';
class _UnspecifiedTextScaler extends TextScaler {
const _UnspecifiedTextScaler();
@override
Never get textScaleFactor => throw UnimplementedError();
@override
Never scale(double fontSize) => throw UnimplementedError();
}
/// A render object that displays a paragraph of text.
class RenderParagraph extends RenderBox
with
@@ -68,7 +76,7 @@ class RenderParagraph extends RenderBox
'This feature was deprecated after v3.12.0-2.0.pre.',
)
double textScaleFactor = 1.0,
TextScaler textScaler = TextScaler.noScaling,
TextScaler textScaler = const _UnspecifiedTextScaler(),
int? maxLines,
Locale? locale,
StrutStyle? strutStyle,
@@ -80,26 +88,22 @@ class RenderParagraph extends RenderBox
required Color primary,
VoidCallback? onShowMore,
}) : assert(text.debugAssertIsValid()),
assert(maxLines == null || maxLines > 0),
assert(
maxLines == null ||
(maxLines > 0 &&
overflow != TextOverflow.ellipsis &&
overflow != TextOverflow.fade),
),
assert(
identical(textScaler, TextScaler.noScaling) || textScaleFactor == 1.0,
identical(textScaler, const _UnspecifiedTextScaler()) ||
textScaleFactor == 1.0,
'textScaleFactor is deprecated and cannot be specified when textScaler is specified.',
),
_primary = primary,
_onShowMore = onShowMore,
_softWrap = softWrap,
_overflow = overflow,
_selectionColor = selectionColor,
_onShowMore = onShowMore,
_textPainter = TextPainter(
text: text,
textAlign: textAlign,
textDirection: textDirection,
textScaler: textScaler == TextScaler.noScaling
textScaler: textScaler == const _UnspecifiedTextScaler()
? TextScaler.linear(textScaleFactor)
: textScaler,
maxLines: maxLines,
@@ -842,6 +846,11 @@ class RenderParagraph extends RenderBox
}
}
assert(() {
_textPainter.debugPaintTextLayoutBoxes = debugPaintTextLayoutBoxes;
return true;
}());
_textPainter.paint(context.canvas, offset);
paintInlineChildren(context, offset);
@@ -1013,8 +1022,9 @@ class RenderParagraph extends RenderBox
}
if (needsAssembleSemanticsNode) {
config.explicitChildNodes = true;
config.isSemanticBoundary = true;
config
..explicitChildNodes = true
..isSemanticBoundary = true;
} else if (needsChildConfigurationsDelegate) {
config.childConfigurationsDelegate =
_childSemanticsConfigurationsDelegate;
@@ -1043,8 +1053,9 @@ class RenderParagraph extends RenderBox
AttributedString(buffer.toString(), attributes: attributes),
];
}
config.attributedLabel = _cachedAttributedLabels![0];
config.textDirection = textDirection;
config
..attributedLabel = _cachedAttributedLabels![0]
..textDirection = textDirection;
}
}
@@ -1126,7 +1137,7 @@ class RenderParagraph extends RenderBox
// can be re-used when [assembleSemanticsNode] is called again. This ensures
// stable ids for the [SemanticsNode]s of [TextSpan]s across
// [assembleSemanticsNode] invocations.
LinkedHashMap<Key, SemanticsNode>? _cachedChildNodes;
Map<Key, SemanticsNode>? _cachedChildNodes;
@override
void assembleSemanticsNode(
@@ -1143,8 +1154,7 @@ class RenderParagraph extends RenderBox
int placeholderIndex = 0;
int childIndex = 0;
RenderBox? child = firstChild;
final LinkedHashMap<Key, SemanticsNode> newChildCache =
LinkedHashMap<Key, SemanticsNode>();
final Map<Key, SemanticsNode> newChildCache = <Key, SemanticsNode>{};
_cachedCombinedSemanticsInfos ??= combineSemanticsInfo(_semanticsInfo!);
for (final InlineSpanSemanticsInformation info
in _cachedCombinedSemanticsInfos!) {
@@ -1214,8 +1224,9 @@ class RenderParagraph extends RenderBox
onDoubleTap: final VoidCallback? handler,
):
if (handler != null) {
configuration.onTap = handler;
configuration.isLink = true;
configuration
..onTap = handler
..isLink = true;
}
case LongPressGestureRecognizer(
onLongPress: final GestureLongPressCallback? onLongPress,
@@ -1285,29 +1296,30 @@ class RenderParagraph extends RenderBox
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(EnumProperty<TextAlign>('textAlign', textAlign));
properties.add(EnumProperty<TextDirection>('textDirection', textDirection));
properties.add(
FlagProperty(
'softWrap',
value: softWrap,
ifTrue: 'wrapping at box width',
ifFalse: 'no wrapping except at line break characters',
showName: true,
),
);
properties.add(EnumProperty<TextOverflow>('overflow', overflow));
properties.add(
DiagnosticsProperty<TextScaler>(
'textScaler',
textScaler,
defaultValue: TextScaler.noScaling,
),
);
properties.add(
DiagnosticsProperty<Locale>('locale', locale, defaultValue: null),
);
properties.add(IntProperty('maxLines', maxLines, ifNull: 'unlimited'));
properties
..add(EnumProperty<TextAlign>('textAlign', textAlign))
..add(EnumProperty<TextDirection>('textDirection', textDirection))
..add(
FlagProperty(
'softWrap',
value: softWrap,
ifTrue: 'wrapping at box width',
ifFalse: 'no wrapping except at line break characters',
showName: true,
),
)
..add(EnumProperty<TextOverflow>('overflow', overflow))
..add(
DiagnosticsProperty<TextScaler>(
'textScaler',
textScaler,
defaultValue: TextScaler.noScaling,
),
)
..add(
DiagnosticsProperty<Locale>('locale', locale, defaultValue: null),
)
..add(IntProperty('maxLines', maxLines, ifNull: 'unlimited'));
}
}
@@ -1768,8 +1780,7 @@ class _SelectableFragment
final TextPosition? existingSelectionEnd = _textSelectionEnd;
_setSelectionPosition(null, isEnd: isEnd);
final Matrix4 transform = paragraph.getTransformTo(null);
transform.invert();
final Matrix4 transform = paragraph.getTransformTo(null)..invert();
final Offset localPosition = MatrixUtils.transformPoint(
transform,
globalPosition,
@@ -1842,8 +1853,7 @@ class _SelectableFragment
required bool isEnd,
}) {
_setSelectionPosition(null, isEnd: isEnd);
final Matrix4 transform = paragraph.getTransformTo(null);
transform.invert();
final Matrix4 transform = paragraph.getTransformTo(null)..invert();
final Offset localPosition = MatrixUtils.transformPoint(
transform,
globalPosition,
@@ -2348,8 +2358,8 @@ class _SelectableFragment
existingSelectionEnd,
);
}
final Matrix4 originTransform = originParagraph.getTransformTo(null);
originTransform.invert();
final Matrix4 originTransform = originParagraph.getTransformTo(null)
..invert();
final Offset originParagraphLocalPosition = MatrixUtils.transformPoint(
originTransform,
globalPosition,
@@ -2653,8 +2663,8 @@ class _SelectableFragment
existingSelectionEnd,
);
}
final Matrix4 originTransform = originParagraph.getTransformTo(null);
originTransform.invert();
final Matrix4 originTransform = originParagraph.getTransformTo(null)
..invert();
final Offset originParagraphLocalPosition = MatrixUtils.transformPoint(
originTransform,
globalPosition,
@@ -3116,8 +3126,7 @@ class _SelectableFragment
RenderObject? current = paragraph;
while (current != null) {
if (current is RenderParagraph) {
final Matrix4 currentTransform = current.getTransformTo(null);
currentTransform.invert();
final Matrix4 currentTransform = current.getTransformTo(null)..invert();
final Offset currentParagraphLocalPosition = MatrixUtils.transformPoint(
currentTransform,
globalPosition,
@@ -3809,13 +3818,14 @@ class _SelectableFragment
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
DiagnosticsProperty<String>(
'textInsideRange',
range.textInside(fullText),
),
);
properties.add(DiagnosticsProperty<TextRange>('range', range));
properties.add(DiagnosticsProperty<String>('fullText', fullText));
properties
..add(
DiagnosticsProperty<String>(
'textInsideRange',
range.textInside(fullText),
),
)
..add(DiagnosticsProperty<TextRange>('range', range))
..add(DiagnosticsProperty<String>('fullText', fullText));
}
}

View File

@@ -1,4 +1,8 @@
import 'dart:ui' as ui;
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui show TextHeightBehavior;
import 'package:PiliPlus/common/widgets/flutter/text/paragraph.dart';
import 'package:flutter/material.dart';
@@ -280,68 +284,69 @@ class RichText extends MultiChildRenderObjectWidget {
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
EnumProperty<TextAlign>(
'textAlign',
textAlign,
defaultValue: TextAlign.start,
),
);
properties.add(
EnumProperty<TextDirection>(
'textDirection',
textDirection,
defaultValue: null,
),
);
properties.add(
FlagProperty(
'softWrap',
value: softWrap,
ifTrue: 'wrapping at box width',
ifFalse: 'no wrapping except at line break characters',
showName: true,
),
);
properties.add(
EnumProperty<TextOverflow>(
'overflow',
overflow,
defaultValue: TextOverflow.clip,
),
);
properties.add(
DiagnosticsProperty<TextScaler>(
'textScaler',
textScaler,
defaultValue: TextScaler.noScaling,
),
);
properties.add(IntProperty('maxLines', maxLines, ifNull: 'unlimited'));
properties.add(
EnumProperty<TextWidthBasis>(
'textWidthBasis',
textWidthBasis,
defaultValue: TextWidthBasis.parent,
),
);
properties.add(StringProperty('text', text.toPlainText()));
properties.add(
DiagnosticsProperty<Locale>('locale', locale, defaultValue: null),
);
properties.add(
DiagnosticsProperty<StrutStyle>(
'strutStyle',
strutStyle,
defaultValue: null,
),
);
properties.add(
DiagnosticsProperty<TextHeightBehavior>(
'textHeightBehavior',
textHeightBehavior,
defaultValue: null,
),
);
properties
..add(
EnumProperty<TextAlign>(
'textAlign',
textAlign,
defaultValue: TextAlign.start,
),
)
..add(
EnumProperty<TextDirection>(
'textDirection',
textDirection,
defaultValue: null,
),
)
..add(
FlagProperty(
'softWrap',
value: softWrap,
ifTrue: 'wrapping at box width',
ifFalse: 'no wrapping except at line break characters',
showName: true,
),
)
..add(
EnumProperty<TextOverflow>(
'overflow',
overflow,
defaultValue: TextOverflow.clip,
),
)
..add(
DiagnosticsProperty<TextScaler>(
'textScaler',
textScaler,
defaultValue: TextScaler.noScaling,
),
)
..add(IntProperty('maxLines', maxLines, ifNull: 'unlimited'))
..add(
EnumProperty<TextWidthBasis>(
'textWidthBasis',
textWidthBasis,
defaultValue: TextWidthBasis.parent,
),
)
..add(StringProperty('text', text.toPlainText()))
..add(
DiagnosticsProperty<Locale>('locale', locale, defaultValue: null),
)
..add(
DiagnosticsProperty<StrutStyle>(
'strutStyle',
strutStyle,
defaultValue: null,
),
)
..add(
DiagnosticsProperty<TextHeightBehavior>(
'textHeightBehavior',
textHeightBehavior,
defaultValue: null,
),
);
}
}

View File

@@ -47,7 +47,11 @@ import 'package:flutter/rendering.dart' hide RenderParagraph;
/// Container(
/// width: 100,
/// decoration: BoxDecoration(border: Border.all()),
/// child: Text(overflow: TextOverflow.ellipsis, 'Hello $_name, how are you?'))
/// child: const Text(
/// 'Hello, how are you?',
/// overflow: TextOverflow.ellipsis,
/// ),
/// )
/// ```
/// {@end-tool}
///
@@ -60,10 +64,11 @@ import 'package:flutter/rendering.dart' hide RenderParagraph;
/// ![If a second line overflows the Text widget displays a horizontal fade](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_fade_max_lines.png)
///
/// ```dart
/// Text(
/// const Text(
/// 'Hello, how are you?',
/// overflow: TextOverflow.fade,
/// maxLines: 1,
/// 'Hello $_name, how are you?')
/// )
/// ```
///
/// Here soft wrapping is enabled and the [Text] widget tries to wrap the words
@@ -74,10 +79,11 @@ import 'package:flutter/rendering.dart' hide RenderParagraph;
/// ![If a single line overflows the Text widget displays a horizontal fade](https://flutter.github.io/assets-for-api-docs/assets/widgets/text_fade_soft_wrap.png)
///
/// ```dart
/// Text(
/// const Text(
/// 'Hello, how are you?',
/// overflow: TextOverflow.fade,
/// softWrap: false,
/// 'Hello $_name, how are you?')
/// )
/// ```
///
/// Here soft wrapping is disabled with `softWrap: false` and the [Text] widget
@@ -410,6 +416,7 @@ class Text extends StatelessWidget {
text: TextSpan(
style: effectiveTextStyle,
text: data,
locale: locale,
children: textSpan != null ? <InlineSpan>[textSpan!] : null,
),
primary: primary,
@@ -442,6 +449,7 @@ class Text extends StatelessWidget {
text: TextSpan(
style: effectiveTextStyle,
text: data,
locale: locale,
children: textSpan != null ? <InlineSpan>[textSpan!] : null,
),
onShowMore: onShowMore,
@@ -1105,7 +1113,7 @@ class _SelectableTextContainerDelegate
bool forwardSelection =
currentSelectionEndIndex >= currentSelectionStartIndex;
if (currentSelectionEndIndex == currentSelectionStartIndex) {
// Determining selection direction is innacurate if currentSelectionStartIndex == currentSelectionEndIndex.
// Determining selection direction is inaccurate if currentSelectionStartIndex == currentSelectionEndIndex.
// Use the range from the selectable within the selection as the source of truth for selection direction.
final SelectedContentRange rangeAtSelectableInSelection =
selectables[currentSelectionStartIndex].getSelection()!;

View File

@@ -209,7 +209,7 @@ class CupertinoAdaptiveTextSelectionToolbar extends StatelessWidget {
@override
Widget build(BuildContext context) {
// If there aren't any buttons to build, build an empty toolbar.
if ((children?.isEmpty ?? false) || (buttonItems?.isEmpty ?? false)) {
if ((children ?? buttonItems)?.isEmpty ?? true) {
return const SizedBox.shrink();
}