/
main.dart
410 lines (385 loc) · 12.7 KB
/
main.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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
import 'package:device_preview/device_preview.dart';
import 'package:example/widgets/vx_shapes.dart';
import 'package:flutter/material.dart';
import 'package:velocity_x/velocity_x.dart';
import 'examples/animated_page_view.dart';
import 'examples/second_page.dart';
import 'models/dummy.dart';
import 'new/demo_list.dart';
import 'widgets/draw_android.dart';
// First way to monitor changes in the routing stack:
void main() {
Vx.setPathUrlStrategy();
/*In this example, we define two functions: debouncedFunction and
throttledFunction.
We apply the debounce and throttle extension methods
to these functions, respectively, with a delay of 2 seconds.
When we call debouncedFunction twice in quick succession,
the function is not executed immediately.
Instead, the delay time of 2 seconds is reset each time,
and the function will only be executed after 2 seconds of inactivity.
On the other hand, when we call throttledFunction twice
in quick succession, the function is executed immediately
on the first call. However, the second call is ignored (throttled)
because it occurs within the 2-second delay period.
After the delay time of 2 seconds expires, subsequent calls to
throttledFunction will execute the function immediately,
resetting the delay time for each call. */
final debouncedFunction = () {
Vx.log("Debounced function executed");
}.debounce(const Duration(seconds: 2));
final throttledFunction = () {
Vx.log("Throttled function executed");
}.throttle(const Duration(seconds: 2));
// Simulating event triggers
debouncedFunction(); // Debounced function is not executed immediately
debouncedFunction(); // Debounced function is not executed immediately
throttledFunction(); // Throttled function is executed immediately
throttledFunction(); // Throttled function is ignored (throttled) within the delay time
// After 2 seconds...
// Output: Debounced function executed
// After another 2 seconds...
// Output: Throttled function executed
// After another 2 seconds...
// Output: Throttled function executed
runApp(
DevicePreview(
enabled: false,
// data: DevicePreviewData(
// deviceIdentifier: Devices.ios.iPad.toString(),
// isFrameVisible: true,
// ),
builder: (context) => VxApp(
store: MyStore(),
builder: (context, VxAppData data) {
return MaterialApp(
locale: DevicePreview.locale(context),
builder: (context, child) {
Vx.log(context.screenWidth);
return VxAdaptive(
designWidth: context.isMobile ? context.screenWidth : 1200,
scaleType: VxAdaptiveScaleType.width,
builder: (context, scaled) {
return DevicePreview.appBuilder(context, child);
});
},
theme: ThemeData(
useMaterial3: true,
brightness:
data.isDarkMode ? Brightness.dark : Brightness.light),
home: const DemoList(),
debugShowCheckedModeBanner: false,
);
},
),
),
);
}
class Demo extends StatefulWidget {
const Demo({super.key});
@override
DemoState createState() => DemoState();
}
class DemoState extends State<Demo> {
final VxPopupMenuController _controller = VxPopupMenuController();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: VStack([
const VxOrderedList(
[
"Hello",
"World",
"Flutter",
"Dart",
"VelocityX",
],
type: VxListType.upperRoman,
color: Colors.blueAccent,
direction: Axis.horizontal,
shrinkWrap: false,
).wh(300, 50),
"Vx Demo".text.white.makeCentered().circle(radius: 100).shadow4xl,
10.heightBox,
DrawAndroid(),
10.heightBox,
// TimelineExample(),
// AnimatedBoxExample(),
// VxAnimationExample(),
// VxAnimator<double>(
// builder: (context, animState, child) {
// return VxBox()
// .rounded
// .alignCenter
// .pink400
// .square(animState.value)
// .makeCentered();
// },
// ).easeInCubic.doubleTween(10.0, 200.0).seconds(sec: 10).infinite.make(),
20.heightBox,
"Hello"
.text
.make()
.box
.p8
.rounded
.red400
.alignCenter
.withConstraints(
const BoxConstraints(maxWidth: 100, minWidth: 50))
.make()
.badge(
size: 20,
count: 200,
limit: false,
color: Colors.black,
// optionalWidget: Icon(
// Icons.notification_important,
// size: 8.0,
// color: Colors.white,
// ),
type: VxBadgeType.round)
.onInkTap(() {
// Show Toast
context.showToast(msg: "Hello Vx", position: VxToastPosition.top);
// VxToast.showLoading(context, msg: "Loading");
/// or
// VxToast.show(context, msg: "Hello from vx", showTime: 10000);
/// Or Show loading
// final close = context.showLoading(
// msg: "Loading",
// );
// Future.delayed(2.seconds, close);
}),
10.heightBox,
"Breaking news from VelocityX - v1.0.0 Released"
.marquee()
.h10(context),
const TapMeWidget(),
10.heightBox,
VxStepper(onChange: (value) {
Vx.log(value);
}),
10.heightBox,
VxRating(
onRatingUpdate: (value) {},
count: 5,
selectionColor: Colors.teal,
size: 30,
stepInt: true,
),
20.heightBox,
const VxTextField(
obscureText: true,
borderType: VxTextFieldBorderType.roundLine,
isPassword: true,
),
20.heightBox,
(context.isMobile ? 'We are on mobile' : 'We are on Web')
.selectableText
.bold
.white
.size(context.isMobile ? 20 : 40)
.center
.make()
.animatedBox
.width(!context.isMobile
? context.screenWidth
: context.percentWidth * 50)
.height(context.percentHeight * 20)
.rounded
.p8
.alignCenter
.shadow2xl
.linearGradient([Vx.teal400, Vx.indigo400]).makeCentered(),
20.heightBox,
List.generate(
50,
(index) => "Item $index"
.text
.white
.make()
.box
.rounded
.alignCenter
.color(Vx.randomOpaqueColor)
.make()
.p4()).swiper(
height: context.isMobile ? 200 : 400,
enlargeCenterPage: true,
autoPlay: false,
onPageChanged: (index) {
Vx.log(index);
},
isFastScrollingEnabled: true,
scrollDirection:
context.isMobile ? Axis.horizontal : Axis.horizontal),
20.heightBox,
const VxDevice(mobile: Text("Hi Mobile"), web: Text("Hi Web")),
const VxResponsive(
xsmall: Text("Hi Extra Small"),
small: Text("Hi Small"),
medium: Text("Hi Medium"),
large: Text("Hi Large"),
xlarge: Text("Hi Extra Large"),
fallback: Text("Hi Nothing Specified"),
),
"Card Sample"
.text
.makeCentered()
.card
.color(Vx.indigo500)
.make()
.h10(context)
.onMouseHover((event) {
Vx.log(event.distance);
}).onMouseEnter((event) {
Vx.log(event.delta);
}),
20.heightBox,
"100100.1546".numCurrency.text.make(),
12341.42334.numCurrencyWithLocale(locale: "hi_IN").text.make(),
10.heightBox,
"https://avatars0.githubusercontent.com/u/12619420?s=460&u=26db98cbde1dd34c7c67b85c240505a436b2c36d&v=4"
.circularNetworkImage(),
10.heightBox,
const VxDash(
dashColor: Colors.red,
),
10.heightBox,
DateTime.now().subtract(10.minutes).timeAgo().text.make(),
const VxShapes(),
20.heightBox,
Container(
padding: Vx.m20,
child: const Icon(Icons.menu),
).popupMenu(
() => ClipRRect(
borderRadius: BorderRadius.circular(5),
child: IntrinsicWidth(
child: VStack(
[
ItemModel(
"Chat",
Icons.chat_bubble,
),
ItemModel(
"Add",
Icons.group_add,
)
]
.map(
(item) => GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
Vx.log(item.title);
},
child: HStack(
[
Icon(
item.icon,
size: 15,
color: Colors.white,
),
Expanded(
child: Text(
item.title,
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
)
.box
.margin(Vx.mOnly(left: 10))
.padding(Vx.mSymmetric(v: 10))
.make(),
),
],
).box.height(40).padding(Vx.mSymmetric(h: 20)).make(),
),
)
.toList(),
crossAlignment: CrossAxisAlignment.stretch,
),
)
.box
.color(
const Color(0xFF4C4C4C),
)
.make(),
),
clickType: VxClickType.singleClick,
verticalMargin: -10,
controller: _controller,
),
20.heightBox,
const AnimatedPageView(),
20.heightBox,
"Neumorphic"
.text
.bold
.make()
.box
.alignCenter
.width(200)
.height(200)
.roundedLg
.neumorphic(color: Colors.white, curve: VxCurve.flat)
.make(),
20.widthBox,
const VxUnorderedList(
["Disc Item 1", "Disc Item 2"],
primary: false,
),
const VxOrderedList(
["Decimal Item 1", "Decimal Item 2"],
primary: false,
),
["Item 1", "Item 2", "Item 3"]
.textDropDown(
selectedValue: "Item 1",
onChanged: (value) {
Vx.log(value!);
},
)
.make(),
]).p16().scrollVertical(),
),
);
}
}
class TapMeWidget extends StatelessWidget {
const TapMeWidget({super.key});
@override
Widget build(BuildContext context) {
return [
"Tap me"
.text
.maxLines(4)
.semiBold
.ellipsis
.blue500
.minFontSize(20)
.make(),
"assets/vxbox.png".circularAssetImage(radius: 50)
].row().onInkTap(() {
context.vxnavigator!.push(const SecondPage("assets/vxbox.png")
.vxPreviewRoute(parentContext: context));
});
}
}
class MyStore extends VxStore {
int count = 0;
}
class MyMutation extends VxMutation<MyStore> {
MyMutation();
@override
void perform() {
store!.count++;
}
}