home_layout.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'dart:io' show Platform;
  2. import 'package:app_flowy/workspace/application/home/home_bloc.dart';
  3. import 'package:flowy_infra/size.dart';
  4. import 'package:flutter/material.dart';
  5. // ignore: import_of_legacy_library_into_null_safe
  6. import 'package:sized_context/sized_context.dart';
  7. import 'package:flutter_bloc/flutter_bloc.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. bool forceCollapse) {
  21. final homeBlocState = context.read<HomeBloc>().state;
  22. showEditPanel = homeBlocState.panelContext.isSome();
  23. menuWidth = Sizes.sideBarMed;
  24. if (context.widthPx >= PageBreaks.desktop) {
  25. menuWidth = Sizes.sideBarLg;
  26. }
  27. menuWidth += homeBlocState.resizeOffset;
  28. if (forceCollapse) {
  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 = homeBlocState.resizeType.duration();
  37. editPanelWidth = HomeSizes.editPanelWidth;
  38. homePageROffset = showEditPanel ? editPanelWidth : 0;
  39. }
  40. }