CupertinoSwitch
: Add clickable cursor for web (#99554)
This commit is contained in:
parent
7b8135af0f
commit
4cea5ee0da
@ -298,19 +298,22 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
|
||||
Widget build(BuildContext context) {
|
||||
if (needsPositionAnimation)
|
||||
_resumePositionAnimation();
|
||||
return Opacity(
|
||||
opacity: widget.onChanged == null ? _kCupertinoSwitchDisabledOpacity : 1.0,
|
||||
child: _CupertinoSwitchRenderObjectWidget(
|
||||
value: widget.value,
|
||||
activeColor: CupertinoDynamicColor.resolve(
|
||||
widget.activeColor ?? CupertinoColors.systemGreen,
|
||||
context,
|
||||
return MouseRegion(
|
||||
cursor: isInteractive && kIsWeb ? SystemMouseCursors.click : MouseCursor.defer,
|
||||
child: Opacity(
|
||||
opacity: widget.onChanged == null ? _kCupertinoSwitchDisabledOpacity : 1.0,
|
||||
child: _CupertinoSwitchRenderObjectWidget(
|
||||
value: widget.value,
|
||||
activeColor: CupertinoDynamicColor.resolve(
|
||||
widget.activeColor ?? CupertinoColors.systemGreen,
|
||||
context,
|
||||
),
|
||||
trackColor: CupertinoDynamicColor.resolve(widget.trackColor ?? CupertinoColors.secondarySystemFill, context),
|
||||
thumbColor: CupertinoDynamicColor.resolve(widget.thumbColor ?? CupertinoColors.white, context),
|
||||
onChanged: widget.onChanged,
|
||||
textDirection: Directionality.of(context),
|
||||
state: this,
|
||||
),
|
||||
trackColor: CupertinoDynamicColor.resolve(widget.trackColor ?? CupertinoColors.secondarySystemFill, context),
|
||||
thumbColor: CupertinoDynamicColor.resolve(widget.thumbColor ?? CupertinoColors.white, context),
|
||||
onChanged: widget.onChanged,
|
||||
textDirection: Directionality.of(context),
|
||||
state: this,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -7,8 +7,10 @@
|
||||
@Tags(<String>['reduced-test-set'])
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@ -761,4 +763,61 @@ void main() {
|
||||
matchesGoldenFile('switch.tap.on.dark.png'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Hovering over Cupertino switch updates cursor to clickable on Web', (WidgetTester tester) async {
|
||||
const bool value = false;
|
||||
// Disabled CupertinoSwitch does not update cursor on Web.
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return const Center(
|
||||
child: CupertinoSwitch(
|
||||
value: value,
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onChanged: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
|
||||
final Offset cupertinoSwitch = tester.getCenter(find.byType(CupertinoSwitch));
|
||||
await gesture.addPointer(location: cupertinoSwitch);
|
||||
await tester.pumpAndSettle();
|
||||
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
|
||||
|
||||
// Enabled CupertinoSwitch updates cursor when hovering on Web.
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return Center(
|
||||
child: CupertinoSwitch(
|
||||
value: value,
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onChanged: (bool newValue) { },
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await gesture.moveTo(const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
|
||||
|
||||
await gesture.moveTo(cupertinoSwitch);
|
||||
addTearDown(gesture.removePointer);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
kIsWeb ? SystemMouseCursors.click : SystemMouseCursors.basic,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user