Fixed project structure
This commit is contained in:
parent
db5745f827
commit
015aa38e16
12 changed files with 1136 additions and 1270 deletions
|
|
@ -1,59 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:socket_io_client/socket_io_client.dart';
|
||||
|
||||
class SocketConnectionIndicator extends StatefulWidget {
|
||||
final Socket socket;
|
||||
final double size;
|
||||
|
||||
const SocketConnectionIndicator(
|
||||
{super.key, required this.socket, this.size = 12});
|
||||
|
||||
@override
|
||||
State<SocketConnectionIndicator> createState() =>
|
||||
_SocketConnectionIndicatorState();
|
||||
}
|
||||
|
||||
class _SocketConnectionIndicatorState extends State<SocketConnectionIndicator> {
|
||||
var connectionStateColor = Colors.amber.obs;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
connectionStateColor =
|
||||
widget.socket.connected ? Colors.green.obs : Colors.red.obs;
|
||||
|
||||
widget.socket.onConnect((data) {
|
||||
connectionStateColor.value = Colors.green;
|
||||
});
|
||||
widget.socket.onConnecting((data) {
|
||||
connectionStateColor.value = Colors.amber;
|
||||
});
|
||||
widget.socket.onReconnectAttempt((data) {
|
||||
connectionStateColor.value = Colors.blue;
|
||||
});
|
||||
widget.socket.onDisconnect((data) {
|
||||
connectionStateColor.value = Colors.red;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkResponse(
|
||||
onTap: () {
|
||||
widget.socket.disconnect().connect();
|
||||
},
|
||||
child: Obx(
|
||||
() => Container(
|
||||
width: widget.size,
|
||||
height: widget.size,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: connectionStateColor.value,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue