home_layout.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import 'dart:io' show Platform;
  2. import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
  3. import 'package:flowy_infra/size.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_bloc/flutter_bloc.dart';
  6. // ignore: import_of_legacy_library_into_null_safe
  7. import 'package:sized_context/sized_context.dart';
  8. import 'home_sizes.dart';
  9. class HomeLayout {
  10. late double menuWidth;
  11. late bool showMenu;
  12. late bool menuIsDrawer;
  13. late bool showEditPanel;
  14. late double editPanelWidth;
  15. late double homePageLOffset;
  16. late double homePageROffset;
  17. late double menuSpacing;
  18. late Duration animDuration;
  19. HomeLayout(BuildContext context, BoxConstraints homeScreenConstraint) {
  20. final homeSetting = context.read<HomeSettingBloc>().state;
  21. showEditPanel = homeSetting.panelContext.isSome();
  22. menuWidth = Sizes.sideBarWidth;
  23. menuWidth += homeSetting.resizeOffset;
  24. final screenWidthPx = context.widthPx;
  25. context
  26. .read<HomeSettingBloc>()
  27. .add(HomeSettingEvent.checkScreenSize(screenWidthPx));
  28. if (homeSetting.isMenuCollapsed) {
  29. showMenu = false;
  30. } else {
  31. showMenu = true;
  32. menuIsDrawer = context.widthPx <= PageBreaks.tabletPortrait;
  33. }
  34. homePageLOffset = (showMenu && !menuIsDrawer) ? menuWidth : 0.0;
  35. menuSpacing = !showMenu && Platform.isMacOS ? 80.0 : 0.0;
  36. animDuration = homeSetting.resizeType.duration();
  37. editPanelWidth = HomeSizes.editPanelWidth;
  38. homePageROffset = showEditPanel ? editPanelWidth : 0;
  39. }
  40. }