-
Notifications
You must be signed in to change notification settings - Fork 129
/
adaptive_offset_effect.dart
87 lines (78 loc) · 2.53 KB
/
adaptive_offset_effect.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:recipes_ui/core/widgets/gyroscope_effect.dart';
import 'package:recipes_ui/core/widgets/mouse_region_effect.dart';
typedef OffsetEffectBuilder = Widget Function(
BuildContext context,
Offset offset,
Widget? child,
);
class AdaptiveOffsetEffect extends StatelessWidget {
const AdaptiveOffsetEffect({
Key? key,
required this.width,
required this.height,
required this.child,
this.offsetMultiplier = 1,
this.childBuilder,
this.maxMovableDistance = 10,
}) : assert(child != null),
super(key: key);
const AdaptiveOffsetEffect.builder({
Key? key,
required this.width,
required this.height,
this.child,
this.offsetMultiplier = 1,
required this.childBuilder,
this.maxMovableDistance = 10,
}) : assert(childBuilder != null),
super(key: key);
final double width;
final double height;
/// Moving child widget
final Widget? child;
/// Maximum distance allowed for the child to move in
final double maxMovableDistance;
/// Value to multiply the movement offset to allow some widgets
/// to move further than the other
final double offsetMultiplier;
/// A builder that provides necessary data to build a moving child
/// with its child not rebuilding with the stream
final OffsetEffectBuilder? childBuilder;
@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.macOS ||
defaultTargetPlatform == TargetPlatform.linux) {
return childBuilder != null
? MouseRegionEffect.builder(
width: width,
height: height,
maxMovableDistance: maxMovableDistance,
offsetMultiplier: offsetMultiplier,
childBuilder: childBuilder,
child: child,
)
: MouseRegionEffect(
width: width,
height: height,
maxMovableDistance: maxMovableDistance,
offsetMultiplier: offsetMultiplier,
child: child,
);
} else {
return childBuilder != null
? GyroscopeEffect.builder(
maxMovableDistance: maxMovableDistance,
offsetMultiplier: offsetMultiplier,
childBuilder: childBuilder,
child: child,
)
: GyroscopeEffect(
maxMovableDistance: maxMovableDistance,
offsetMultiplier: offsetMultiplier,
child: child,
);
}
}
}