2021-07-22 17:06:53 +08:00
|
|
|
import 'package:app_flowy/workspace/application/app/app_bloc.dart';
|
|
|
|
import 'package:app_flowy/workspace/application/app/app_watch_bloc.dart';
|
|
|
|
import 'package:app_flowy/workspace/presentation/app/view_list.dart';
|
2021-07-26 08:34:40 +08:00
|
|
|
import 'package:app_flowy/workspace/presentation/widgets/menu/menu_list.dart';
|
2021-07-22 11:23:15 +08:00
|
|
|
import 'package:app_flowy/startup/startup.dart';
|
2021-07-21 22:41:44 +08:00
|
|
|
import 'package:expandable/expandable.dart';
|
2021-07-22 11:23:15 +08:00
|
|
|
import 'package:flowy_infra_ui/widget/error_page.dart';
|
2021-07-26 15:25:30 +08:00
|
|
|
import 'package:flowy_infra_ui/widget/spacing.dart';
|
2021-07-27 14:38:51 +08:00
|
|
|
import 'package:flowy_infra_ui/style_widget/styled_text_button.dart';
|
|
|
|
import 'package:flowy_infra_ui/style_widget/styled_icon_button.dart';
|
2021-07-21 22:41:44 +08:00
|
|
|
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';
|
2021-07-22 17:06:53 +08:00
|
|
|
import 'package:dartz/dartz.dart';
|
2021-07-21 22:41:44 +08:00
|
|
|
|
2021-07-26 15:25:30 +08:00
|
|
|
class AppWidgetSize {
|
|
|
|
static double expandedIconSize = 24;
|
|
|
|
static double expandedIconRightSpace = 8;
|
|
|
|
|
|
|
|
static double scale = 1;
|
|
|
|
|
|
|
|
static double get expandedPadding =>
|
|
|
|
expandedIconSize * scale + expandedIconRightSpace;
|
|
|
|
}
|
|
|
|
|
2021-07-26 08:34:40 +08:00
|
|
|
class AppWidget extends MenuItem {
|
2021-07-21 22:41:44 +08:00
|
|
|
final App app;
|
2021-07-26 11:51:39 +08:00
|
|
|
AppWidget(this.app, {Key? key}) : super(key: ValueKey(app.id));
|
2021-07-21 22:41:44 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-07-22 12:23:14 +08:00
|
|
|
return MultiBlocProvider(
|
|
|
|
providers: [
|
2021-07-22 17:06:53 +08:00
|
|
|
BlocProvider<AppBloc>(create: (context) {
|
|
|
|
final appBloc = getIt<AppBloc>(param1: app.id);
|
|
|
|
appBloc.add(const AppEvent.initial());
|
|
|
|
return appBloc;
|
|
|
|
}),
|
|
|
|
BlocProvider<AppWatchBloc>(create: (context) {
|
|
|
|
final watchBloc = getIt<AppWatchBloc>(param1: app.id);
|
|
|
|
watchBloc.add(const AppWatchEvent.started());
|
|
|
|
return watchBloc;
|
|
|
|
}),
|
2021-07-22 12:23:14 +08:00
|
|
|
],
|
|
|
|
child: BlocBuilder<AppWatchBloc, AppWatchState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
final child = state.map(
|
|
|
|
initial: (_) => BlocBuilder<AppBloc, AppState>(
|
2021-07-27 14:38:51 +08:00
|
|
|
builder: (context, state) => _renderViewList(state.views),
|
2021-07-22 12:23:14 +08:00
|
|
|
),
|
2021-07-27 14:38:51 +08:00
|
|
|
loadViews: (s) => _renderViewList(some(s.views)),
|
2021-07-22 17:06:53 +08:00
|
|
|
loadFail: (s) => FlowyErrorPage(s.error.toString()),
|
2021-07-22 12:23:14 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
return expandableWrapper(context, child);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2021-07-21 22:41:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ExpandableNotifier expandableWrapper(BuildContext context, Widget child) {
|
|
|
|
return ExpandableNotifier(
|
|
|
|
child: ScrollOnExpand(
|
|
|
|
scrollOnExpand: true,
|
|
|
|
scrollOnCollapse: false,
|
2021-07-26 15:25:30 +08:00
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
ExpandablePanel(
|
|
|
|
theme: const ExpandableThemeData(
|
|
|
|
headerAlignment: ExpandablePanelHeaderAlignment.center,
|
|
|
|
tapBodyToExpand: false,
|
|
|
|
tapBodyToCollapse: false,
|
2021-07-27 14:38:51 +08:00
|
|
|
tapHeaderToExpand: false,
|
2021-07-26 15:25:30 +08:00
|
|
|
iconPadding: EdgeInsets.zero,
|
|
|
|
hasIcon: false,
|
2021-07-21 22:41:44 +08:00
|
|
|
),
|
2021-07-27 23:10:39 +08:00
|
|
|
header: AppHeader(app),
|
2021-07-27 09:11:53 +08:00
|
|
|
expanded: child,
|
2021-07-26 15:25:30 +08:00
|
|
|
collapsed: const SizedBox(),
|
|
|
|
),
|
|
|
|
],
|
2021-07-21 22:41:44 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-07-26 08:34:40 +08:00
|
|
|
|
2021-07-27 14:38:51 +08:00
|
|
|
Widget _renderViewList(Option<List<View>> views) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
child: ViewList(views),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-26 08:34:40 +08:00
|
|
|
@override
|
|
|
|
MenuItemType get type => MenuItemType.app;
|
2021-07-21 22:41:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class AppHeader extends StatelessWidget {
|
|
|
|
final App app;
|
|
|
|
const AppHeader(
|
|
|
|
this.app, {
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-07-26 15:25:30 +08:00
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2021-07-27 14:38:51 +08:00
|
|
|
InkWell(
|
2021-07-27 23:10:39 +08:00
|
|
|
onTap: () {
|
|
|
|
ExpandableController.of(context,
|
|
|
|
rebuildOnChange: false, required: true)
|
|
|
|
?.toggle();
|
|
|
|
},
|
2021-07-27 14:38:51 +08:00
|
|
|
child: ExpandableIcon(
|
|
|
|
theme: ExpandableThemeData(
|
|
|
|
expandIcon: Icons.arrow_drop_up,
|
|
|
|
collapseIcon: Icons.arrow_drop_down,
|
|
|
|
iconColor: Colors.black,
|
|
|
|
iconSize: AppWidgetSize.expandedIconSize,
|
|
|
|
iconPadding: EdgeInsets.zero,
|
|
|
|
hasIcon: false,
|
|
|
|
),
|
2021-07-26 15:25:30 +08:00
|
|
|
),
|
2021-07-21 22:41:44 +08:00
|
|
|
),
|
2021-07-26 15:25:30 +08:00
|
|
|
HSpace(AppWidgetSize.expandedIconRightSpace),
|
|
|
|
Expanded(
|
2021-07-27 14:38:51 +08:00
|
|
|
child: StyledTextButton(
|
2021-07-26 15:25:30 +08:00
|
|
|
app.name,
|
2021-07-27 14:38:51 +08:00
|
|
|
onPressed: () {
|
|
|
|
debugPrint('show app document');
|
|
|
|
},
|
2021-07-26 15:25:30 +08:00
|
|
|
),
|
|
|
|
),
|
2021-07-27 14:38:51 +08:00
|
|
|
StyledIconButton(
|
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
onPressed: () {
|
|
|
|
debugPrint('add view');
|
|
|
|
},
|
|
|
|
),
|
2021-07-26 15:25:30 +08:00
|
|
|
],
|
2021-07-21 22:41:44 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:38:51 +08:00
|
|
|
// return PopupMenuButton(
|
|
|
|
// iconSize: 20,
|
|
|
|
// tooltip: 'create new view',
|
|
|
|
// icon: const Icon(Icons.add),
|
|
|
|
// padding: EdgeInsets.zero,
|
|
|
|
// onSelected: (viewType) => _createView(viewType as ViewType, context),
|
|
|
|
// itemBuilder: (context) => menuItemBuilder());
|
2021-07-21 22:41:44 +08:00
|
|
|
|
|
|
|
List<PopupMenuEntry> menuItemBuilder() {
|
|
|
|
return ViewType.values
|
2021-07-22 17:39:44 +08:00
|
|
|
.where((element) => element != ViewType.Blank)
|
2021-07-21 22:41:44 +08:00
|
|
|
.map((ty) {
|
|
|
|
return PopupMenuItem<ViewType>(
|
|
|
|
value: ty,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[Text(ty.name)],
|
|
|
|
));
|
|
|
|
}).toList();
|
|
|
|
}
|
|
|
|
|
2021-07-22 17:06:53 +08:00
|
|
|
void _createView(ViewType viewType, BuildContext context) {
|
|
|
|
context.read<AppBloc>().add(AppEvent.createView("New view", "", viewType));
|
2021-07-21 22:41:44 +08:00
|
|
|
}
|
|
|
|
}
|