modify reservation table page, add socket io client for real time data update, modify makanan list page

This commit is contained in:
kicap
2023-08-25 04:21:55 +08:00
parent 6c5bfde828
commit d96a14e062
30 changed files with 726 additions and 165 deletions

View File

@ -6,7 +6,7 @@ import '../app/app.logger.dart';
class MyHttpServices {
final log = getLogger('MyHttpServices');
final _options = BaseOptions(
baseUrl: dotenv.env['api_url']!,
baseUrl: dotenv.env['url']!,
connectTimeout: const Duration(seconds: 120),
receiveTimeout: const Duration(seconds: 120),
);

View File

@ -0,0 +1,48 @@
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:socket_io_client/socket_io_client.dart';
import '../app/app.logger.dart';
class MySocketIoClient {
final log = getLogger('MySocketIoClient');
final String _url = dotenv.env['url']!;
static final MySocketIoClient _instance = MySocketIoClient._internal();
factory MySocketIoClient() => _instance;
MySocketIoClient._internal();
late Socket _socket;
Socket get socket => _socket;
Future<void> init() async {
try {
_socket = io(_url, <String, dynamic>{
'transports': ['websocket'],
'autoConnect': false,
});
_socket.connect();
log.i('socket connected');
} catch (e) {
log.e('error : $e');
}
}
Future<void> emit(String event, dynamic data) async {
_socket.emit(event, data);
}
Future<void> on(String event, Function(dynamic) callback) async {
_socket.on(event, callback);
}
Future<void> off(String event) async {
_socket.off(event);
}
Future<void> disconnect() async {
_socket.disconnect();
}
Future<void> connect() async {
_socket.connect();
}
}