2021-07-28 15:13:48 +08:00
|
|
|
import 'package:flowy_infra_ui/style_widget/hover.dart';
|
|
|
|
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
2021-07-26 15:25:30 +08:00
|
|
|
import 'package:flowy_infra_ui/widget/spacing.dart';
|
2021-07-22 17:06:53 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2021-07-28 13:41:39 +08:00
|
|
|
import 'package:app_flowy/workspace/domain/image.dart';
|
|
|
|
import 'package:app_flowy/workspace/presentation/app/app_widget.dart';
|
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
2021-07-22 17:06:53 +08:00
|
|
|
|
2021-07-28 13:41:39 +08:00
|
|
|
class ViewWidgetContext {
|
2021-07-22 17:06:53 +08:00
|
|
|
final View view;
|
2021-07-28 13:41:39 +08:00
|
|
|
bool isSelected;
|
|
|
|
|
|
|
|
ViewWidgetContext(
|
|
|
|
this.view, {
|
|
|
|
this.isSelected = false,
|
|
|
|
});
|
2021-07-28 15:13:48 +08:00
|
|
|
|
|
|
|
Key valueKey() => ValueKey("${view.id}${view.version}");
|
2021-07-28 13:41:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef OpenViewCallback = void Function(View);
|
|
|
|
|
|
|
|
class ViewWidget extends StatelessWidget {
|
|
|
|
final ViewWidgetContext viewCtx;
|
|
|
|
final OpenViewCallback onOpen;
|
2021-07-28 15:13:48 +08:00
|
|
|
ViewWidget({Key? key, required this.viewCtx, required this.onOpen})
|
|
|
|
: super(key: viewCtx.valueKey());
|
2021-07-22 17:06:53 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-07-28 13:41:39 +08:00
|
|
|
final config = HoverDisplayConfig(hoverColor: Colors.grey.shade200);
|
2021-07-27 09:11:53 +08:00
|
|
|
return InkWell(
|
|
|
|
onTap: _openView(context),
|
2021-07-28 15:13:48 +08:00
|
|
|
child: FlowyHover(
|
2021-07-28 13:41:39 +08:00
|
|
|
config: config,
|
|
|
|
builder: (context, onHover) => _render(context, onHover, config),
|
2021-07-27 09:11:53 +08:00
|
|
|
),
|
|
|
|
);
|
2021-07-22 17:06:53 +08:00
|
|
|
}
|
|
|
|
|
2021-07-28 13:41:39 +08:00
|
|
|
Widget _render(
|
|
|
|
BuildContext context, bool onHover, HoverDisplayConfig config) {
|
|
|
|
const double width = 22;
|
2021-07-27 11:54:59 +08:00
|
|
|
List<Widget> children = [
|
|
|
|
Image(
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
width: width,
|
|
|
|
height: width,
|
2021-07-28 13:41:39 +08:00
|
|
|
image: assetImageForViewType(viewCtx.view.viewType)),
|
2021-07-27 11:54:59 +08:00
|
|
|
const HSpace(6),
|
|
|
|
Text(
|
2021-07-28 13:41:39 +08:00
|
|
|
viewCtx.view.name,
|
2021-07-27 11:54:59 +08:00
|
|
|
textAlign: TextAlign.start,
|
|
|
|
style: const TextStyle(fontSize: 15),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
if (onHover) {
|
2021-07-28 13:41:39 +08:00
|
|
|
_addedHover(children, width);
|
2021-07-27 11:54:59 +08:00
|
|
|
}
|
|
|
|
|
2021-07-28 13:41:39 +08:00
|
|
|
Widget widget = Row(children: children).padding(
|
|
|
|
vertical: 5,
|
2021-07-27 11:54:59 +08:00
|
|
|
left: AppWidgetSize.expandedPadding,
|
|
|
|
right: 5,
|
|
|
|
);
|
|
|
|
|
2021-07-28 13:41:39 +08:00
|
|
|
if (viewCtx.isSelected) {
|
2021-07-28 15:13:48 +08:00
|
|
|
widget = FlowyHoverBackground(child: widget, config: config);
|
2021-07-28 13:41:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return widget;
|
2021-07-22 17:06:53 +08:00
|
|
|
}
|
|
|
|
|
2021-07-22 18:04:24 +08:00
|
|
|
Function() _openView(BuildContext context) {
|
2021-07-28 13:41:39 +08:00
|
|
|
return () => onOpen(viewCtx.view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _addedHover(List<Widget> children, double hoverWidth) {
|
|
|
|
children.add(const Spacer());
|
|
|
|
children.add(Align(
|
|
|
|
alignment: Alignment.center,
|
2021-07-28 15:13:48 +08:00
|
|
|
child: FlowyMoreButton(
|
2021-07-28 13:41:39 +08:00
|
|
|
width: hoverWidth,
|
|
|
|
onPressed: () {
|
|
|
|
debugPrint('show view setting');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
));
|
2021-07-22 17:06:53 +08:00
|
|
|
}
|
|
|
|
}
|