Solian/lib/widgets/current_state_action.dart

49 lines
1.6 KiB
Dart
Raw Normal View History

2024-06-06 12:23:50 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:get/get.dart';
import 'package:solian/providers/websocket.dart';
2024-06-08 13:35:50 +00:00
import 'package:solian/providers/auth.dart';
2024-06-06 12:23:50 +00:00
class BackgroundStateWidget extends StatelessWidget {
const BackgroundStateWidget({super.key});
@override
Widget build(BuildContext context) {
2024-06-08 13:35:50 +00:00
final AuthProvider auth = Get.find();
final WebSocketProvider ws = Get.find();
2024-06-06 12:23:50 +00:00
return Obx(() {
final disconnected = ws.isConnected.isFalse;
final connecting = ws.isConnecting.isTrue;
2024-06-06 12:23:50 +00:00
return Row(children: [
2024-07-24 17:18:47 +00:00
if (auth.isAuthorized.isTrue && disconnected && !connecting)
IconButton(
tooltip: [
if (ws.isConnected.isFalse)
'Lost Connection with Solar Network...',
].join('\n'),
icon: const Icon(Icons.wifi_off)
.animate(onPlay: (c) => c.repeat())
.fadeIn(duration: 800.ms)
.then()
.fadeOut(duration: 800.ms),
onPressed: () {
if (ws.isConnected.isFalse) ws.connect();
2024-06-06 12:23:50 +00:00
},
),
2024-07-24 17:18:47 +00:00
if (auth.isAuthorized.isTrue && connecting)
IconButton(
tooltip: [
if (ws.isConnecting.isTrue) 'Waiting Solar Network Connection...',
].join('\n'),
icon: const Icon(Icons.sync)
.animate(onPlay: (c) => c.repeat())
.rotate(duration: 1850.ms, begin: 1, end: 0),
onPressed: () {},
2024-06-06 12:23:50 +00:00
),
]);
});
}
}