home_menu.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import 'package:app_flowy/home/application/menu/menu_bloc.dart';
  2. import 'package:app_flowy/home/domain/page_context.dart';
  3. import 'package:app_flowy/startup/startup.dart';
  4. import 'package:dartz/dartz.dart';
  5. import 'package:flowy_infra/size.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_bloc/flutter_bloc.dart';
  8. import '../../home_sizes.dart';
  9. import 'package:styled_widget/styled_widget.dart';
  10. class HomeMenu extends StatelessWidget {
  11. final Function(Option<PageContext>) pageContextChanged;
  12. final Function(bool) isCollapseChanged;
  13. const HomeMenu(
  14. {Key? key,
  15. required this.pageContextChanged,
  16. required this.isCollapseChanged})
  17. : super(key: key);
  18. @override
  19. Widget build(BuildContext context) {
  20. return MultiBlocProvider(
  21. providers: [
  22. BlocProvider<MenuBloc>(create: (context) => getIt<MenuBloc>()),
  23. ],
  24. child: MultiBlocListener(
  25. listeners: bind(),
  26. child: Container(
  27. color: Theme.of(context).colorScheme.primaryVariant,
  28. child: Padding(
  29. padding: EdgeInsets.symmetric(horizontal: Insets.sm),
  30. child: Column(
  31. mainAxisAlignment: MainAxisAlignment.start,
  32. children: [
  33. const MenuTopBar(),
  34. Container(),
  35. const NewAppButton(),
  36. ],
  37. ),
  38. ),
  39. ),
  40. ));
  41. }
  42. // bind the function passed by ooutter with the bloc listener
  43. List<BlocListener<MenuBloc, MenuState>> bind() {
  44. return [
  45. BlocListener<MenuBloc, MenuState>(
  46. listenWhen: (p, c) => p.pageContext != c.pageContext,
  47. listener: (context, state) => pageContextChanged(state.pageContext),
  48. ),
  49. BlocListener<MenuBloc, MenuState>(
  50. listenWhen: (p, c) => p.isCollapse != c.isCollapse,
  51. listener: (context, state) => isCollapseChanged(state.isCollapse),
  52. )
  53. ];
  54. }
  55. }
  56. class MenuTopBar extends StatelessWidget {
  57. const MenuTopBar({Key? key}) : super(key: key);
  58. @override
  59. Widget build(BuildContext context) {
  60. return BlocBuilder<MenuBloc, MenuState>(
  61. builder: (context, state) {
  62. return SizedBox(
  63. height: HomeSizes.menuTopBarHeight,
  64. child: Row(
  65. children: [
  66. const Text(
  67. 'AppFlowy',
  68. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
  69. ).constrained(minWidth: 100),
  70. const Spacer(),
  71. IconButton(
  72. icon: const Icon(Icons.arrow_left),
  73. onPressed: () =>
  74. context.read<MenuBloc>().add(const MenuEvent.collapse()),
  75. ),
  76. ],
  77. ),
  78. );
  79. },
  80. );
  81. }
  82. }
  83. class NewAppButton extends StatelessWidget {
  84. const NewAppButton({Key? key}) : super(key: key);
  85. @override
  86. Widget build(BuildContext context) {
  87. return SizedBox(
  88. height: HomeSizes.menuAddButtonHeight,
  89. child: Row(
  90. mainAxisAlignment: MainAxisAlignment.start,
  91. children: [
  92. const Icon(Icons.add),
  93. const SizedBox(
  94. width: 10,
  95. ),
  96. TextButton(
  97. onPressed: () async {
  98. // Dialogs.show(OkCancelDialog(
  99. // title: "No Connection",
  100. // message:
  101. // "It appears your device is offline. Please check your connection and try again.",
  102. // onOkPressed: () => AppGlobals.nav.pop(),
  103. // ));
  104. },
  105. child: const Text('New App',
  106. style: TextStyle(
  107. color: Colors.black,
  108. fontWeight: FontWeight.bold,
  109. fontSize: 20)),
  110. )
  111. ],
  112. ),
  113. );
  114. }
  115. }