mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 14:47:23 +00:00
122 lines
3.7 KiB
Dart
122 lines
3.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import 'package:graphview/GraphView.dart';
|
|
import 'package:syncrow_web/pages/access_management/view/access_management.dart';
|
|
import 'package:syncrow_web/pages/auth/model/user_model.dart';
|
|
import 'package:syncrow_web/pages/device_managment/all_devices/view/device_managment_page.dart';
|
|
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|
import 'package:syncrow_web/pages/home/bloc/home_state.dart';
|
|
import 'package:syncrow_web/pages/home/home_model/home_item_model.dart';
|
|
import 'package:syncrow_web/services/home_api.dart';
|
|
import 'package:syncrow_web/utils/color_manager.dart';
|
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
|
|
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|
final Graph graph = Graph()..isTree = true;
|
|
final BuchheimWalkerConfiguration builder = BuchheimWalkerConfiguration();
|
|
List<Node> sourcesList = [];
|
|
List<Node> destinationsList = [];
|
|
static UserModel? user;
|
|
|
|
HomeBloc() : super((HomeInitial())) {
|
|
on<CreateNewNode>(_createNode);
|
|
fetchUserInfo();
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
Future fetchUserInfo() async {
|
|
try {
|
|
var uuid =
|
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
|
user = await HomeApi().fetchUserInfo(uuid);
|
|
emit(HomeUserInfoLoaded(user!)); // Emit state after fetching user info
|
|
} catch (e) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
List<HomeItemModel> homeItems = [
|
|
HomeItemModel(
|
|
title: 'Access',
|
|
icon: Assets.accessIcon,
|
|
active: true,
|
|
onPress: (context) {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (context) => AccessManagementPage()),
|
|
);
|
|
},
|
|
color: null,
|
|
),
|
|
HomeItemModel(
|
|
title: 'Space Management',
|
|
icon: Assets.spaseManagementIcon,
|
|
active: true,
|
|
onPress: (context) {},
|
|
color: ColorsManager.primaryColor,
|
|
),
|
|
HomeItemModel(
|
|
title: 'Devices',
|
|
icon: Assets.devicesIcon,
|
|
active: true,
|
|
onPress: (context) {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (context) => const DeviceManagementPage()),
|
|
);
|
|
},
|
|
color: ColorsManager.primaryColor,
|
|
),
|
|
HomeItemModel(
|
|
title: 'Move in',
|
|
icon: Assets.moveinIcon,
|
|
active: false,
|
|
onPress: (context) {},
|
|
color: ColorsManager.primaryColor,
|
|
),
|
|
HomeItemModel(
|
|
title: 'Construction',
|
|
icon: Assets.constructionIcon,
|
|
active: false,
|
|
onPress: (context) {},
|
|
color: ColorsManager.primaryColor,
|
|
),
|
|
HomeItemModel(
|
|
title: 'Energy',
|
|
icon: Assets.energyIcon,
|
|
active: false,
|
|
onPress: (context) {},
|
|
color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
|
),
|
|
HomeItemModel(
|
|
title: 'Integrations',
|
|
icon: Assets.integrationsIcon,
|
|
active: false,
|
|
onPress: (context) {},
|
|
color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
|
),
|
|
HomeItemModel(
|
|
title: 'Asset',
|
|
icon: Assets.assetIcon,
|
|
active: false,
|
|
onPress: (context) {},
|
|
color: ColorsManager.slidingBlueColor.withOpacity(0.2),
|
|
),
|
|
];
|
|
}
|