diff options
Diffstat (limited to 'lib/Buttons/defrost_recirculate.dart')
-rw-r--r-- | lib/Buttons/defrost_recirculate.dart | 85 |
1 files changed, 34 insertions, 51 deletions
diff --git a/lib/Buttons/defrost_recirculate.dart b/lib/Buttons/defrost_recirculate.dart index 909bbf5..69adb89 100644 --- a/lib/Buttons/defrost_recirculate.dart +++ b/lib/Buttons/defrost_recirculate.dart @@ -5,20 +5,16 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg_provider/flutter_svg_provider.dart'; -import 'package:flutter_hvac/kuksa-server/vehicle-class.dart'; -import 'package:flutter_hvac/kuksa-server/vehicle-provider.dart'; -import 'package:flutter_hvac/kuksa-server/vehicle_methods.dart'; +import 'package:flutter_hvac/vehicle-signals/vehicle_ac_status_provider.dart'; +import 'package:flutter_hvac/vehicle-signals/vss_provider.dart'; +import 'package:flutter_hvac/vehicle-signals/vss_path.dart'; import 'package:flutter_hvac/size.dart'; class CustomButton extends ConsumerStatefulWidget { - WebSocket socket; - String serverPath; String img; String type; CustomButton({ Key? key, - required this.serverPath, - required this.socket, required this.img, required this.type, }) : super(key: key); @@ -30,7 +26,9 @@ class CustomButton extends ConsumerStatefulWidget { class _CustomButtonState extends ConsumerState<CustomButton> with SingleTickerProviderStateMixin { late AnimationController _controller; - late vehicle vehicledata; + late bool isFrontDefrosterActive; + late bool isRearDefrosterActive; + late bool isRecirculationActive; late Animation<Color?> _colorAnimation; @override @@ -51,35 +49,18 @@ class _CustomButtonState extends ConsumerState<CustomButton> }); _controller.addStatusListener((status) { - if (status == AnimationStatus.completed) { - if (widget.type == 'Front_defrost') { - VISS.set(widget.socket,ref, widget.serverPath, - vehicledata.isFrontDefrosterActive.toString()); - } - if (widget.type == "Rear_defrost") { - VISS.set(widget.socket,ref, widget.serverPath, - vehicledata.isRearDefrosterActive.toString()); - } - if (widget.type == "Recirculation") { - VISS.set(widget.socket,ref, widget.serverPath, - vehicledata.isRecirculationActive.toString()); - } - - - - } - if (status == AnimationStatus.dismissed) { - if (widget.type == 'Front_defrost') { - VISS.set(widget.socket, ref,widget.serverPath, - vehicledata.isFrontDefrosterActive.toString()); - } - if (widget.type == "Rear_defrost") { - VISS.set(widget.socket, ref,widget.serverPath, - vehicledata.isRearDefrosterActive.toString()); - } - if (widget.type == "Recirculation") { - VISS.set(widget.socket, ref,widget.serverPath, - vehicledata.isRecirculationActive.toString()); + if (status == AnimationStatus.completed || status == AnimationStatus.dismissed) { + var vss = ref.read(vssClientProvider); + if (vss != null) { + if (widget.type == 'Front_defrost') { + vss.setBool(VSSPath.vehicleIsFrontDefrosterActive, isFrontDefrosterActive, true); + } + if (widget.type == "Rear_defrost") { + vss.setBool(VSSPath.vehicleIsRearDefrosterActive, isRearDefrosterActive, true); + } + if (widget.type == "Recirculation") { + vss.setBool(VSSPath.vehicleIsRecirculationActive, isRecirculationActive, true); + } } } }); @@ -94,7 +75,10 @@ class _CustomButtonState extends ConsumerState<CustomButton> @override Widget build(BuildContext context) { - vehicledata = ref.watch(vehicleProvider); + isFrontDefrosterActive = ref.watch(vehicleAcStatusProvider.select((p) => p.isFrontDefrosterActive)); + isRearDefrosterActive = ref.watch(vehicleAcStatusProvider.select((p) => p.isRearDefrosterActive)); + isRecirculationActive = ref.watch(vehicleAcStatusProvider.select((p) => p.isRecirculationActive)); + return AnimatedBuilder( animation: _controller, builder: (BuildContext context, _) { @@ -108,20 +92,20 @@ class _CustomButtonState extends ConsumerState<CustomButton> decoration: BoxDecoration( gradient: widget.type == "Front_defrost" - ? vehicledata.isFrontDefrosterActive + ? isFrontDefrosterActive ? RadialGradient( colors: [Colors.black, Colors.lightBlue], radius: 2, ) : null : widget.type == "Rear_defrost" - ? vehicledata.isRearDefrosterActive + ? isRearDefrosterActive ? RadialGradient( colors: [Colors.black, Colors.lightBlue], radius: 2, ) : null - : vehicledata.isRecirculationActive + : isRecirculationActive ? RadialGradient( colors: [Colors.black, Colors.lightBlue], radius: 2, @@ -149,26 +133,25 @@ class _CustomButtonState extends ConsumerState<CustomButton> ), onTap: () { if (widget.type == "Front_defrost") { - vehicledata.isFrontDefrosterActive + isFrontDefrosterActive ? _controller.reverse() : _controller.forward(); - ref.read(vehicleProvider.notifier).update( - isFrontDefrosterActive: - !vehicledata.isFrontDefrosterActive); + ref.read(vehicleAcStatusProvider.notifier).update( + isFrontDefrosterActive: !isFrontDefrosterActive); } if (widget.type == "Rear_defrost") { - vehicledata.isRearDefrosterActive + isRearDefrosterActive ? _controller.reverse() : _controller.forward(); - ref.read(vehicleProvider.notifier).update( - isRearDefrosterActive: !vehicledata.isRearDefrosterActive); + ref.read(vehicleAcStatusProvider.notifier).update( + isRearDefrosterActive: !isRearDefrosterActive); } if (widget.type == "Recirculation") { - vehicledata.isRecirculationActive + isRecirculationActive ? _controller.reverse() : _controller.forward(); - ref.read(vehicleProvider.notifier).update( - isRecirculationActive: !vehicledata.isRecirculationActive); + ref.read(vehicleAcStatusProvider.notifier).update( + isRecirculationActive: !isRecirculationActive); } }, ); |