Solian/lib/widgets/current_state_action.dart

66 lines
2.1 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: [
if (disconnected && !connecting)
2024-06-08 13:35:50 +00:00
FutureBuilder(
future: auth.isAuthorized,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == false) {
return const SizedBox();
}
return IconButton(
tooltip: [
if (ws.isConnected.isFalse)
'Lost Connection with Solar Network...',
2024-06-08 13:35:50 +00:00
].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-08 13:35:50 +00:00
},
);
2024-06-06 12:23:50 +00:00
},
),
if (connecting)
2024-06-08 13:35:50 +00:00
FutureBuilder(
future: auth.isAuthorized,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == false) {
return const SizedBox();
}
return IconButton(
tooltip: [
if (ws.isConnecting.isTrue)
'Waiting Solar Network Connection...',
2024-06-08 13:35:50 +00:00
].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
),
]);
});
}
}