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';
|
2024-07-16 11:46:53 +00:00
|
|
|
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();
|
2024-07-16 11:46:53 +00:00
|
|
|
final WebSocketProvider ws = Get.find();
|
2024-06-06 12:23:50 +00:00
|
|
|
|
|
|
|
return Obx(() {
|
2024-07-16 11:46:53 +00:00
|
|
|
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: [
|
2024-07-16 11:46:53 +00:00
|
|
|
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: () {
|
2024-07-16 11:46:53 +00:00
|
|
|
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: [
|
2024-07-16 11:46:53 +00:00
|
|
|
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
|
|
|
),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|