Unverified Commit 5d37734e authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Slight cleanup in PointerSignalResolver docs (#78817)

parent 720dac54
...@@ -29,7 +29,6 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) { ...@@ -29,7 +29,6 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) {
/// ///
/// To use this class, objects should register their event handler like so: /// To use this class, objects should register their event handler like so:
/// ///
/// {@tool snippet}
/// ```dart /// ```dart
/// void handleSignalEvent(PointerSignalEvent event) { /// void handleSignalEvent(PointerSignalEvent event) {
/// GestureBinding.instance!.pointerSignalResolver.register(event, (PointerSignalEvent event) { /// GestureBinding.instance!.pointerSignalResolver.register(event, (PointerSignalEvent event) {
...@@ -37,42 +36,83 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) { ...@@ -37,42 +36,83 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) {
/// }); /// });
/// } /// }
/// ``` /// ```
/// {@end-tool}
/// ///
/// {@tool dartpad --template=stateful_widget_material} /// {@tool dartpad --template=stateful_widget_material}
/// Here is an example that demonstrates the effect of not using the resolver /// Here is an example that demonstrates the effect of not using the resolver
/// versus using it. /// versus using it.
/// ///
/// When this example is set to _not_ use the resolver, then scrolling the /// When this example is set to _not_ use the resolver, then triggering the
/// mouse wheel over the outer box will cause only the outer box to change /// mouse wheel over the outer box will cause only the outer box to change
/// color, but scrolling the mouse wheel over inner box will cause _both_ the /// color, but triggering the mouse wheel over the inner box will cause _both_
/// outer and the inner boxes to change color (because they're both receiving /// the outer and the inner boxes to change color (because they're both
/// the scroll event). /// receiving the event).
/// ///
/// When this excample is set to _use_ the resolver, then only the box located /// When this example is set to _use_ the resolver, then only the box located
/// directly under the cursor will change color when the mouse wheel is /// directly under the cursor will change color when the mouse wheel is
/// scrolled. /// triggered.
/// ///
/// ```dart imports /// ```dart imports
/// import 'package:flutter/gestures.dart'; /// import 'package:flutter/gestures.dart';
/// ``` /// ```
/// ///
/// ```dart /// ```dart preamble
/// HSVColor outerColor = const HSVColor.fromAHSV(0.2, 120.0, 1, 1); /// class ColorChanger extends StatefulWidget {
/// HSVColor innerColor = const HSVColor.fromAHSV(1, 60.0, 1, 1); /// const ColorChanger({
/// bool useResolver = false; /// Key? key,
/// required this.initialColor,
/// required this.useResolver,
/// required this.child,
/// }) : super(key: key);
/// ///
/// void rotateOuterColor() { /// final HSVColor initialColor;
/// setState(() { /// final bool useResolver;
/// outerColor = outerColor.withHue((outerColor.hue + 6) % 360.0); /// final Widget child;
/// }); ///
/// @override
/// _ColorChangerState createState() => _ColorChangerState();
/// } /// }
/// ///
/// void rotateInnerColor() { /// class _ColorChangerState extends State<ColorChanger> {
/// setState(() { /// late HSVColor color;
/// innerColor = innerColor.withHue((innerColor.hue + 6) % 360.0); ///
/// }); /// void rotateColor() {
/// setState(() {
/// color = color.withHue((color.hue + 6) % 360.0);
/// });
/// }
///
/// @override
/// void initState() {
/// super.initState();
/// color = widget.initialColor;
/// }
///
/// @override
/// Widget build(BuildContext context) {
/// return DecoratedBox(
/// decoration: BoxDecoration(
/// border: const Border.fromBorderSide(BorderSide()),
/// color: color.toColor(),
/// ),
/// child: Listener(
/// onPointerSignal: (PointerSignalEvent event) {
/// if (widget.useResolver) {
/// GestureBinding.instance!.pointerSignalResolver.register(event, (PointerSignalEvent event) {
/// rotateColor();
/// });
/// } else {
/// rotateColor();
/// }
/// },
/// child: widget.child,
/// ),
/// );
/// }
/// } /// }
/// ```
///
/// ```dart
/// bool useResolver = false;
/// ///
/// @override /// @override
/// Widget build(BuildContext context) { /// Widget build(BuildContext context) {
...@@ -80,42 +120,16 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) { ...@@ -80,42 +120,16 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) {
/// child: Stack( /// child: Stack(
/// fit: StackFit.expand, /// fit: StackFit.expand,
/// children: <Widget>[ /// children: <Widget>[
/// Listener( /// ColorChanger(
/// onPointerSignal: (PointerSignalEvent event) { /// initialColor: const HSVColor.fromAHSV(0.2, 120.0, 1, 1),
/// if (useResolver) { /// useResolver: useResolver,
/// GestureBinding.instance!.pointerSignalResolver.register(event, (PointerSignalEvent event) { /// child: FractionallySizedBox(
/// rotateOuterColor(); /// widthFactor: 0.5,
/// }); /// heightFactor: 0.5,
/// } else { /// child: ColorChanger(
/// rotateOuterColor(); /// initialColor: const HSVColor.fromAHSV(1, 60.0, 1, 1),
/// } /// useResolver: useResolver,
/// }, /// child: const AbsorbPointer(),
/// child: DecoratedBox(
/// decoration: BoxDecoration(
/// border: const Border.fromBorderSide(BorderSide()),
/// color: outerColor.toColor(),
/// ),
/// child: FractionallySizedBox(
/// widthFactor: 0.5,
/// heightFactor: 0.5,
/// child: DecoratedBox(
/// decoration: BoxDecoration(
/// border: const Border.fromBorderSide(BorderSide()),
/// color: innerColor.toColor(),
/// ),
/// child: Listener(
/// onPointerSignal: (PointerSignalEvent event) {
/// if (useResolver) {
/// GestureBinding.instance!.pointerSignalResolver.register(event, (PointerSignalEvent event) {
/// rotateInnerColor();
/// });
/// } else {
/// rotateInnerColor();
/// }
/// },
/// child: const AbsorbPointer(),
/// ),
/// ),
/// ), /// ),
/// ), /// ),
/// ), /// ),
...@@ -132,9 +146,9 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) { ...@@ -132,9 +146,9 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) {
/// }); /// });
/// }, /// },
/// ), /// ),
/// Text( /// const Text(
/// 'Use the PointerSignalResolver?', /// 'Use the PointerSignalResolver?',
/// style: DefaultTextStyle.of(context).style.copyWith(fontWeight: FontWeight.bold), /// style: TextStyle(fontWeight: FontWeight.bold),
/// ), /// ),
/// ], /// ],
/// ), /// ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment