|
@@ -8,88 +8,103 @@ import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
import 'cell_builder.dart';
|
|
|
import 'cell_container.dart';
|
|
|
-import 'grid_cell.dart';
|
|
|
-import 'package:dartz/dartz.dart';
|
|
|
|
|
|
-class GridRowWidget extends StatelessWidget {
|
|
|
+class GridRowWidget extends StatefulWidget {
|
|
|
final GridRowData data;
|
|
|
- final Function(bool)? onHoverChange;
|
|
|
- const GridRowWidget(this.data, {Key? key, this.onHoverChange}) : super(key: key);
|
|
|
+ GridRowWidget({required this.data, Key? key}) : super(key: ObjectKey(data.row.id));
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<GridRowWidget> createState() => _GridRowWidgetState();
|
|
|
+}
|
|
|
+
|
|
|
+class _GridRowWidgetState extends State<GridRowWidget> {
|
|
|
+ late RowBloc _rowBloc;
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ _rowBloc = getIt<RowBloc>(param1: widget.data);
|
|
|
+ super.initState();
|
|
|
+ }
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
- return BlocProvider(
|
|
|
- create: (context) => getIt<RowBloc>(param1: data),
|
|
|
- child: BlocBuilder<RowBloc, RowState>(
|
|
|
- builder: (context, state) {
|
|
|
- return GestureDetector(
|
|
|
- behavior: HitTestBehavior.translucent,
|
|
|
- child: MouseRegion(
|
|
|
- cursor: SystemMouseCursors.click,
|
|
|
- onEnter: (p) => context.read<RowBloc>().add(RowEvent.highlightRow(some(data.row.id))),
|
|
|
- onExit: (p) => context.read<RowBloc>().add(RowEvent.highlightRow(none())),
|
|
|
- child: SizedBox(
|
|
|
- height: data.row.height.toDouble(),
|
|
|
- child: Row(
|
|
|
- crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
- children: _buildCells(),
|
|
|
- ),
|
|
|
- ),
|
|
|
+ return BlocProvider.value(
|
|
|
+ value: _rowBloc,
|
|
|
+ child: GestureDetector(
|
|
|
+ behavior: HitTestBehavior.translucent,
|
|
|
+ child: MouseRegion(
|
|
|
+ cursor: SystemMouseCursors.click,
|
|
|
+ onEnter: (p) => _rowBloc.add(const RowEvent.activeRow()),
|
|
|
+ onExit: (p) => _rowBloc.add(const RowEvent.disactiveRow()),
|
|
|
+ child: SizedBox(
|
|
|
+ height: _rowBloc.state.data.row.height.toDouble(),
|
|
|
+ child: Row(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
+ children: [
|
|
|
+ const LeadingRow(),
|
|
|
+ _buildCells(),
|
|
|
+ const TrailingRow(),
|
|
|
+ ],
|
|
|
),
|
|
|
- );
|
|
|
- },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- List<Widget> _buildCells() {
|
|
|
- return [
|
|
|
- SizedBox(
|
|
|
- width: GridSize.leadingHeaderPadding,
|
|
|
- child: LeadingRow(rowId: data.row.id),
|
|
|
- ),
|
|
|
- ...data.fields.map(
|
|
|
- (field) {
|
|
|
- final cellData = data.cellMap[field.id];
|
|
|
- return CellContainer(
|
|
|
- width: field.width.toDouble(),
|
|
|
- child: GridCellBuilder.buildCell(field, cellData),
|
|
|
- );
|
|
|
- },
|
|
|
- ),
|
|
|
- SizedBox(
|
|
|
- width: GridSize.trailHeaderPadding,
|
|
|
- child: TrailingRow(rowId: data.row.id),
|
|
|
- )
|
|
|
- ].toList();
|
|
|
+ @override
|
|
|
+ Future<void> dispose() async {
|
|
|
+ _rowBloc.close();
|
|
|
+ super.dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget _buildCells() {
|
|
|
+ return BlocBuilder<RowBloc, RowState>(
|
|
|
+ buildWhen: (p, c) => p.data != c.data,
|
|
|
+ builder: (context, state) {
|
|
|
+ return Row(
|
|
|
+ key: ValueKey(state.data.row.id),
|
|
|
+ children: state.data.fields.map(
|
|
|
+ (field) {
|
|
|
+ final cellData = state.data.cellMap[field.id];
|
|
|
+ return CellContainer(
|
|
|
+ width: field.width.toDouble(),
|
|
|
+ child: GridCellBuilder.buildCell(field, cellData),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ ).toList(),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class LeadingRow extends StatelessWidget {
|
|
|
- final String rowId;
|
|
|
- const LeadingRow({required this.rowId, Key? key}) : super(key: key);
|
|
|
+ const LeadingRow({Key? key}) : super(key: key);
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
- return BlocBuilder<RowBloc, RowState>(
|
|
|
- builder: (context, state) {
|
|
|
- if (state.isHighlight) {
|
|
|
- return Row(
|
|
|
- mainAxisAlignment: MainAxisAlignment.center,
|
|
|
- children: const [
|
|
|
- CreateRowButton(),
|
|
|
- ],
|
|
|
- );
|
|
|
- }
|
|
|
- return const SizedBox.expand();
|
|
|
+ return BlocSelector<RowBloc, RowState, bool>(
|
|
|
+ selector: (state) => state.active,
|
|
|
+ builder: (context, isActive) {
|
|
|
+ return SizedBox(
|
|
|
+ width: GridSize.leadingHeaderPadding,
|
|
|
+ child: isActive
|
|
|
+ ? Row(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ children: const [
|
|
|
+ CreateRowButton(),
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ : null,
|
|
|
+ );
|
|
|
},
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class TrailingRow extends StatelessWidget {
|
|
|
- final String rowId;
|
|
|
- const TrailingRow({required this.rowId, Key? key}) : super(key: key);
|
|
|
+ const TrailingRow({Key? key}) : super(key: key);
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|