-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
147 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lib/features/meeting/presentation/bloc/drawing/drawing_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:injectable/injectable.dart'; | ||
import 'package:waterbus/features/meeting/presentation/socket/drawing/socket_draw_event.dart'; | ||
import 'package:waterbus/features/meeting/presentation/socket/drawing/socket_draw_handle.dart'; | ||
|
||
part 'drawing_event.dart'; | ||
part 'drawing_state.dart'; | ||
|
||
@injectable | ||
class DrawingBloc extends Bloc<DrawingEvent, DrawingState> { | ||
final SocketDrawHandle _socketDrawHandle; | ||
|
||
DrawingBloc(this._socketDrawHandle) : super(DrawingInitialState()) { | ||
on<DrawingEvent>((event, emit) { | ||
if (event is OnDrawingChangedEvent) { | ||
_hanldeChangeDraw(); | ||
|
||
emit(DrawingChangedState(points: event.points)); | ||
} | ||
|
||
if (event is OnDrawingDeletedEvent) { | ||
emit(DrawingChangedState(points: [])); | ||
} | ||
}); | ||
} | ||
void _hanldeChangeDraw() { | ||
_socketDrawHandle.onSendSocket(SocketDrawEvent.updateBoard); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
lib/features/meeting/presentation/bloc/drawing/drawing_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
part of 'drawing_bloc.dart'; | ||
|
||
class DrawingEvent {} | ||
|
||
class OnDrawingChangedEvent extends DrawingEvent { | ||
final List<Offset?> points; | ||
OnDrawingChangedEvent({required this.points}); | ||
} | ||
|
||
class OnDrawingDeletedEvent extends DrawingEvent {} |
16 changes: 16 additions & 0 deletions
16
lib/features/meeting/presentation/bloc/drawing/drawing_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
part of 'drawing_bloc.dart'; | ||
|
||
abstract class DrawingState { | ||
List get props => []; | ||
} | ||
|
||
final class DrawingInitialState extends DrawingState {} | ||
|
||
final class DrawingChangedState extends DrawingState { | ||
final List<Offset?> points; | ||
|
||
DrawingChangedState({required this.points}); | ||
|
||
@override | ||
List get props => [points]; | ||
} |
2 changes: 1 addition & 1 deletion
2
...res/meeting/socket/socket_draw_event.dart → ...ion/socket/drawing/socket_draw_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class SocketDrawEvent { | ||
static String drawingBoard = 'DRAWING_BOARD'; | ||
static String updateBoard = 'DRAWING_BOARD'; | ||
static String deleteBoard = 'DELETE_BOARD'; | ||
} |
34 changes: 34 additions & 0 deletions
34
lib/features/meeting/presentation/socket/drawing/socket_draw_handle.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:injectable/injectable.dart'; | ||
import 'package:socket_io_client/socket_io_client.dart'; | ||
import 'package:waterbus/features/app/bloc/bloc.dart'; | ||
import 'package:waterbus/features/meeting/presentation/bloc/drawing/drawing_bloc.dart'; | ||
import 'package:waterbus/features/meeting/presentation/socket/drawing/socket_draw_event.dart'; | ||
import 'package:waterbus_sdk/core/websocket/interfaces/socket_handler_interface.dart'; | ||
|
||
@injectable | ||
class SocketDrawHandle { | ||
final SocketHandler _webSocket; | ||
SocketDrawHandle(this._webSocket); | ||
void onListenSocket() { | ||
final Socket? socket = _webSocket.socket; | ||
|
||
if (socket == null || !socket.active) return; | ||
|
||
socket.onConnect((_) async { | ||
socket.on(SocketDrawEvent.updateBoard, (data) { | ||
if (data == null) return; | ||
|
||
AppBloc.drawingBloc.add(OnDrawingChangedEvent(points: [])); | ||
print(data); | ||
}); | ||
}); | ||
} | ||
|
||
void onSendSocket(String event) { | ||
final Socket? socket = _webSocket.socket; | ||
if (socket == null || !socket.active) return; | ||
socket.onConnect((_) async { | ||
socket.emit(event); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.