app_header.dart 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import 'package:app_flowy/workspace/application/app/app_bloc.dart';
  2. import 'package:expandable/expandable.dart';
  3. import 'package:flowy_infra_ui/flowy_infra_ui.dart';
  4. import 'package:flowy_infra_ui/style_widget/icon_button.dart';
  5. import 'package:flowy_infra_ui/widget/spacing.dart';
  6. import 'package:flowy_infra_ui/style_widget/text_button.dart';
  7. import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart';
  8. import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter_bloc/flutter_bloc.dart';
  11. import 'app_page.dart';
  12. class AppHeader extends StatelessWidget {
  13. final App app;
  14. const AppHeader(
  15. this.app, {
  16. Key? key,
  17. }) : super(key: key);
  18. @override
  19. Widget build(BuildContext context) {
  20. return Row(
  21. mainAxisAlignment: MainAxisAlignment.center,
  22. crossAxisAlignment: CrossAxisAlignment.center,
  23. children: [
  24. InkWell(
  25. onTap: () {
  26. ExpandableController.of(context,
  27. rebuildOnChange: false, required: true)
  28. ?.toggle();
  29. },
  30. child: ExpandableIcon(
  31. theme: ExpandableThemeData(
  32. expandIcon: Icons.arrow_drop_up,
  33. collapseIcon: Icons.arrow_drop_down,
  34. iconColor: Colors.black,
  35. iconSize: AppPageSize.expandedIconSize,
  36. iconPadding: EdgeInsets.zero,
  37. hasIcon: false,
  38. ),
  39. ),
  40. ),
  41. HSpace(AppPageSize.expandedIconRightSpace),
  42. Expanded(
  43. child: FlowyTextButton(
  44. app.name,
  45. onPressed: () {
  46. debugPrint('show app');
  47. },
  48. ),
  49. ),
  50. // FlowyIconButton(
  51. // icon: const Icon(Icons.add),
  52. // onPressed: () {
  53. // debugPrint('add view');
  54. // FlowyOverlay.of(context)
  55. // .insert(widget: Text('test'), identifier: 'identifier');
  56. // },
  57. // ),
  58. PopupMenuButton(
  59. iconSize: 20,
  60. tooltip: 'create new view',
  61. icon: const Icon(Icons.add),
  62. padding: EdgeInsets.zero,
  63. onSelected: (viewType) =>
  64. _createView(viewType as ViewType, context),
  65. itemBuilder: (context) => menuItemBuilder())
  66. ],
  67. );
  68. }
  69. List<PopupMenuEntry> menuItemBuilder() {
  70. return ViewType.values
  71. .where((element) => element != ViewType.Blank)
  72. .map((ty) {
  73. return PopupMenuItem<ViewType>(
  74. value: ty,
  75. child: Row(
  76. children: <Widget>[Text(ty.name)],
  77. ));
  78. }).toList();
  79. }
  80. void _createView(ViewType viewType, BuildContext context) {
  81. context.read<AppBloc>().add(AppEvent.createView("New view", "", viewType));
  82. }
  83. }