|
@@ -1,16 +1,19 @@
|
|
|
-import 'package:app_flowy/workspace/application/app/app_bloc.dart';
|
|
|
import 'package:expandable/expandable.dart';
|
|
|
+import 'package:flowy_infra/flowy_icon_data_icons.dart';
|
|
|
+import 'package:flowy_infra/image.dart';
|
|
|
import 'package:flowy_infra/theme.dart';
|
|
|
+import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
|
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
|
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
|
|
import 'package:flowy_infra_ui/widget/spacing.dart';
|
|
|
-import 'package:flowy_infra/flowy_icon_data_icons.dart';
|
|
|
import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart';
|
|
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
|
|
|
|
+import 'package:app_flowy/workspace/application/app/app_bloc.dart';
|
|
|
+
|
|
|
import 'menu_app.dart';
|
|
|
|
|
|
class MenuAppHeader extends StatelessWidget {
|
|
@@ -55,37 +58,88 @@ class MenuAppHeader extends StatelessWidget {
|
|
|
fontSize: 12,
|
|
|
),
|
|
|
)),
|
|
|
-
|
|
|
- ViewAddButton(
|
|
|
- onPressed: () {
|
|
|
- debugPrint('add view');
|
|
|
- // FlowyOverlay.of(context)
|
|
|
- // .insert(widget: Text('test'), identifier: 'identifier');
|
|
|
+ DisclosureButton(
|
|
|
+ onSelected: (viewType) {
|
|
|
+ context.read<AppBloc>().add(AppEvent.createView("New view", "", viewType));
|
|
|
},
|
|
|
).padding(right: MenuAppSizes.expandedIconPadding),
|
|
|
- // PopupMenuButton(
|
|
|
- // iconSize: 16,
|
|
|
- // tooltip: 'create new view',
|
|
|
- // icon: svg("home/add"),
|
|
|
- // padding: EdgeInsets.zero,
|
|
|
- // onSelected: (viewType) => _createView(viewType as ViewType, context),
|
|
|
- // itemBuilder: (context) => menuItemBuilder())
|
|
|
],
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- List<PopupMenuEntry> menuItemBuilder() {
|
|
|
- return ViewType.values.where((element) => element != ViewType.Blank).map((ty) {
|
|
|
- return PopupMenuItem<ViewType>(
|
|
|
- value: ty,
|
|
|
- child: Row(
|
|
|
- children: <Widget>[Text(ty.name)],
|
|
|
- ));
|
|
|
+class DisclosureButton extends StatelessWidget {
|
|
|
+ final Function(ViewType) onSelected;
|
|
|
+ const DisclosureButton({
|
|
|
+ Key? key,
|
|
|
+ required this.onSelected,
|
|
|
+ }) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return FlowyIconButton(
|
|
|
+ width: 16,
|
|
|
+ onPressed: () {
|
|
|
+ DisclosureButtonActionList(
|
|
|
+ anchorContext: context,
|
|
|
+ onSelected: onSelected,
|
|
|
+ ).show(context);
|
|
|
+ },
|
|
|
+ icon: svg("home/add"),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class DisclosureButtonActionList {
|
|
|
+ final Function(ViewType) onSelected;
|
|
|
+ final BuildContext anchorContext;
|
|
|
+ final String _identifier = 'DisclosureButtonActionList';
|
|
|
+
|
|
|
+ const DisclosureButtonActionList({required this.anchorContext, required this.onSelected});
|
|
|
+
|
|
|
+ void show(BuildContext buildContext) {
|
|
|
+ final items = ViewType.values.where((element) => element != ViewType.Blank).map((ty) {
|
|
|
+ return CreateItem(
|
|
|
+ viewType: ty,
|
|
|
+ onSelected: (viewType) {
|
|
|
+ FlowyOverlay.of(buildContext).remove(_identifier);
|
|
|
+ onSelected(viewType);
|
|
|
+ });
|
|
|
}).toList();
|
|
|
+
|
|
|
+ ListOverlay.showWithAnchor(
|
|
|
+ buildContext,
|
|
|
+ identifier: _identifier,
|
|
|
+ itemCount: items.length,
|
|
|
+ itemBuilder: (context, index) => items[index],
|
|
|
+ anchorContext: anchorContext,
|
|
|
+ anchorDirection: AnchorDirection.bottomRight,
|
|
|
+ maxWidth: 120,
|
|
|
+ maxHeight: 80,
|
|
|
+ );
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- void _createView(ViewType viewType, BuildContext context) {
|
|
|
- context.read<AppBloc>().add(AppEvent.createView("New view", "", viewType));
|
|
|
+class CreateItem extends StatelessWidget {
|
|
|
+ final ViewType viewType;
|
|
|
+ final Function(ViewType) onSelected;
|
|
|
+ const CreateItem({
|
|
|
+ Key? key,
|
|
|
+ required this.viewType,
|
|
|
+ required this.onSelected,
|
|
|
+ }) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return GestureDetector(
|
|
|
+ onTap: () {
|
|
|
+ onSelected(viewType);
|
|
|
+ },
|
|
|
+ child: FlowyText.medium(
|
|
|
+ viewType.name,
|
|
|
+ fontSize: 12,
|
|
|
+ ).padding(horizontal: 10, vertical: 10),
|
|
|
+ );
|
|
|
}
|
|
|
}
|