2022-08-12 20:10:56 +08:00
|
|
|
import 'package:app_flowy/plugins/board/application/card/card_bloc.dart';
|
|
|
|
import 'package:app_flowy/plugins/board/application/card/card_data_controller.dart';
|
|
|
|
import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_service.dart';
|
2022-08-16 17:36:39 +08:00
|
|
|
import 'package:app_flowy/plugins/grid/presentation/widgets/row/row_action_sheet.dart';
|
2022-08-13 11:51:26 +08:00
|
|
|
import 'package:flowy_infra/image.dart';
|
|
|
|
import 'package:flowy_infra/theme.dart';
|
2022-08-16 17:36:39 +08:00
|
|
|
import 'package:flowy_infra_ui/flowy_infra_ui_web.dart';
|
2022-08-10 17:59:28 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-12 20:10:56 +08:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'card_cell_builder.dart';
|
2022-08-13 11:51:26 +08:00
|
|
|
import 'card_container.dart';
|
2022-08-10 17:59:28 +08:00
|
|
|
|
2022-08-13 16:23:44 +08:00
|
|
|
typedef OnEndEditing = void Function(String rowId);
|
|
|
|
|
2022-08-12 20:10:56 +08:00
|
|
|
class BoardCard extends StatefulWidget {
|
|
|
|
final String gridId;
|
2022-08-25 16:17:19 +08:00
|
|
|
final String groupId;
|
2022-08-13 16:23:44 +08:00
|
|
|
final bool isEditing;
|
2022-08-12 20:10:56 +08:00
|
|
|
final CardDataController dataController;
|
|
|
|
final BoardCellBuilder cellBuilder;
|
2022-08-13 16:23:44 +08:00
|
|
|
final OnEndEditing onEditEditing;
|
2022-08-16 18:02:39 +08:00
|
|
|
final void Function(BuildContext) openCard;
|
2022-08-12 20:10:56 +08:00
|
|
|
|
|
|
|
const BoardCard({
|
|
|
|
required this.gridId,
|
2022-08-25 16:17:19 +08:00
|
|
|
required this.groupId,
|
2022-08-13 16:23:44 +08:00
|
|
|
required this.isEditing,
|
2022-08-12 20:10:56 +08:00
|
|
|
required this.dataController,
|
|
|
|
required this.cellBuilder,
|
2022-08-13 16:23:44 +08:00
|
|
|
required this.onEditEditing,
|
2022-08-16 18:02:39 +08:00
|
|
|
required this.openCard,
|
2022-08-12 20:10:56 +08:00
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<BoardCard> createState() => _BoardCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _BoardCardState extends State<BoardCard> {
|
|
|
|
late BoardCardBloc _cardBloc;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_cardBloc = BoardCardBloc(
|
|
|
|
gridId: widget.gridId,
|
|
|
|
dataController: widget.dataController,
|
2022-08-24 21:06:10 +08:00
|
|
|
)..add(const BoardCardEvent.initial());
|
2022-08-12 20:10:56 +08:00
|
|
|
super.initState();
|
|
|
|
}
|
2022-08-10 17:59:28 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-12 20:10:56 +08:00
|
|
|
return BlocProvider.value(
|
|
|
|
value: _cardBloc,
|
|
|
|
child: BlocBuilder<BoardCardBloc, BoardCardState>(
|
|
|
|
builder: (context, state) {
|
2022-08-13 11:51:26 +08:00
|
|
|
return BoardCardContainer(
|
|
|
|
accessoryBuilder: (context) {
|
|
|
|
return [const _CardMoreOption()];
|
|
|
|
},
|
2022-08-16 18:02:39 +08:00
|
|
|
onTap: (context) {
|
|
|
|
widget.openCard(context);
|
|
|
|
},
|
2022-08-13 10:01:40 +08:00
|
|
|
child: Column(
|
|
|
|
children: _makeCells(context, state.gridCellMap),
|
|
|
|
),
|
2022-08-12 20:10:56 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Widget> _makeCells(BuildContext context, GridCellMap cellMap) {
|
|
|
|
return cellMap.values.map(
|
|
|
|
(cellId) {
|
2022-08-25 16:17:19 +08:00
|
|
|
final child = widget.cellBuilder.buildCell(widget.groupId, cellId);
|
2022-08-13 10:01:40 +08:00
|
|
|
return Padding(
|
2022-08-26 08:47:41 +08:00
|
|
|
padding: const EdgeInsets.only(left: 4, right: 4, top: 6),
|
2022-08-13 10:01:40 +08:00
|
|
|
child: child,
|
|
|
|
);
|
2022-08-12 20:10:56 +08:00
|
|
|
},
|
|
|
|
).toList();
|
2022-08-10 17:59:28 +08:00
|
|
|
}
|
2022-08-24 21:06:10 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> dispose() async {
|
|
|
|
_cardBloc.close();
|
|
|
|
super.dispose();
|
|
|
|
}
|
2022-08-10 17:59:28 +08:00
|
|
|
}
|
2022-08-13 11:51:26 +08:00
|
|
|
|
|
|
|
class _CardMoreOption extends StatelessWidget with CardAccessory {
|
|
|
|
const _CardMoreOption({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-25 09:46:26 +08:00
|
|
|
return svgWidget('grid/details', color: context.read<AppTheme>().iconColor);
|
2022-08-13 11:51:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void onTap(BuildContext context) {
|
2022-08-16 17:36:39 +08:00
|
|
|
GridRowActionSheet(
|
|
|
|
rowData: context.read<BoardCardBloc>().rowInfo(),
|
|
|
|
).show(context, direction: AnchorDirection.bottomWithCenterAligned);
|
2022-08-13 11:51:26 +08:00
|
|
|
}
|
|
|
|
}
|