diff --git a/test/config/tilt_config_test.dart b/test/config/tilt_config_test.dart index 4167e0e..0989532 100644 --- a/test/config/tilt_config_test.dart +++ b/test/config/tilt_config_test.dart @@ -3,7 +3,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_tilt/src/config/tilt_config.dart'; void main() { - group('TiltConfig', () { + group('TiltConfig ::', () { test('copyWith', () { const TiltConfig tiltConfig = TiltConfig(); final TiltConfig tiltConfigExpect = TiltConfig( @@ -57,7 +57,7 @@ void main() { expect(tiltConfigCopyWith.hashCode, tiltConfigExpect.hashCode); }); }); - group('TiltDirection', () { + group('TiltDirection ::', () { test('value', () { final TiltDirection tiltDirection = -const TiltDirection(1.0, 1.0); expect(tiltDirection.dx, -1.0); diff --git a/test/config/tilt_light_config_test.dart b/test/config/tilt_light_config_test.dart index 50b026c..4559406 100644 --- a/test/config/tilt_light_config_test.dart +++ b/test/config/tilt_light_config_test.dart @@ -4,7 +4,7 @@ import 'package:flutter_tilt/src/config/tilt_light_config.dart'; import 'package:flutter_tilt/src/enums.dart'; void main() { - group('LightConfig', () { + group('LightConfig ::', () { test('assert', () { expect( () => LightConfig( diff --git a/test/config/tilt_shadow_config_test.dart b/test/config/tilt_shadow_config_test.dart index b130bbe..c8aed18 100644 --- a/test/config/tilt_shadow_config_test.dart +++ b/test/config/tilt_shadow_config_test.dart @@ -4,7 +4,7 @@ import 'package:flutter_tilt/src/config/tilt_shadow_config.dart'; import 'package:flutter_tilt/src/enums.dart'; void main() { - group('ShadowConfig', () { + group('ShadowConfig ::', () { test('assert', () { expect( () => ShadowConfig(minIntensity: 1.0, maxIntensity: 0.0), diff --git a/test/data/tilt_data_test.dart b/test/data/tilt_data_test.dart index 3a7b1a1..6a9b216 100644 --- a/test/data/tilt_data_test.dart +++ b/test/data/tilt_data_test.dart @@ -5,7 +5,7 @@ import 'package:flutter_tilt/src/data/tilt_data.dart'; import 'package:flutter_tilt/src/enums.dart'; void main() { - group('TiltData', () { + group('TiltData ::', () { test('tiltTransform', () { expect( const TiltData( @@ -72,7 +72,7 @@ void main() { }); }); - group('TiltDataModel', () { + group('TiltDataModel ::', () { test('hashCode', () { final TiltDataModel tiltDataModel = TiltDataModel( position: const Offset(5, 5), @@ -91,7 +91,7 @@ void main() { }); }); - group('TiltStreamModel', () { + group('TiltStreamModel ::', () { test('hashCode', () { const TiltStreamModel tiltStreamModel = TiltStreamModel( position: Offset(5, 5), diff --git a/test/internal/tilt_decoration_mixin_test.dart b/test/internal/tilt_decoration_mixin_test.dart index db6e4ea..22b2bfa 100644 --- a/test/internal/tilt_decoration_mixin_test.dart +++ b/test/internal/tilt_decoration_mixin_test.dart @@ -3,7 +3,7 @@ import 'package:flutter_tilt/src/enums.dart'; import 'package:flutter_tilt/src/internal/tilt_decoration_mixin.dart'; void main() { - group('TiltDecoration', () { + group('TiltDecoration ::', () { final tiltDecorationTest = TiltDecorationTest(); final tiltDecorationDirectionProgress = tiltDecorationTest.tiltDecorationDirectionProgress; diff --git a/test/internal/tilt_tween_animation_mixin_test.dart b/test/internal/tilt_tween_animation_mixin_test.dart index 8766db6..4a6f55d 100644 --- a/test/internal/tilt_tween_animation_mixin_test.dart +++ b/test/internal/tilt_tween_animation_mixin_test.dart @@ -5,7 +5,7 @@ import 'package:flutter_tilt/src/enums.dart'; import 'package:flutter_tilt/src/internal/tilt_tween_animation_mixin.dart'; void main() { - group('TiltTweenAnimation', () { + group('TiltTweenAnimation ::', () { final tiltTweenAnimationTest = TiltTweenAnimationTest(); test('tiltTweenAnimationEnd', () { final tiltTweenAnimationEnd = diff --git a/test/tilt_parallax_widget/tilt_parallax_test.dart b/test/tilt_parallax_widget/tilt_parallax_test.dart index 8055622..e9bb237 100644 --- a/test/tilt_parallax_widget/tilt_parallax_test.dart +++ b/test/tilt_parallax_widget/tilt_parallax_test.dart @@ -4,7 +4,7 @@ import 'package:flutter_tilt/flutter_tilt.dart'; import 'tilt_parallax_widget.dart'; void main() { - group('tilt parallax', () { + group('tilt parallax ::', () { testWidgets('default', (WidgetTester tester) async { final Finder outerFinder = find.text('outer'); final Finder innerFinder = find.text('inner'); diff --git a/test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_drag_test.dart b/test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_drag_test.dart new file mode 100644 index 0000000..fad81fb --- /dev/null +++ b/test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_drag_test.dart @@ -0,0 +1,67 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; + +void main() { + group('LightShadowMode.base :: tilt gestures drag ::', () { + testWidgets('scroll', (WidgetTester tester) async { + final Finder childFinder = find.text('Tilt'); + final Finder scrollFinder = find.byKey(const Key('scroll')); + final ScrollController scrollController = ScrollController(); + + debugDefaultTargetPlatformOverride = TargetPlatform.windows; + + /// 回调赋值 + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ListView( + controller: scrollController, + children: const [ + Tilt( + key: Key('tilt_widget'), + child: SizedBox(width: 100, height: 100, child: Text('Tilt')), + ), + SizedBox(key: Key('scroll'), height: 100, width: 100), + SizedBox(height: 1000), + ], + ), + ), + ), + ); + debugDefaultTargetPlatformOverride = null; + + /// onVerticalDragUpdate + await tester.timedDrag( + childFinder, + const Offset(0.0, -100.0), + const Duration(milliseconds: 1000), + ); + await tester.pumpAndSettle(); + expect(scrollController.offset, 0.0); + expect(childFinder, findsOneWidget); + + /// onHorizontalDragUpdate + await tester.timedDrag( + childFinder, + const Offset(-100.0, 0.0), + const Duration(milliseconds: 1000), + ); + await tester.pumpAndSettle(); + expect(scrollController.offset, 0.0); + expect(childFinder, findsOneWidget); + + /// scroll + await tester.timedDrag( + scrollFinder, + const Offset(0.0, -100.0), + const Duration(milliseconds: 1000), + warnIfMissed: false, + ); + await tester.pumpAndSettle(); + expect(scrollController.offset, 100.0); + expect(childFinder, findsNothing); + }); + }); +} diff --git a/test/tilt_widget/tilt_gestures_hover_test.dart b/test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_hover_test.dart similarity index 65% rename from test/tilt_widget/tilt_gestures_hover_test.dart rename to test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_hover_test.dart index d87d43c..dea710f 100644 --- a/test/tilt_widget/tilt_gestures_hover_test.dart +++ b/test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_hover_test.dart @@ -2,37 +2,25 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_tilt/flutter_tilt.dart'; -import 'tilt_widget.dart'; +import 'package:flutter_tilt/src/data/tilt_data.dart'; +import 'tilt_widget_base.dart'; void main() { - group('tilt gestures hover', () { + group('LightShadowMode.base :: tilt gestures hover ::', () { const TiltConfig tiltConfig = TiltConfig(); + TiltData tiltDataTestCalculate(Offset areaProgress) => TiltData( + isInit: true, + width: 10, + height: 10, + areaProgress: areaProgress, + tiltConfig: tiltConfig, + ); + final Finder tiltWidgetFinder = find.byKey(const Key('tilt_widget')); final Finder childFinder = find.text('Tilt'); final TestPointer testPointer = TestPointer(1, PointerDeviceKind.mouse); - final TiltDataModel leaveTiltDataExpect = TiltDataModel( - angle: Offset.zero, - areaProgress: Offset.zero, - position: const Offset(5.0, 5.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.05, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel leaveTiltDataExpect = + tiltDataTestCalculate(Offset.zero).data; testWidgets('gestures move leave', (WidgetTester tester) async { TiltDataModel? moveTiltDataTest; @@ -42,7 +30,7 @@ void main() { /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { moveTiltDataTest = tiltData; moveGesturesTypeTest = gesturesType; @@ -76,33 +64,12 @@ void main() { testWidgets('move top', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, 0.0), - areaProgress: const Offset(0.0, 1.0), - position: const Offset(5.0, 0.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - 0.0, - -0.17364817766693033, - 0.984807753012208, - 0.0492403876506104, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(0.0, 1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -140,33 +107,12 @@ void main() { testWidgets('move bottom', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: const Offset(-8.0, 0.0), - areaProgress: const Offset(0.0, -0.8), - position: const Offset(5.0, 9.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.9902680687415704, - -0.13917310096006544, - -0.006958655048003273, - 0.0, - 0.13917310096006544, - 0.9902680687415704, - 0.049513403437078524, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(0.0, -0.8)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -204,33 +150,12 @@ void main() { testWidgets('move left', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(0.0, -tiltConfig.angle), - areaProgress: const Offset(1.0, 0.0), - position: const Offset(0.0, 5.0), - transform: Matrix4( - 0.984807753012208, - 0.0, - 0.17364817766693033, - 0.008682408883346517, - 0.0, - 1.0, - 0.0, - 0.0, - -0.17364817766693033, - 0.0, - 0.984807753012208, - 0.0492403876506104, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, 0.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -268,33 +193,12 @@ void main() { testWidgets('move right', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: const Offset(0.0, 8.0), - areaProgress: const Offset(-0.8, 0.0), - position: const Offset(9.0, 5.0), - transform: Matrix4( - 0.9902680687415704, - 0.0, - -0.13917310096006544, - -0.006958655048003273, - 0.0, - 1.0, - 0.0, - 0.0, - 0.13917310096006544, - 0.0, - 0.9902680687415704, - 0.049513403437078524, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-0.8, 0.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -332,33 +236,12 @@ void main() { testWidgets('move top left', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, -tiltConfig.angle), - areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - 0.17101007166283433, - 0.008550503583141718, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - -0.17364817766693033, - -0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, 1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -396,33 +279,12 @@ void main() { testWidgets('move top right', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, 8.0), - areaProgress: const Offset(-0.8, 1.0), - position: const Offset(9.0, 0.0), - transform: Matrix4( - 0.9902680687415704, - 0.024167155361971074, - -0.1370587488362232, - -0.006852937441811161, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - 0.13917310096006544, - -0.17195824553872419, - 0.9752236716571246, - 0.048761183582856235, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-0.8, 1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -460,33 +322,12 @@ void main() { testWidgets('move bottom left', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(-8.0, -tiltConfig.angle), - areaProgress: const Offset(1.0, -0.8), - position: const Offset(0.0, 9.0), - transform: Matrix4( - 0.984807753012208, - 0.024167155361971074, - 0.17195824553872419, - 0.008597912276936211, - 0.0, - 0.9902680687415704, - -0.13917310096006544, - -0.006958655048003273, - -0.17364817766693033, - 0.1370587488362232, - 0.9752236716571246, - 0.048761183582856235, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, -0.8)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -524,33 +365,12 @@ void main() { testWidgets('move bottom right', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: const Offset(-8.0, 8.0), - areaProgress: const Offset(-0.8, -0.8), - position: const Offset(9.0, 9.0), - transform: Matrix4( - 0.9902680687415704, - -0.019369152030840567, - -0.13781867790849958, - -0.006890933895424981, - 0.0, - 0.9902680687415704, - -0.13917310096006544, - -0.006958655048003273, - 0.13917310096006544, - 0.13781867790849958, - 0.9806308479691596, - 0.04903154239845798, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-0.8, -0.8)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -583,47 +403,6 @@ void main() { expect(gesturesTypeTest, GesturesType.hover); expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); - await tester.sendEventToBinding(testPointer.removePointer()); - }); - testWidgets('LightShadowMode.projector gestures move leave', - (WidgetTester tester) async { - TiltDataModel? moveTiltDataTest; - TiltDataModel? leaveTiltDataTest; - GesturesType? moveGesturesTypeTest; - GesturesType? leaveGesturesTypeTest; - - /// 回调赋值 - await tester.pumpWidget( - TiltWidget( - lightShadowMode: LightShadowMode.projector, - onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { - moveTiltDataTest = tiltData; - moveGesturesTypeTest = gesturesType; - }, - onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { - leaveTiltDataTest = tiltData; - leaveGesturesTypeTest = gesturesType; - }, - ), - ); - - /// mouse hover - final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); - - /// 倾斜 hover move - await tester.sendEventToBinding(testPointer.hover(hoverEventLocation)); - await tester.pumpAndSettle(); - expect(childFinder, findsNWidgets(2)); - expect(moveGesturesTypeTest, GesturesType.hover); - expect(moveTiltDataTest != null, true); - - /// 倾斜 hover leave - await tester.sendEventToBinding(testPointer.hover(const Offset(-1, -1))); - await tester.pumpAndSettle(); - expect(childFinder, findsNWidgets(2)); - expect(leaveGesturesTypeTest, GesturesType.hover); - expect(leaveTiltDataTest, leaveTiltDataExpect); - await tester.sendEventToBinding(testPointer.removePointer()); }); }); diff --git a/test/tilt_widget/tilt_gestures_touch_test.dart b/test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_touch_test.dart similarity index 56% rename from test/tilt_widget/tilt_gestures_touch_test.dart rename to test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_touch_test.dart index 2880217..27cc529 100644 --- a/test/tilt_widget/tilt_gestures_touch_test.dart +++ b/test/tilt_widget/light_shadow_mode_base_widget/tilt_gestures_touch_test.dart @@ -1,11 +1,20 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_tilt/flutter_tilt.dart'; -import 'tilt_widget.dart'; +import 'package:flutter_tilt/src/data/tilt_data.dart'; +import 'tilt_widget_base.dart'; void main() { - group('tilt gestures touch', () { + group('LightShadowMode.base :: tilt gestures touch ::', () { const TiltConfig tiltConfig = TiltConfig(); + TiltData tiltDataTestCalculate(Offset areaProgress) => TiltData( + isInit: true, + width: 10, + height: 10, + areaProgress: areaProgress, + tiltConfig: tiltConfig, + ); + final Finder tiltScaffoldFinder = find.byKey(const Key('tilt_scaffold')); final Finder tiltWidgetFinder = find.byKey(const Key('tilt_widget')); final Finder childFinder = find.text('Tilt'); @@ -16,33 +25,12 @@ void main() { TiltDataModel? leaveTiltDataTest; GesturesType? moveGesturesTypeTest; GesturesType? leaveGesturesTypeTest; - final TiltDataModel leaveTiltDataTestExpect = TiltDataModel( - angle: Offset.zero, - areaProgress: Offset.zero, - position: const Offset(5.0, 5.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.05, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel leaveTiltDataTestExpect = + tiltDataTestCalculate(Offset.zero).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { moveTiltDataTest = tiltData; moveGesturesTypeTest = gesturesType; @@ -67,7 +55,7 @@ void main() { expect(leaveTiltDataTest, leaveTiltDataTestExpect); }); testWidgets('onPointerCancel', (WidgetTester tester) async { - await tester.pumpWidget(const TiltWidget()); + await tester.pumpWidget(const TiltWidgetBase()); final Offset location = tester.getCenter(tiltWidgetFinder); await tester.sendEventToBinding(testPointer.down(location)); @@ -80,33 +68,12 @@ void main() { testWidgets('move top', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, 0.0), - areaProgress: const Offset(0.0, 1.0), - position: const Offset(5.0, 0.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - 0.0, - -0.17364817766693033, - 0.984807753012208, - 0.0492403876506104, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(0.0, 1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -129,33 +96,12 @@ void main() { testWidgets('move bottom', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(-tiltConfig.angle, 0.0), - areaProgress: const Offset(0.0, -1.0), - position: const Offset(5.0, 10.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.984807753012208, - -0.17364817766693033, - -0.008682408883346517, - 0.0, - 0.17364817766693033, - 0.984807753012208, - 0.0492403876506104, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(0.0, -1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -178,33 +124,12 @@ void main() { testWidgets('move left', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(0.0, -tiltConfig.angle), - areaProgress: const Offset(1.0, 0.0), - position: const Offset(0.0, 5.0), - transform: Matrix4( - 0.984807753012208, - 0.0, - 0.17364817766693033, - 0.008682408883346517, - 0.0, - 1.0, - 0.0, - 0.0, - -0.17364817766693033, - 0.0, - 0.984807753012208, - 0.0492403876506104, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, 0.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -227,33 +152,12 @@ void main() { testWidgets('move right', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(0.0, tiltConfig.angle), - areaProgress: const Offset(-1.0, 0.0), - position: Offset(tiltConfig.angle, 5.0), - transform: Matrix4( - 0.984807753012208, - 0.0, - -0.17364817766693033, - -0.008682408883346517, - 0.0, - 1.0, - 0.0, - 0.0, - 0.17364817766693033, - 0.0, - 0.984807753012208, - 0.0492403876506104, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-1.0, 0.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -276,33 +180,12 @@ void main() { testWidgets('move top left', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, -tiltConfig.angle), - areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - 0.17101007166283433, - 0.008550503583141718, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - -0.17364817766693033, - -0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, 1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -325,33 +208,12 @@ void main() { testWidgets('move top right', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, tiltConfig.angle), - areaProgress: const Offset(-1.0, 1.0), - position: Offset(tiltConfig.angle, 0.0), - transform: Matrix4( - 0.984807753012208, - 0.030153689607045803, - -0.17101007166283433, - -0.008550503583141718, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - 0.17364817766693033, - -0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-1.0, 1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -374,33 +236,12 @@ void main() { testWidgets('move bottom left', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(-tiltConfig.angle, -tiltConfig.angle), - areaProgress: const Offset(1.0, -1.0), - position: Offset(0.0, tiltConfig.angle), - transform: Matrix4( - 0.984807753012208, - 0.030153689607045803, - 0.17101007166283433, - 0.008550503583141718, - 0.0, - 0.984807753012208, - -0.17364817766693033, - -0.008682408883346517, - -0.17364817766693033, - 0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, -1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -423,33 +264,12 @@ void main() { testWidgets('move bottom right', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(-tiltConfig.angle, tiltConfig.angle), - areaProgress: const Offset(-1.0, -1.0), - position: Offset(tiltConfig.angle, tiltConfig.angle), - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - -0.17101007166283433, - -0.008550503583141718, - 0.0, - 0.984807753012208, - -0.17364817766693033, - -0.008682408883346517, - 0.17364817766693033, - 0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-1.0, -1.0)).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -470,98 +290,17 @@ void main() { expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); }); - testWidgets('LightShadowMode.projector gestures move leave', - (WidgetTester tester) async { - TiltDataModel? moveTiltDataTest; - TiltDataModel? leaveTiltDataTest; - GesturesType? moveGesturesTypeTest; - GesturesType? leaveGesturesTypeTest; - final TiltDataModel leaveTiltDataTestExpect = TiltDataModel( - angle: Offset.zero, - areaProgress: Offset.zero, - position: const Offset(5.0, 5.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.05, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); - - /// 回调赋值 - await tester.pumpWidget( - TiltWidget( - lightShadowMode: LightShadowMode.projector, - onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { - moveTiltDataTest = tiltData; - moveGesturesTypeTest = gesturesType; - }, - onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { - leaveTiltDataTest = tiltData; - leaveGesturesTypeTest = gesturesType; - }, - ), - ); - - /// 倾斜 touch move - await tester.fling(tiltWidgetFinder, const Offset(0.0, 5.0), 0.1); - expect(childFinder, findsNWidgets(2)); - expect(moveGesturesTypeTest, GesturesType.touch); - expect(moveTiltDataTest != null, true); - - /// 倾斜 touch leave - await tester.fling(tiltScaffoldFinder, const Offset(0.0, -1.0), 0.1); - expect(childFinder, findsNWidgets(2)); - expect(leaveGesturesTypeTest, GesturesType.touch); - expect(leaveTiltDataTest, leaveTiltDataTestExpect); - }); - - testWidgets('LightShadowMode.projector ShadowConfig.disable = true', - (WidgetTester tester) async { + testWidgets('ShadowConfig.disable = true', (WidgetTester tester) async { TiltDataModel? moveTiltDataTest; TiltDataModel? leaveTiltDataTest; GesturesType? moveGesturesTypeTest; GesturesType? leaveGesturesTypeTest; - final TiltDataModel leaveTiltDataTestExpect = TiltDataModel( - angle: Offset.zero, - areaProgress: Offset.zero, - position: const Offset(5.0, 5.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.05, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + final TiltDataModel leaveTiltDataTestExpect = + tiltDataTestCalculate(Offset.zero).data; /// 回调赋值 await tester.pumpWidget( - TiltWidget( - lightShadowMode: LightShadowMode.projector, + TiltWidgetBase( shadowConfig: const ShadowConfig(disable: true), onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { moveTiltDataTest = tiltData; diff --git a/test/tilt_widget/tilt_stream_controller_test.dart b/test/tilt_widget/light_shadow_mode_base_widget/tilt_stream_controller_test.dart similarity index 98% rename from test/tilt_widget/tilt_stream_controller_test.dart rename to test/tilt_widget/light_shadow_mode_base_widget/tilt_stream_controller_test.dart index cd90c81..834babe 100644 --- a/test/tilt_widget/tilt_stream_controller_test.dart +++ b/test/tilt_widget/light_shadow_mode_base_widget/tilt_stream_controller_test.dart @@ -2,11 +2,11 @@ import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_tilt/flutter_tilt.dart'; -import 'tilt_widget.dart'; +import 'tilt_widget_base.dart'; void main() { final Finder childFinder = find.text('Tilt'); - group('tilt TiltStreamController', () { + group('LightShadowMode.base :: tilt TiltStreamController ::', () { testWidgets('stream listen', (WidgetTester tester) async { TiltStreamModel tiltStreamModelTest = const TiltStreamModel( position: Offset(1, 1), @@ -23,7 +23,7 @@ void main() { final StreamController tiltStreamController = StreamController.broadcast(); await tester.pumpWidget( - TiltWidget(tiltStreamController: tiltStreamController), + TiltWidgetBase(tiltStreamController: tiltStreamController), ); await tester.pumpAndSettle(); expect(childFinder, findsOneWidget); @@ -64,7 +64,7 @@ void main() { final StreamController tiltStreamController = StreamController.broadcast(); await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( tiltStreamController: tiltStreamController, tiltConfig: const TiltConfig( enableGestureTouch: false, @@ -256,7 +256,7 @@ void main() { final StreamController tiltStreamController = StreamController.broadcast(); await tester.pumpWidget( - TiltWidget( + TiltWidgetBase( tiltStreamController: tiltStreamController, onGestureMove: ( TiltDataModel tiltDataModel, diff --git a/test/tilt_widget/light_shadow_mode_base_widget/tilt_widget_base.dart b/test/tilt_widget/light_shadow_mode_base_widget/tilt_widget_base.dart new file mode 100644 index 0000000..593fcd0 --- /dev/null +++ b/test/tilt_widget/light_shadow_mode_base_widget/tilt_widget_base.dart @@ -0,0 +1,67 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; + +class TiltWidgetBase extends StatelessWidget { + const TiltWidgetBase({ + super.key, + this.childLayout = const ChildLayout(), + this.tiltStreamController, + this.disable = false, + this.fps = 60, + this.border, + this.borderRadius, + this.clipBehavior = Clip.antiAlias, + this.tiltConfig = const TiltConfig(), + this.lightShadowMode = LightShadowMode.base, + this.lightConfig = const LightConfig(), + this.shadowConfig = const ShadowConfig(), + this.onGestureMove, + this.onGestureLeave, + }); + + final ChildLayout childLayout; + final StreamController? tiltStreamController; + final bool disable; + final int fps; + final BoxBorder? border; + final BorderRadiusGeometry? borderRadius; + final Clip clipBehavior; + final TiltConfig tiltConfig; + final LightShadowMode lightShadowMode; + final LightConfig lightConfig; + final ShadowConfig shadowConfig; + final void Function(TiltDataModel, GesturesType)? onGestureMove; + final void Function(TiltDataModel, GesturesType)? onGestureLeave; + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + key: const Key('tilt_scaffold'), + body: Tilt( + key: const Key('tilt_widget'), + childLayout: childLayout, + tiltStreamController: tiltStreamController, + disable: disable, + fps: fps, + border: border, + borderRadius: borderRadius, + clipBehavior: clipBehavior, + lightShadowMode: lightShadowMode, + tiltConfig: tiltConfig.copyWith(enableGestureSensors: false), + lightConfig: lightConfig, + shadowConfig: shadowConfig, + onGestureMove: onGestureMove, + onGestureLeave: onGestureLeave, + child: const SizedBox( + width: 10, + height: 10, + child: Text('Tilt'), + ), + ), + ), + ); + } +} diff --git a/test/tilt_widget/tilt_gestures_drag_test.dart b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_drag_test.dart similarity index 52% rename from test/tilt_widget/tilt_gestures_drag_test.dart rename to test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_drag_test.dart index b2aae10..9ae12d1 100644 --- a/test/tilt_widget/tilt_gestures_drag_test.dart +++ b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_drag_test.dart @@ -4,72 +4,12 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_tilt/flutter_tilt.dart'; void main() { - group('tilt gestures drag', () { + group('LightShadowMode.projector :: tilt gestures drag ::', () { testWidgets('scroll', (WidgetTester tester) async { final Finder childFinder = find.text('Tilt'); final Finder scrollFinder = find.byKey(const Key('scroll')); final ScrollController scrollController = ScrollController(); - debugDefaultTargetPlatformOverride = TargetPlatform.windows; - - /// 回调赋值 - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ListView( - controller: scrollController, - children: const [ - Tilt( - key: Key('tilt_widget'), - child: SizedBox(width: 100, height: 100, child: Text('Tilt')), - ), - SizedBox(key: Key('scroll'), height: 100, width: 100), - SizedBox(height: 1000), - ], - ), - ), - ), - ); - debugDefaultTargetPlatformOverride = null; - - /// onVerticalDragUpdate - await tester.timedDrag( - childFinder, - const Offset(0.0, -100.0), - const Duration(milliseconds: 1000), - ); - await tester.pumpAndSettle(); - expect(scrollController.offset, 0.0); - expect(childFinder, findsOneWidget); - - /// onHorizontalDragUpdate - await tester.timedDrag( - childFinder, - const Offset(-100.0, 0.0), - const Duration(milliseconds: 1000), - ); - await tester.pumpAndSettle(); - expect(scrollController.offset, 0.0); - expect(childFinder, findsOneWidget); - - /// scroll - await tester.timedDrag( - scrollFinder, - const Offset(0.0, -100.0), - const Duration(milliseconds: 1000), - warnIfMissed: false, - ); - await tester.pumpAndSettle(); - expect(scrollController.offset, 100.0); - expect(childFinder, findsNothing); - }); - - testWidgets('LightShadowMode.projector scroll', - (WidgetTester tester) async { - final Finder childFinder = find.text('Tilt').first; - final Finder scrollFinder = find.byKey(const Key('scroll')); - final ScrollController scrollController = ScrollController(); - debugDefaultTargetPlatformOverride = TargetPlatform.windows; await tester.pumpWidget( MaterialApp( @@ -99,25 +39,25 @@ void main() { /// onVerticalDragUpdate await tester.timedDrag( - childFinder, + childFinder.first, const Offset(0.0, -100.0), const Duration(milliseconds: 1000), warnIfMissed: false, ); await tester.pumpAndSettle(); expect(scrollController.offset, 0.0); - expect(childFinder, findsOneWidget); + expect(childFinder, findsNWidgets(2)); /// onHorizontalDragUpdate await tester.timedDrag( - childFinder, + childFinder.first, const Offset(-100.0, 0.0), const Duration(milliseconds: 1000), warnIfMissed: false, ); await tester.pumpAndSettle(); expect(scrollController.offset, 0.0); - expect(childFinder, findsOneWidget); + expect(childFinder, findsNWidgets(2)); /// scroll await tester.timedDrag( diff --git a/test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_hover_test.dart b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_hover_test.dart new file mode 100644 index 0000000..b8f6bd9 --- /dev/null +++ b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_hover_test.dart @@ -0,0 +1,409 @@ +import 'package:flutter/gestures.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; +import 'package:flutter_tilt/src/data/tilt_data.dart'; +import 'tilt_widget_projector.dart'; + +void main() { + group('LightShadowMode.projector :: tilt gestures hover ::', () { + const TiltConfig tiltConfig = TiltConfig(); + TiltData tiltDataTestCalculate(Offset areaProgress) => TiltData( + isInit: true, + width: 10, + height: 10, + areaProgress: areaProgress, + tiltConfig: tiltConfig, + ); + + final Finder tiltWidgetFinder = find.byKey(const Key('tilt_widget')); + final Finder childFinder = find.text('Tilt'); + final TestPointer testPointer = TestPointer(1, PointerDeviceKind.mouse); + final TiltDataModel leaveTiltDataExpect = + tiltDataTestCalculate(Offset.zero).data; + + testWidgets('gestures move leave', (WidgetTester tester) async { + TiltDataModel? moveTiltDataTest; + TiltDataModel? leaveTiltDataTest; + GesturesType? moveGesturesTypeTest; + GesturesType? leaveGesturesTypeTest; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + moveTiltDataTest = tiltData; + moveGesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + leaveTiltDataTest = tiltData; + leaveGesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜 hover move + await tester.sendEventToBinding(testPointer.hover(hoverEventLocation)); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(moveGesturesTypeTest, GesturesType.hover); + expect(moveTiltDataTest != null, true); + + /// 倾斜 hover leave + await tester.sendEventToBinding(testPointer.hover(const Offset(-1, -1))); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(leaveGesturesTypeTest, GesturesType.hover); + expect(leaveTiltDataTest, leaveTiltDataExpect); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move top', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(0.0, 1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜-不超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(0.0, -5.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(0.0, -6.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move bottom', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(0.0, -0.8)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜-不超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(0.0, 4.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(0.0, 6.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move left', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, 0.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜-不超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(-5.0, 0.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(-6.0, 0.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move right', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-0.8, 0.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜-不超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(4.0, 0.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(6.0, 0.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move top left', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, 1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜-不超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(-5.0, -5.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(-6.0, -6.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move top right', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-0.8, 1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜-不超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(4.0, -5.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(6.0, -6.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move bottom left', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, -0.8)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜-不超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(-5.0, 4.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(-6.0, 6.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move bottom right', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-0.8, -0.8)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// mouse hover + final Offset hoverEventLocation = tester.getCenter(tiltWidgetFinder); + + /// 倾斜-不超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(4.0, 4.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.sendEventToBinding( + testPointer.hover(hoverEventLocation + const Offset(6.0, 6.0)), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.hover); + expect(tiltDataTest, leaveTiltDataExpect, reason: '倾斜-超范围'); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + }); +} diff --git a/test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_touch_test.dart b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_touch_test.dart new file mode 100644 index 0000000..c63bc4c --- /dev/null +++ b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_gestures_touch_test.dart @@ -0,0 +1,329 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; +import 'package:flutter_tilt/src/data/tilt_data.dart'; +import 'tilt_widget_projector.dart'; + +void main() { + group('LightShadowMode.projector :: tilt gestures touch ::', () { + const TiltConfig tiltConfig = TiltConfig(); + TiltData tiltDataTestCalculate(Offset areaProgress) => TiltData( + isInit: true, + width: 10, + height: 10, + areaProgress: areaProgress, + tiltConfig: tiltConfig, + ); + + final Finder tiltScaffoldFinder = find.byKey(const Key('tilt_scaffold')); + final Finder tiltWidgetFinder = find.byKey(const Key('tilt_widget')); + final Finder childFinder = find.text('Tilt'); + final TestPointer testPointer = TestPointer(); + + testWidgets('gestures move leave', (WidgetTester tester) async { + TiltDataModel? moveTiltDataTest; + TiltDataModel? leaveTiltDataTest; + GesturesType? moveGesturesTypeTest; + GesturesType? leaveGesturesTypeTest; + final TiltDataModel leaveTiltDataTestExpect = + tiltDataTestCalculate(Offset.zero).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + moveTiltDataTest = tiltData; + moveGesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + leaveTiltDataTest = tiltData; + leaveGesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜 touch move + await tester.fling(tiltWidgetFinder, const Offset(0.0, 5.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(moveGesturesTypeTest, GesturesType.touch); + expect(moveTiltDataTest != null, true); + + /// 倾斜 touch leave + await tester.fling(tiltScaffoldFinder, const Offset(0.0, -1.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(leaveGesturesTypeTest, GesturesType.touch); + expect(leaveTiltDataTest, leaveTiltDataTestExpect); + }); + testWidgets('onPointerCancel', (WidgetTester tester) async { + await tester.pumpWidget(const TiltWidgetProjector()); + + final Offset location = tester.getCenter(tiltWidgetFinder); + await tester.sendEventToBinding(testPointer.down(location)); + await tester.sendEventToBinding(testPointer.cancel()); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + + await tester.sendEventToBinding(testPointer.removePointer()); + }); + testWidgets('move top', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(0.0, 1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜-不超范围 + await tester.fling(tiltWidgetFinder, const Offset(0.0, -5.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.fling(tiltWidgetFinder, const Offset(0.0, -6.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); + }); + testWidgets('move bottom', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(0.0, -1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜-不超范围 + await tester.fling(tiltWidgetFinder, const Offset(0.0, 5.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.fling(tiltWidgetFinder, const Offset(0.0, 6.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); + }); + testWidgets('move left', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, 0.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜-不超范围 + await tester.fling(tiltWidgetFinder, const Offset(-5.0, 0.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.fling(tiltWidgetFinder, const Offset(-6.0, 0.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); + }); + testWidgets('move right', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-1.0, 0.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜-不超范围 + await tester.fling(tiltWidgetFinder, const Offset(5.0, 0.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.fling(tiltWidgetFinder, const Offset(6.0, 0.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); + }); + testWidgets('move top left', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, 1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜-不超范围 + await tester.fling(tiltWidgetFinder, const Offset(-5.0, -5.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.fling(tiltWidgetFinder, const Offset(-6.0, -6.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); + }); + testWidgets('move top right', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-1.0, 1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜-不超范围 + await tester.fling(tiltWidgetFinder, const Offset(5.0, -5.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.fling(tiltWidgetFinder, const Offset(6.0, -6.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); + }); + testWidgets('move bottom left', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(1.0, -1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜-不超范围 + await tester.fling(tiltWidgetFinder, const Offset(-5.0, 5.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.fling(tiltWidgetFinder, const Offset(-6.0, 6.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); + }); + testWidgets('move bottom right', (WidgetTester tester) async { + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + final TiltDataModel tiltDataExpect = + tiltDataTestCalculate(const Offset(-1.0, -1.0)).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜-不超范围 + await tester.fling(tiltWidgetFinder, const Offset(5.0, 5.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-不超范围'); + + /// 倾斜-超范围 + await tester.fling(tiltWidgetFinder, const Offset(6.0, 6.0), 0.1); + expect(childFinder, findsNWidgets(2)); + expect(gesturesTypeTest, GesturesType.touch); + expect(tiltDataTest, tiltDataExpect, reason: '倾斜-超范围'); + }); + + testWidgets('ShadowConfig.disable = true', (WidgetTester tester) async { + TiltDataModel? moveTiltDataTest; + TiltDataModel? leaveTiltDataTest; + GesturesType? moveGesturesTypeTest; + GesturesType? leaveGesturesTypeTest; + final TiltDataModel leaveTiltDataTestExpect = + tiltDataTestCalculate(Offset.zero).data; + + /// 回调赋值 + await tester.pumpWidget( + TiltWidgetProjector( + shadowConfig: const ShadowConfig(disable: true), + onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { + moveTiltDataTest = tiltData; + moveGesturesTypeTest = gesturesType; + }, + onGestureLeave: (TiltDataModel tiltData, GesturesType gesturesType) { + leaveTiltDataTest = tiltData; + leaveGesturesTypeTest = gesturesType; + }, + ), + ); + + /// 倾斜 touch move + await tester.fling(tiltWidgetFinder, const Offset(0.0, 5.0), 0.1); + expect(childFinder, findsNWidgets(1)); + expect(moveGesturesTypeTest, GesturesType.touch); + expect(moveTiltDataTest != null, true); + + /// 倾斜 touch leave + await tester.fling(tiltScaffoldFinder, const Offset(0.0, -1.0), 0.1); + expect(childFinder, findsNWidgets(1)); + expect(leaveGesturesTypeTest, GesturesType.touch); + expect(leaveTiltDataTest, leaveTiltDataTestExpect); + }); + }); +} diff --git a/test/tilt_widget/light_shadow_mode_projector_widget/tilt_stream_controller_test.dart b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_stream_controller_test.dart new file mode 100644 index 0000000..ce3c451 --- /dev/null +++ b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_stream_controller_test.dart @@ -0,0 +1,392 @@ +import 'dart:async'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; +import 'tilt_widget_projector.dart'; + +void main() { + final Finder childFinder = find.text('Tilt'); + group('LightShadowMode.projector :: tilt TiltStreamController ::', () { + testWidgets('stream listen', (WidgetTester tester) async { + TiltStreamModel tiltStreamModelTest = const TiltStreamModel( + position: Offset(1, 1), + gesturesType: GesturesType.touch, + gestureUse: false, + ); + const TiltStreamModel tiltStreamModelExpect = TiltStreamModel( + position: Offset.zero, + gesturesType: GesturesType.controller, + gestureUse: true, + ); + + /// 基础 + final StreamController tiltStreamController = + StreamController.broadcast(); + await tester.pumpWidget( + TiltWidgetProjector(tiltStreamController: tiltStreamController), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + + /// 测试值不同 + expect(tiltStreamModelTest != tiltStreamModelExpect, true); + + await tester.pumpAndSettle(); + + /// 监听 + tiltStreamController.stream.listen((TiltStreamModel tiltStreamModel) { + tiltStreamModelTest = tiltStreamModel; + }); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + + /// 测试值相同 + expect(tiltStreamModelTest, tiltStreamModelExpect); + }); + + testWidgets('disable all gestures and use controller triggers', ( + WidgetTester tester, + ) async { + TiltStreamModel tiltStreamModelTest = const TiltStreamModel( + position: Offset(1, 1), + gesturesType: GesturesType.controller, + gestureUse: true, + ); + TiltStreamModel tiltStreamModelExpect = const TiltStreamModel( + position: Offset.zero, + gesturesType: GesturesType.controller, + gestureUse: false, + ); + TiltStreamModel? gestureMoveExpect; + TiltStreamModel? gestureLeaveExpect; + + /// 基础 回调赋值 + final StreamController tiltStreamController = + StreamController.broadcast(); + await tester.pumpWidget( + TiltWidgetProjector( + tiltStreamController: tiltStreamController, + tiltConfig: const TiltConfig( + enableGestureTouch: false, + enableGestureHover: false, + enableGestureSensors: false, + ), + onGestureMove: ( + TiltDataModel tiltDataModel, + GesturesType gesturesType, + ) { + gestureMoveExpect = TiltStreamModel( + position: tiltDataModel.position, + gesturesType: gesturesType, + gestureUse: true, + ); + }, + onGestureLeave: ( + TiltDataModel tiltDataModel, + GesturesType gesturesType, + ) { + gestureLeaveExpect = TiltStreamModel( + position: tiltDataModel.position, + gesturesType: gesturesType, + gestureUse: false, + ); + }, + ), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(tiltStreamModelTest != tiltStreamModelExpect, true); + + /// stream 监听 + tiltStreamController.stream.listen((TiltStreamModel tiltStreamModel) { + tiltStreamModelTest = tiltStreamModel; + }); + + /// controller touch 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.touch, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + + /// controller touch 手势离开 + gestureLeaveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.touch, + gestureUse: false, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect( + const TiltStreamModel( + position: Offset(5, 5), + gesturesType: GesturesType.touch, + gestureUse: false, + ), + gestureLeaveExpect, + ); + + /// controller hover 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.hover, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + + /// controller hover 手势离开 + gestureLeaveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.hover, + gestureUse: false, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect( + gestureLeaveExpect, + const TiltStreamModel( + position: Offset(5, 5), + gesturesType: GesturesType.hover, + gestureUse: false, + ), + ); + + /// controller controller 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.controller, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + + /// controller controller 手势离开 + gestureLeaveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.controller, + gestureUse: false, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect( + gestureLeaveExpect, + const TiltStreamModel( + position: Offset(5, 5), + gesturesType: GesturesType.controller, + gestureUse: false, + ), + ); + + /// controller sensors 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.sensors, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + + /// controller sensors 手势还原 + gestureLeaveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.sensors, + gestureUse: false, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + // sensors 不会触发 onGestureLeave + expect(gestureLeaveExpect, null); + // 触发 sensors 为 0,让组件还原一点 + tiltStreamModelExpect = const TiltStreamModel( + position: Offset.zero, + gesturesType: GesturesType.sensors, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect( + gestureMoveExpect, + const TiltStreamModel( + position: Offset(9.75, 9.75), + gesturesType: GesturesType.sensors, + gestureUse: true, + ), + ); + }); + + testWidgets('gesture priority', ( + WidgetTester tester, + ) async { + TiltStreamModel tiltStreamModelTest = const TiltStreamModel( + position: Offset(1, 1), + gesturesType: GesturesType.controller, + gestureUse: true, + ); + TiltStreamModel tiltStreamModelExpect = const TiltStreamModel( + position: Offset.zero, + gesturesType: GesturesType.controller, + gestureUse: false, + ); + TiltStreamModel? gestureMoveExpect; + TiltStreamModel? gestureLeaveExpect; + + /// 基础 回调赋值 + final StreamController tiltStreamController = + StreamController.broadcast(); + await tester.pumpWidget( + TiltWidgetProjector( + tiltStreamController: tiltStreamController, + onGestureMove: ( + TiltDataModel tiltDataModel, + GesturesType gesturesType, + ) { + gestureMoveExpect = TiltStreamModel( + position: tiltDataModel.position, + gesturesType: gesturesType, + gestureUse: true, + ); + }, + onGestureLeave: ( + TiltDataModel tiltDataModel, + GesturesType gesturesType, + ) { + gestureLeaveExpect = TiltStreamModel( + position: tiltDataModel.position, + gesturesType: gesturesType, + gestureUse: false, + ); + }, + ), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsNWidgets(2)); + expect(tiltStreamModelTest != tiltStreamModelExpect, true); + + /// stream 监听 + tiltStreamController.stream.listen((TiltStreamModel tiltStreamModel) { + tiltStreamModelTest = tiltStreamModel; + }); + + /// sensors 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.sensors, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + + /// controller 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.controller, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + + /// hover 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.hover, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + + /// touch 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.touch, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + + /// 低优先级判断 + const TiltStreamModel lowPriorityData = TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.touch, + gestureUse: true, + ); + + /// hover 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.hover, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(gestureMoveExpect, lowPriorityData); + + /// touch 手势离开 + gestureMoveExpect = null; + gestureLeaveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.touch, + gestureUse: false, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(gestureMoveExpect, null); + expect( + gestureLeaveExpect, + const TiltStreamModel( + position: Offset(5, 5), + gesturesType: GesturesType.touch, + gestureUse: false, + ), + ); + + /// hover 手势移动 + gestureMoveExpect = null; + tiltStreamModelExpect = const TiltStreamModel( + position: Offset(10, 10), + gesturesType: GesturesType.hover, + gestureUse: true, + ); + tiltStreamController.sink.add(tiltStreamModelExpect); + await tester.pumpAndSettle(); + expect(tiltStreamModelTest, tiltStreamModelExpect); + expect(tiltStreamModelTest, gestureMoveExpect); + }); + }); +} diff --git a/test/tilt_widget/light_shadow_mode_projector_widget/tilt_widget_projector.dart b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_widget_projector.dart new file mode 100644 index 0000000..fba5e60 --- /dev/null +++ b/test/tilt_widget/light_shadow_mode_projector_widget/tilt_widget_projector.dart @@ -0,0 +1,67 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:flutter_tilt/flutter_tilt.dart'; + +class TiltWidgetProjector extends StatelessWidget { + const TiltWidgetProjector({ + super.key, + this.childLayout = const ChildLayout(), + this.tiltStreamController, + this.disable = false, + this.fps = 60, + this.border, + this.borderRadius, + this.clipBehavior = Clip.antiAlias, + this.tiltConfig = const TiltConfig(), + this.lightShadowMode = LightShadowMode.projector, + this.lightConfig = const LightConfig(), + this.shadowConfig = const ShadowConfig(), + this.onGestureMove, + this.onGestureLeave, + }); + + final ChildLayout childLayout; + final StreamController? tiltStreamController; + final bool disable; + final int fps; + final BoxBorder? border; + final BorderRadiusGeometry? borderRadius; + final Clip clipBehavior; + final TiltConfig tiltConfig; + final LightShadowMode lightShadowMode; + final LightConfig lightConfig; + final ShadowConfig shadowConfig; + final void Function(TiltDataModel, GesturesType)? onGestureMove; + final void Function(TiltDataModel, GesturesType)? onGestureLeave; + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + key: const Key('tilt_scaffold'), + body: Tilt( + key: const Key('tilt_widget'), + childLayout: childLayout, + tiltStreamController: tiltStreamController, + disable: disable, + fps: fps, + border: border, + borderRadius: borderRadius, + clipBehavior: clipBehavior, + lightShadowMode: lightShadowMode, + tiltConfig: tiltConfig.copyWith(enableGestureSensors: false), + lightConfig: lightConfig, + shadowConfig: shadowConfig, + onGestureMove: onGestureMove, + onGestureLeave: onGestureLeave, + child: const SizedBox( + width: 10, + height: 10, + child: Text('Tilt'), + ), + ), + ), + ); + } +} diff --git a/test/tilt_widget/tilt_config_test.dart b/test/tilt_widget/tilt_config_test.dart index fe8748b..3c2c555 100644 --- a/test/tilt_widget/tilt_config_test.dart +++ b/test/tilt_widget/tilt_config_test.dart @@ -6,7 +6,7 @@ import 'tilt_widget.dart'; void main() { final Finder tiltWidgetFinder = find.byKey(const Key('tilt_widget')); final Finder childFinder = find.text('Tilt'); - group('tilt config', () { + group('tilt config ::', () { testWidgets('default', (WidgetTester tester) async { await tester.pumpWidget(const TiltWidget()); await tester.pumpAndSettle(); diff --git a/test/tilt_widget/tilt_config_tilt_test.dart b/test/tilt_widget/tilt_config_tilt_test.dart index aca2538..758357f 100644 --- a/test/tilt_widget/tilt_config_tilt_test.dart +++ b/test/tilt_widget/tilt_config_tilt_test.dart @@ -3,44 +3,40 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_tilt/flutter_tilt.dart'; +import 'package:flutter_tilt/src/data/tilt_data.dart'; import 'tilt_widget.dart'; void main() { const TiltConfig tiltConfig = TiltConfig(); + TiltData tiltDataTestCalculate({ + required Offset areaProgress, + TiltConfig tiltConfig = tiltConfig, + }) => + TiltData( + isInit: true, + width: 10, + height: 10, + areaProgress: areaProgress, + tiltConfig: tiltConfig, + ); + final Finder tiltWidgetFinder = find.byKey(const Key('tilt_widget')); final Finder childFinder = find.text('Tilt'); final TestPointer testPointer = TestPointer(1, PointerDeviceKind.mouse); - group('tilt TiltConfig', () { + + group('tilt TiltConfig ::', () { testWidgets('disable true', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, 0.0), + const TiltConfig tiltConfigTest = TiltConfig(disable: true); + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( areaProgress: const Offset(0.0, 1.0), - position: const Offset(5.0, 0.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( - tiltConfig: const TiltConfig(disable: true), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -52,59 +48,23 @@ void main() { expect(gesturesTypeTest, GesturesType.touch); expect(tiltDataTest, tiltDataExpect); }); + testWidgets('initial', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataInitialExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, -tiltConfig.angle), + const TiltConfig tiltConfigTest = TiltConfig(initial: Offset(1.0, 1.0)); + final TiltDataModel tiltDataInitialExpect = tiltDataTestCalculate( areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - 0.17101007166283433, - 0.008550503583141718, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - -0.17364817766693033, - -0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: const Offset(-8.0, 8.0), + tiltConfig: tiltConfigTest, + ).data; + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( areaProgress: const Offset(-0.8, -0.8), - position: const Offset(9.0, 9.0), - transform: Matrix4( - 0.9902680687415704, - -0.019369152030840567, - -0.13781867790849958, - -0.006890933895424981, - 0.0, - 0.9902680687415704, - -0.13917310096006544, - -0.006958655048003273, - 0.13917310096006544, - 0.13781867790849958, - 0.9806308479691596, - 0.04903154239845798, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( - tiltConfig: const TiltConfig(initial: Offset(1.0, 1.0)), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -139,111 +99,60 @@ void main() { await tester.sendEventToBinding(testPointer.removePointer()); }); + testWidgets('angle', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: const Offset(20.0, -20.0), + const TiltConfig tiltConfigTest = TiltConfig(angle: 20); + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.9396926207859084, - -0.11697777844051097, - 0.3213938048432697, - 0.016069690242163485, - 0.0, - 0.9396926207859084, - 0.3420201433256687, - 0.017101007166283436, - -0.3420201433256687, - -0.3213938048432697, - 0.8830222215594891, - 0.04415111107797446, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; + await tester.pumpWidget( TiltWidget( - tiltConfig: const TiltConfig(angle: 20), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; }, ), ); + await tester.fling(tiltWidgetFinder, const Offset(-5.0, -5.0), 0.1); expect(childFinder, findsOneWidget); expect(gesturesTypeTest, GesturesType.touch); expect(tiltDataTest, tiltDataExpect); }); + testWidgets('direction all', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, -tiltConfig.angle), + final TiltConfig tiltConfigTest = TiltConfig( + direction: [ + TiltDirection.none, + TiltDirection.top, + TiltDirection.bottom, + TiltDirection.left, + TiltDirection.right, + TiltDirection.topLeft, + TiltDirection.topRight, + TiltDirection.bottomLeft, + TiltDirection.bottomRight, + ], + ); + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - 0.17101007166283433, - 0.008550503583141718, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - -0.17364817766693033, - -0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); - final TiltDataModel tiltDataExpect2 = TiltDataModel( - angle: Offset(-tiltConfig.angle, tiltConfig.angle), + tiltConfig: tiltConfigTest, + ).data; + final TiltDataModel tiltDataExpect2 = tiltDataTestCalculate( areaProgress: const Offset(-1.0, -1.0), - position: Offset(tiltConfig.angle, tiltConfig.angle), - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - -0.17101007166283433, - -0.008550503583141718, - 0.0, - 0.984807753012208, - -0.17364817766693033, - -0.008682408883346517, - 0.17364817766693033, - 0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( - tiltConfig: TiltConfig( - direction: [ - TiltDirection.none, - TiltDirection.top, - TiltDirection.bottom, - TiltDirection.left, - TiltDirection.right, - TiltDirection.topLeft, - TiltDirection.topRight, - TiltDirection.bottomLeft, - TiltDirection.bottomRight, - ], - ), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -263,61 +172,25 @@ void main() { expect(gesturesTypeTest, GesturesType.touch); expect(tiltDataTest, tiltDataExpect2); }); + testWidgets('direction part', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, -tiltConfig.angle), - areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - 0.17101007166283433, - 0.008550503583141718, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - -0.17364817766693033, - -0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), + final TiltConfig tiltConfigTest = TiltConfig( + direction: [TiltDirection.top, TiltDirection.left], ); - final TiltDataModel tiltDataExpect2 = TiltDataModel( - angle: Offset.zero, + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( + areaProgress: const Offset(1.0, 1.0), + tiltConfig: tiltConfigTest, + ).data; + final TiltDataModel tiltDataExpect2 = tiltDataTestCalculate( areaProgress: Offset.zero, - position: const Offset(5.0, 5.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.05, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( - tiltConfig: TiltConfig( - direction: [TiltDirection.top, TiltDirection.left], - ), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -337,36 +210,19 @@ void main() { expect(gesturesTypeTest, GesturesType.touch); expect(tiltDataTest, tiltDataExpect2); }); + testWidgets('enableRevert false', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, -tiltConfig.angle), + const TiltConfig tiltConfigTest = TiltConfig(enableRevert: false); + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - 0.17101007166283433, - 0.008550503583141718, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - -0.17364817766693033, - -0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( - tiltConfig: const TiltConfig(enableRevert: false), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -401,36 +257,19 @@ void main() { await tester.sendEventToBinding(testPointer.removePointer()); }); + testWidgets('enableReverse true', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(-tiltConfig.angle, tiltConfig.angle), + const TiltConfig tiltConfigTest = TiltConfig(enableReverse: true); + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - -0.17101007166283433, - -0.008550503583141718, - 0.0, - 0.984807753012208, - -0.17364817766693033, - -0.008682408883346517, - 0.17364817766693033, - 0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( - tiltConfig: const TiltConfig(enableReverse: true), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -443,58 +282,24 @@ void main() { expect(gesturesTypeTest, GesturesType.touch); expect(tiltDataTest, tiltDataExpect); }); + testWidgets('enableOutsideAreaMove false', (WidgetTester tester) async { TiltDataModel? moveTiltDataTest; TiltDataModel? leaveTiltDataTest; GesturesType? moveGesturesTypeTest; GesturesType? leaveGesturesTypeTest; int leaveCountTest = 0; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(tiltConfig.angle, -tiltConfig.angle), - areaProgress: const Offset(1.0, 1.0), - position: Offset.zero, - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - 0.17101007166283433, - 0.008550503583141718, - 0.0, - 0.984807753012208, - 0.17364817766693033, - 0.008682408883346517, - -0.17364817766693033, - -0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), + const TiltConfig tiltConfigTest = TiltConfig( + enableOutsideAreaMove: false, ); - final TiltDataModel tiltDataExpect2 = TiltDataModel( - angle: Offset.zero, + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( + areaProgress: const Offset(1.0, 1.0), + tiltConfig: tiltConfigTest, + ).data; + final TiltDataModel tiltDataExpect2 = tiltDataTestCalculate( areaProgress: Offset.zero, - position: const Offset(5.0, 5.0), - transform: Matrix4( - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.05, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( @@ -524,36 +329,19 @@ void main() { expect(leaveCountTest == 1, true); expect(leaveTiltDataTest, tiltDataExpect2); }); + testWidgets('enableGestureTouch false', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: const Offset(-8.0, 8.0), + const TiltConfig tiltConfigTest = TiltConfig(enableGestureTouch: false); + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( areaProgress: const Offset(-0.8, -0.8), - position: const Offset(9.0, 9.0), - transform: Matrix4( - 0.9902680687415704, - -0.019369152030840567, - -0.13781867790849958, - -0.006890933895424981, - 0.0, - 0.9902680687415704, - -0.13917310096006544, - -0.006958655048003273, - 0.13917310096006544, - 0.13781867790849958, - 0.9806308479691596, - 0.04903154239845798, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( - tiltConfig: const TiltConfig(enableGestureTouch: false), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; @@ -579,6 +367,7 @@ void main() { await tester.sendEventToBinding(testPointer.removePointer()); }); + testWidgets('enableGestureTouch false - scrolling', (WidgetTester tester) async { final ScrollController scrollController = ScrollController(); @@ -630,36 +419,19 @@ void main() { expect(gesturesTypeTest, null); expect(tiltDataTest, null); }); + testWidgets('enableGestureHover false', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; - final TiltDataModel tiltDataExpect = TiltDataModel( - angle: Offset(-tiltConfig.angle, tiltConfig.angle), + const TiltConfig tiltConfigTest = TiltConfig(enableGestureHover: false); + final TiltDataModel tiltDataExpect = tiltDataTestCalculate( areaProgress: const Offset(-1.0, -1.0), - position: Offset(tiltConfig.angle, tiltConfig.angle), - transform: Matrix4( - 0.984807753012208, - -0.030153689607045803, - -0.17101007166283433, - -0.008550503583141718, - 0.0, - 0.984807753012208, - -0.17364817766693033, - -0.008682408883346517, - 0.17364817766693033, - 0.17101007166283433, - 0.9698463103929541, - 0.04849231551964771, - 0.0, - 0.0, - 0.0, - 1.0, - ), - ); + tiltConfig: tiltConfigTest, + ).data; await tester.pumpWidget( TiltWidget( - tiltConfig: const TiltConfig(enableGestureHover: false), + tiltConfig: tiltConfigTest, onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { tiltDataTest = tiltData; gesturesTypeTest = gesturesType; diff --git a/test/utils_test.dart b/test/utils_test.dart index 0c072dd..45c42b7 100644 --- a/test/utils_test.dart +++ b/test/utils_test.dart @@ -4,7 +4,7 @@ import 'package:flutter_tilt/flutter_tilt.dart'; import 'package:flutter_tilt/src/utils.dart'; void main() { - group('utils', () { + group('utils ::', () { const sensorsPlatformSupport = Utils.sensorsPlatformSupport; const centerPosition = Utils.centerPosition; const radian = Utils.radian;