mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
34 lines
1.1 KiB
Dart
34 lines
1.1 KiB
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:graphview/GraphView.dart';
|
|
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|
import 'package:syncrow_web/pages/home/bloc/home_state.dart';
|
|
|
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|
final Graph graph = Graph()..isTree = true;
|
|
final BuchheimWalkerConfiguration builder = BuchheimWalkerConfiguration();
|
|
List<Node> sourcesList = [];
|
|
List<Node> destinationsList = [];
|
|
|
|
HomeBloc() : super((HomeInitial())) {
|
|
on<CreateNewNode>(_createNode);
|
|
}
|
|
|
|
void _createNode(CreateNewNode event, Emitter<HomeState> emit) async {
|
|
emit(HomeInitial());
|
|
sourcesList.add(event.sourceNode);
|
|
destinationsList.add(event.destinationNode);
|
|
|
|
for (int i = 0; i < sourcesList.length; i++) {
|
|
graph.addEdge(sourcesList[i], destinationsList[i]);
|
|
}
|
|
|
|
builder
|
|
..siblingSeparation = (100)
|
|
..levelSeparation = (150)
|
|
..subtreeSeparation = (150)
|
|
..orientation = (BuchheimWalkerConfiguration.ORIENTATION_TOP_BOTTOM);
|
|
|
|
emit(HomeUpdateTree(graph: graph, builder: builder));
|
|
}
|
|
}
|