1 import 'package:flutter_ics_homescreen/export.dart';
2 import 'package:flutter_ics_homescreen/presentation/custom_icons/custom_icons.dart';
4 class CustomTrebleSlider extends ConsumerStatefulWidget {
5 const CustomTrebleSlider({
10 CustomTrebleSliderState createState() => CustomTrebleSliderState();
13 class CustomTrebleSliderState extends ConsumerState<CustomTrebleSlider> {
14 bool isPressed = false;
17 if (_currentVal < 10) {
19 ref.read(audioStateProvider.notifier).setTreble(_currentVal);
26 if (_currentVal > 0) {
28 ref.read(audioStateProvider.notifier).setTreble(_currentVal);
33 double _currentVal = 5;
35 Widget build(BuildContext context) {
37 ref.watch(audioStateProvider.select((audio) => audio.treble));
39 //crossAxisAlignment: CrossAxisAlignment.center,
42 padding: EdgeInsets.symmetric(vertical: 8),
45 style: TextStyle(fontSize: 40),
51 decoration: const ShapeDecoration(
52 gradient: LinearGradient(
54 AGLDemoColors.neonBlueColor,
55 AGLDemoColors.resolutionBlueColor,
56 Color.fromARGB(127, 20, 31, 100),
63 color: Color(0xFF5477D4),
68 mainAxisAlignment: MainAxisAlignment.spaceBetween,
71 padding: const EdgeInsets.only(left: 40),
78 color: AGLDemoColors.periwinkleColor,
86 data: SliderThemeData(
87 showValueIndicator: ShowValueIndicator.always,
88 trackShape: CustomRoundedRectSliderTrackShape(
89 silderVal: trebleValue),
90 activeTickMarkColor: Colors.transparent,
91 inactiveTickMarkColor: Colors.transparent,
92 inactiveTrackColor: AGLDemoColors.backgroundInsetColor,
93 thumbShape: PolygonSliderThumb(
94 sliderValue: 3, thumbRadius: 23, isPressed: isPressed),
102 onChanged: (newValue) {
103 ref.read(audioStateProvider.notifier).setTreble(newValue);
104 _currentVal = newValue;
106 onChangeEnd: (value) {
111 onChangeStart: (value) {
120 padding: const EdgeInsets.only(
129 color: AGLDemoColors.periwinkleColor,
141 class CustomBassSlider extends ConsumerStatefulWidget {
142 const CustomBassSlider({
147 CustomBassSliderState createState() => CustomBassSliderState();
150 class CustomBassSliderState extends ConsumerState<CustomBassSlider> {
151 bool isPressed = false;
155 if (_currentVal < 10) {
157 ref.read(audioStateProvider.notifier).setBass(_currentVal);
164 if (_currentVal > 0) {
166 ref.read(audioStateProvider.notifier).setBass(_currentVal);
171 double _currentVal = 5;
173 Widget build(BuildContext context) {
175 ref.watch(audioStateProvider.select((audio) => audio.bass));
178 //crossAxisAlignment: CrossAxisAlignment.center,
181 padding: EdgeInsets.symmetric(vertical: 8),
184 style: TextStyle(fontSize: 40),
190 decoration: const ShapeDecoration(
191 gradient: LinearGradient(
193 AGLDemoColors.neonBlueColor,
194 AGLDemoColors.resolutionBlueColor,
195 Color.fromARGB(127, 20, 31, 100),
200 shape: StadiumBorder(
202 color: Color(0xFF5477D4),
207 mainAxisAlignment: MainAxisAlignment.spaceBetween,
210 padding: const EdgeInsets.only(left: 40),
217 color: AGLDemoColors.periwinkleColor,
224 data: SliderThemeData(
225 showValueIndicator: ShowValueIndicator.always,
227 CustomRoundedRectSliderTrackShape(silderVal: bassValue),
228 activeTickMarkColor: Colors.transparent,
229 inactiveTickMarkColor: Colors.transparent,
230 inactiveTrackColor: AGLDemoColors.backgroundInsetColor,
231 thumbShape: PolygonSliderThumb(
232 sliderValue: 3, thumbRadius: 23, isPressed: isPressed),
240 onChanged: (newValue) {
241 ref.read(audioStateProvider.notifier).setBass(newValue);
242 _currentVal = newValue;
244 onChangeEnd: (value) {
249 onChangeStart: (value) {
258 padding: const EdgeInsets.only(right: 40),
265 color: AGLDemoColors.periwinkleColor,
277 class CustomRearFrontSlider extends ConsumerStatefulWidget {
278 const CustomRearFrontSlider({
283 CustomRearFrontState createState() => CustomRearFrontState();
286 class CustomRearFrontState extends ConsumerState<CustomRearFrontSlider> {
287 bool isPressed = false;
291 if (_currentVal < 10) {
293 ref.read(audioStateProvider.notifier).setRearFront(_currentVal);
300 if (_currentVal > 0) {
302 ref.read(audioStateProvider.notifier).setRearFront(_currentVal);
307 double _currentVal = 5;
309 Widget build(BuildContext context) {
310 final rearFrontValue =
311 ref.watch(audioStateProvider.select((audio) => audio.rearFront));
313 //crossAxisAlignment: CrossAxisAlignment.center,
316 padding: EdgeInsets.symmetric(vertical: 8),
319 style: TextStyle(fontSize: 40),
325 decoration: const ShapeDecoration(
326 gradient: LinearGradient(
328 AGLDemoColors.neonBlueColor,
329 AGLDemoColors.resolutionBlueColor,
330 Color.fromARGB(127, 20, 31, 100),
335 shape: StadiumBorder(
337 color: Color(0xFF5477D4),
342 mainAxisAlignment: MainAxisAlignment.spaceBetween,
345 padding: const EdgeInsets.only(left: 40),
351 CustomIcons.slider_rear,
352 color: AGLDemoColors.periwinkleColor,
359 data: SliderThemeData(
360 showValueIndicator: ShowValueIndicator.always,
361 trackShape: CustomRoundedRectSliderTrackShape(
362 silderVal: rearFrontValue, isFrontRear: true),
363 activeTickMarkColor: Colors.transparent,
364 inactiveTickMarkColor: Colors.transparent,
365 inactiveTrackColor: AGLDemoColors.backgroundInsetColor,
366 thumbShape: PolygonSliderThumb(
367 sliderValue: 3, thumbRadius: 23, isPressed: isPressed),
374 value: rearFrontValue,
375 onChanged: (newValue) {
377 .read(audioStateProvider.notifier)
378 .setRearFront(newValue);
379 _currentVal = newValue;
381 onChangeEnd: (value) {
386 onChangeStart: (value) {
395 padding: const EdgeInsets.only(right: 40),
401 CustomIcons.slider_front,
402 color: AGLDemoColors.periwinkleColor,
414 class PolygonSliderThumb extends SliderComponentShape {
415 final double thumbRadius;
416 final double sliderValue;
417 final bool isPressed;
418 const PolygonSliderThumb(
419 {required this.thumbRadius,
420 required this.sliderValue,
421 this.isPressed = false});
424 Size getPreferredSize(bool isEnabled, bool isDiscrete) {
425 return Size.fromRadius(thumbRadius);
430 PaintingContext context,
432 required Animation<double> activationAnimation,
433 required Animation<double> enableAnimation,
434 required bool isDiscrete,
435 required TextPainter labelPainter,
436 required RenderBox parentBox,
437 required SliderThemeData sliderTheme,
438 required TextDirection textDirection,
439 required double value,
440 required double textScaleFactor,
441 required Size sizeWithOverflow,
443 // Define the slider thumb design here
444 final Canvas canvas = context.canvas;
445 var paintStroke = Paint()
447 isPressed ? AGLDemoColors.jordyBlueColor : AGLDemoColors.neonBlueColor
449 ..style = PaintingStyle.stroke
450 ..strokeCap = StrokeCap.round;
451 var paintFill = Paint()
452 ..color = isPressed ? Colors.white : AGLDemoColors.periwinkleColor
454 ..style = PaintingStyle.fill
455 ..strokeCap = StrokeCap.round;
457 path.addOval(Rect.fromCircle(
461 canvas.drawCircle(center, isPressed ? 37 : 32, paintFill);
462 canvas.drawShadow(path, Colors.black26, 0.5, false);
463 canvas.drawCircle(center, isPressed ? 21 : 16, paintStroke);
467 //TODO add border to custom track Shape
468 class CustomRoundedRectSliderTrackShape extends SliderTrackShape
469 with BaseSliderTrackShape {
470 final double silderVal;
471 final bool? isFrontRear;
473 CustomRoundedRectSliderTrackShape({
474 required this.silderVal,
475 this.isFrontRear = false,
479 PaintingContext context,
481 required RenderBox parentBox,
482 required SliderThemeData sliderTheme,
483 required Animation<double> enableAnimation,
484 required TextDirection textDirection,
485 required Offset thumbCenter,
486 Offset? secondaryOffset,
487 bool isDiscrete = false,
488 bool isEnabled = false,
489 double additionalActiveTrackHeight = 2,
491 assert(sliderTheme.disabledActiveTrackColor != null);
492 assert(sliderTheme.disabledInactiveTrackColor != null);
493 assert(sliderTheme.activeTrackColor != null);
494 assert(sliderTheme.inactiveTrackColor != null);
495 assert(sliderTheme.thumbShape != null);
496 if (sliderTheme.trackHeight == null || sliderTheme.trackHeight! <= 0) {
500 final Rect trackRect = getPreferredRect(
501 parentBox: parentBox,
503 sliderTheme: sliderTheme,
504 isEnabled: isEnabled,
505 isDiscrete: isDiscrete,
507 final Radius trackRadius = Radius.circular(trackRect.height / 2);
508 final Radius activeTrackRadius =
509 Radius.circular((trackRect.height + additionalActiveTrackHeight) / 2);
510 final activeGradientRect = Rect.fromLTRB(
512 textDirection == TextDirection.ltr
513 ? trackRect.top - (additionalActiveTrackHeight / 2)
516 (textDirection == TextDirection.ltr)
517 ? trackRect.bottom + (additionalActiveTrackHeight / 2)
521 LinearGradient gradient = const LinearGradient(
522 colors: [AGLDemoColors.jordyBlueColor, Colors.white]);
523 // Assign the track segment paints, which are leading: active and
524 // trailing: inactive.
525 final ColorTween activeTrackColorTween = ColorTween(
526 begin: sliderTheme.disabledActiveTrackColor,
527 end: sliderTheme.activeTrackColor);
528 final ColorTween inactiveTrackColorTween = ColorTween(
529 begin: sliderTheme.disabledInactiveTrackColor,
530 end: sliderTheme.inactiveTrackColor);
531 final Paint activePaint = Paint()
532 ..shader = gradient.createShader(activeGradientRect)
533 ..color = activeTrackColorTween.evaluate(enableAnimation)!;
534 final Paint inactivePaint = Paint()
535 ..color = inactiveTrackColorTween.evaluate(enableAnimation)!;
536 final Paint leftTrackPaint;
537 final Paint rightTrackPaint;
538 switch (textDirection) {
539 case TextDirection.ltr:
540 leftTrackPaint = activePaint;
541 rightTrackPaint = inactivePaint;
542 case TextDirection.rtl:
543 leftTrackPaint = inactivePaint;
544 rightTrackPaint = activePaint;
548 Rect.fromLTWH(trackRect.right / 2, trackRect.bottom / 2 + 15, 10, 40);
549 context.canvas.drawRRect(
550 RRect.fromRectAndCorners(smallRect,
551 topLeft: const Radius.circular(25),
552 topRight: const Radius.circular(25),
553 bottomLeft: const Radius.circular(25),
554 bottomRight: const Radius.circular(25)),
555 //silderVal > 5 ? leftTrackPaint : rightTrackPaint);
562 context.canvas.drawRRect(
563 RRect.fromLTRBAndCorners(
565 (textDirection == TextDirection.ltr)
566 ? trackRect.top - (additionalActiveTrackHeight / 2)
569 (textDirection == TextDirection.ltr)
570 ? trackRect.bottom + (additionalActiveTrackHeight / 2)
572 topLeft: (textDirection == TextDirection.ltr)
575 bottomLeft: (textDirection == TextDirection.ltr)
579 isFrontRear! ? rightTrackPaint : leftTrackPaint,
582 context.canvas.drawRRect(
583 RRect.fromLTRBAndCorners(
585 (textDirection == TextDirection.rtl)
586 ? trackRect.top - (additionalActiveTrackHeight / 2)
589 (textDirection == TextDirection.rtl)
590 ? trackRect.bottom + (additionalActiveTrackHeight / 2)
592 topRight: (textDirection == TextDirection.rtl)
595 bottomRight: (textDirection == TextDirection.rtl)