onboarding_common_widgets.dart
5.2 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import 'dart:math' as math;
import 'package:doublefeel_flutter/core/theme/app_theme.dart';
import 'package:flutter/material.dart';
class OnboardingPageScrollBody extends StatelessWidget {
const OnboardingPageScrollBody({
super.key,
required this.child,
this.horizontalPadding = 16,
this.topPadding = null,
});
final Widget child;
final double horizontalPadding;
final double? topPadding;
@override
Widget build(BuildContext context) {
final topPadding =
this.topPadding ?? (MediaQuery.paddingOf(context).top + 4);
// this.topPadding ?? (MediaQuery.paddingOf(context).top + 48);
// final topPadding = 48.0;
return SingleChildScrollView(
physics: const ClampingScrollPhysics(),
padding: EdgeInsets.fromLTRB(
horizontalPadding,
topPadding,
horizontalPadding,
140,
),
child: child,
);
}
}
class OnboardingTitleText extends StatelessWidget {
const OnboardingTitleText(
this.text, {
super.key,
this.maxWidth = 330,
});
final String text;
final double maxWidth;
@override
Widget build(BuildContext context) {
return Center(
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth),
child: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: context.colors.textPrimary,
fontSize: 20,
fontWeight: FontWeight.w600,
height: 1.3,
letterSpacing: 0,
),
),
),
);
}
}
class OnboardingBodyText extends StatelessWidget {
const OnboardingBodyText(
this.text, {
super.key,
this.fontSize = 16,
});
final String text;
final double fontSize;
@override
Widget build(BuildContext context) {
return Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: context.colors.textPrimary,
fontSize: fontSize,
fontWeight: FontWeight.w400,
height: 1.38,
letterSpacing: 0,
),
);
}
}
class OnboardingBottomButton extends StatelessWidget {
const OnboardingBottomButton({
super.key,
required this.label,
required this.enabled,
required this.onPressed,
});
final String label;
final bool enabled;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
final width = math.min(280.0, MediaQuery.sizeOf(context).width - 96);
return Center(
child: SizedBox(
width: width,
height: 48,
child: ElevatedButton(
onPressed: enabled ? onPressed : null,
style: ElevatedButton.styleFrom(
backgroundColor: context.colors.primary,
disabledBackgroundColor:
context.colors.primary.withValues(alpha: 0.4),
foregroundColor: Colors.white,
disabledForegroundColor: Colors.white,
elevation: 0,
shadowColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
textStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
letterSpacing: 0,
),
),
child: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
);
}
}
class StaggeredEntranceItem extends StatefulWidget {
const StaggeredEntranceItem({
super.key,
required this.index,
required this.child,
});
final int index;
final Widget child;
@override
State<StaggeredEntranceItem> createState() => _StaggeredEntranceItemState();
}
class _StaggeredEntranceItemState extends State<StaggeredEntranceItem> {
bool _visible = false;
@override
void initState() {
super.initState();
Future.delayed(Duration(milliseconds: 100 * widget.index), () {
if (!mounted) {
return;
}
setState(() {
_visible = true;
});
});
}
@override
Widget build(BuildContext context) {
return AnimatedOpacity(
opacity: _visible ? 1 : 0,
duration: const Duration(milliseconds: 600),
curve: Curves.easeOutCubic,
child: AnimatedPadding(
duration: const Duration(milliseconds: 600),
curve: Curves.easeOutCubic,
padding: _visible
? EdgeInsets.zero
: const EdgeInsets.only(top: 24, bottom: 0),
child: widget.child,
),
);
}
}
class OnboardingPageIndicators extends StatelessWidget {
const OnboardingPageIndicators({
super.key,
required this.activeIndex,
required this.count,
});
final int activeIndex;
final int count;
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(count, (index) {
return Container(
width: 27,
height: 4,
margin: const EdgeInsets.symmetric(horizontal: 2),
decoration: BoxDecoration(
color: index == activeIndex
? context.colors.primary
: const Color(0xFFD6C7FC),
borderRadius: BorderRadius.circular(19),
),
);
}),
);
}
}