Skip to content

Commit

Permalink
fix: flutter analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
zoli committed Apr 12, 2023
1 parent eff5444 commit 97e61b4
Show file tree
Hide file tree
Showing 19 changed files with 468 additions and 263 deletions.
21 changes: 15 additions & 6 deletions lib/src/render/color_menu/color_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ class _ColorPickerState extends State<ColorPicker> {
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: _buildColorOptionLists(widget.colorOptionLists)),
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: _buildColorOptionLists(widget.colorOptionLists),
),
),
),
);
Expand Down Expand Up @@ -106,14 +107,22 @@ class _ColorPickerState extends State<ColorPicker> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: colorOptionList.colorOptions
.map((e) => _buildColorItem(colorOptionList.onSubmittedAction, e,
e.colorHex == colorOptionList.selectedColorHex))
.map(
(e) => _buildColorItem(
colorOptionList.onSubmittedAction,
e,
e.colorHex == colorOptionList.selectedColorHex,
),
)
.toList(),
);
}

Widget _buildColorItem(
void Function(String color) onTap, ColorOption option, bool isChecked) {
void Function(String color) onTap,
ColorOption option,
bool isChecked,
) {
return SizedBox(
height: 36,
child: InkWell(
Expand Down
71 changes: 47 additions & 24 deletions lib/src/render/table/table_action.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/render/table/util.dart';

addCol(Node tableNode, Transaction transaction) {
void addCol(Node tableNode, Transaction transaction) {
List<Node> cellNodes = [];
final int rowsLen = tableNode.attributes['rowsLen'],
colsLen = tableNode.attributes['colsLen'];
Expand All @@ -25,7 +25,7 @@ addCol(Node tableNode, Transaction transaction) {
transaction.updateNode(tableNode, {'colsLen': colsLen + 1});
}

addRow(Node tableNode, Transaction transaction) {
void addRow(Node tableNode, Transaction transaction) {
final int rowsLen = tableNode.attributes['rowsLen'],
colsLen = tableNode.attributes['colsLen'];
for (var i = 0; i < colsLen; i++) {
Expand All @@ -37,13 +37,15 @@ addRow(Node tableNode, Transaction transaction) {
);
node.insert(TextNode.empty());

transaction.insertNode(getCellNode(tableNode, i, rowsLen - 1)!.path.next,
newCellNode(tableNode, node));
transaction.insertNode(
getCellNode(tableNode, i, rowsLen - 1)!.path.next,
newCellNode(tableNode, node),
);
}
transaction.updateNode(tableNode, {'rowsLen': rowsLen + 1});
}

removeCol(Node tableNode, int col, Transaction transaction) {
void removeCol(Node tableNode, int col, Transaction transaction) {
final int rowsLen = tableNode.attributes['rowsLen'],
colsLen = tableNode.attributes['colsLen'];
List<Node> nodes = [];
Expand All @@ -63,7 +65,7 @@ removeCol(Node tableNode, int col, Transaction transaction) {
transaction.updateNode(tableNode, {'colsLen': colsLen - 1});
}

removeRow(Node tableNode, int row, Transaction transaction) {
void removeRow(Node tableNode, int row, Transaction transaction) {
final int rowsLen = tableNode.attributes['rowsLen'],
colsLen = tableNode.attributes['colsLen'];
List<Node> nodes = [];
Expand All @@ -83,18 +85,24 @@ removeRow(Node tableNode, int row, Transaction transaction) {
transaction.updateNode(tableNode, {'rowsLen': rowsLen - 1});
}

duplicateCol(Node tableNode, int col, Transaction transaction) {
void duplicateCol(Node tableNode, int col, Transaction transaction) {
final int rowsLen = tableNode.attributes['rowsLen'],
colsLen = tableNode.attributes['colsLen'];
List<Node> nodes = [];
for (var i = 0; i < rowsLen; i++) {
final node = getCellNode(tableNode, col, i)!;
nodes.add(node.copyWith(attributes: {
'position': {'col': col + 1, 'row': i}
}));
nodes.add(
node.copyWith(
attributes: {
'position': {'col': col + 1, 'row': i}
},
),
);
}
transaction.insertNodes(
getCellNode(tableNode, col, rowsLen - 1)!.path.next, nodes);
getCellNode(tableNode, col, rowsLen - 1)!.path.next,
nodes,
);

for (var i = col + 1; i < colsLen; i++) {
for (var j = 0; j < rowsLen; j++) {
Expand All @@ -107,16 +115,18 @@ duplicateCol(Node tableNode, int col, Transaction transaction) {
transaction.updateNode(tableNode, {'colsLen': colsLen + 1});
}

duplicateRow(Node tableNode, int row, Transaction transaction) {
void duplicateRow(Node tableNode, int row, Transaction transaction) {
final int rowsLen = tableNode.attributes['rowsLen'],
colsLen = tableNode.attributes['colsLen'];
for (var i = 0; i < colsLen; i++) {
final node = getCellNode(tableNode, i, row)!;
transaction.insertNode(
node.path.next,
node.copyWith(attributes: {
'position': {'row': row + 1, 'col': i}
}),
node.copyWith(
attributes: {
'position': {'row': row + 1, 'col': i}
},
),
);
}

Expand All @@ -131,7 +141,12 @@ duplicateRow(Node tableNode, int row, Transaction transaction) {
transaction.updateNode(tableNode, {'rowsLen': rowsLen + 1});
}

setColBgColor(Node tableNode, int col, Transaction transaction, String? color) {
void setColBgColor(
Node tableNode,
int col,
Transaction transaction,
String? color,
) {
final rowslen = tableNode.attributes['rowsLen'];
for (var i = 0; i < rowslen; i++) {
final node = getCellNode(tableNode, col, i)!;
Expand All @@ -142,7 +157,12 @@ setColBgColor(Node tableNode, int col, Transaction transaction, String? color) {
}
}

setRowBgColor(Node tableNode, int row, Transaction transaction, String? color) {
void setRowBgColor(
Node tableNode,
int row,
Transaction transaction,
String? color,
) {
final colsLen = tableNode.attributes['colsLen'];
for (var i = 0; i < colsLen; i++) {
final node = getCellNode(tableNode, i, row)!;
Expand All @@ -153,30 +173,33 @@ setRowBgColor(Node tableNode, int row, Transaction transaction, String? color) {
}
}

newCellNode(Node tableNode, n) {
dynamic newCellNode(Node tableNode, n) {
final row = n.attributes['position']['row'] as int;
final col = n.attributes['position']['col'] as int;
final int rowsLen = tableNode.attributes['rowsLen'];
final int colsLen = tableNode.attributes['colsLen'];

if (!n.attributes.containsKey('height')) {
double nodeHeight = double.tryParse(
tableNode.attributes['config']['rowDefaultHeight'].toString())!;
tableNode.attributes['config']['rowDefaultHeight'].toString(),
)!;
if (row < rowsLen) {
nodeHeight = double.tryParse(getCellNode(tableNode, 0, row)!
.attributes['height']
.toString()) ??
nodeHeight = double.tryParse(
getCellNode(tableNode, 0, row)!.attributes['height'].toString(),
) ??
nodeHeight;
}
n.updateAttributes({'height': nodeHeight});
}

if (!n.attributes.containsKey('width')) {
double nodeWidth = double.tryParse(
tableNode.attributes['config']['colDefaultWidth'].toString())!;
tableNode.attributes['config']['colDefaultWidth'].toString(),
)!;
if (col < colsLen) {
nodeWidth = double.tryParse(
getCellNode(tableNode, col, 0)!.attributes['width'].toString()) ??
getCellNode(tableNode, col, 0)!.attributes['width'].toString(),
) ??
nodeWidth;
}
n.updateAttributes({'width': nodeWidth});
Expand Down
36 changes: 21 additions & 15 deletions lib/src/render/table/table_action_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,26 @@ class _TableActionButtonState extends State<TableActionButton> {
@override
Widget build(BuildContext context) {
return Container(
padding: widget.padding,
width: widget.width,
height: widget.height,
child: MouseRegion(
onEnter: (_) => setState(() => _visible = true),
onExit: (_) => setState(() => _visible = false),
child: Center(
child: Visibility(
visible: _visible,
child: ActionMenuWidget(items: [
ActionMenuItem.icon(
iconData: Icons.add, onPressed: () => widget.onPressed()),
]),
),
)));
padding: widget.padding,
width: widget.width,
height: widget.height,
child: MouseRegion(
onEnter: (_) => setState(() => _visible = true),
onExit: (_) => setState(() => _visible = false),
child: Center(
child: Visibility(
visible: _visible,
child: ActionMenuWidget(
items: [
ActionMenuItem.icon(
iconData: Icons.add,
onPressed: () => widget.onPressed(),
),
],
),
),
),
),
);
}
}
25 changes: 15 additions & 10 deletions lib/src/render/table/table_col.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ class _TableColState extends State<TableCol> {
Widget build(BuildContext context) {
List<Widget> children = [];
if (widget.colIdx == 0) {
children.add(TableColBorder(
resizable: false,
tableNode: widget.tableNode,
colIdx: widget.colIdx,
));
children.add(
TableColBorder(
resizable: false,
tableNode: widget.tableNode,
colIdx: widget.colIdx,
),
);
}

children.addAll([
SizedBox(
width: context.select(
(Node n) => getCellNode(n, widget.colIdx, 0)?.attributes['width']),
(Node n) => getCellNode(n, widget.colIdx, 0)?.attributes['width'],
),
child: Column(children: _buildCells(context)),
),
TableColBorder(
Expand Down Expand Up @@ -82,8 +85,10 @@ class _TableColState extends State<TableCol> {
];
}

updateRowHeightCallback(int row) => WidgetsBinding.instance
.addPostFrameCallback((_) => row < widget.tableNode.rowsLen
? widget.tableNode.updateRowHeight(row)
: null);
void updateRowHeightCallback(int row) =>
WidgetsBinding.instance.addPostFrameCallback(
(_) => row < widget.tableNode.rowsLen
? widget.tableNode.updateRowHeight(row)
: null,
);
}
4 changes: 2 additions & 2 deletions lib/src/render/table/table_col_border.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class _TableColBorderState extends State<TableColBorder> {
return buildFixedBorder(context);
}

buildResizableBorder(BuildContext context) {
MouseRegion buildResizableBorder(BuildContext context) {
return MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight,
onEnter: (_) => setState(() => _borderHovering = true),
Expand Down Expand Up @@ -66,7 +66,7 @@ class _TableColBorderState extends State<TableColBorder> {
);
}

buildFixedBorder(BuildContext context) {
Container buildFixedBorder(BuildContext context) {
return Container(
width: widget.tableNode.config.tableBorderWidth,
height: context.select((Node n) => n.attributes['colsHeight']),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/render/table/table_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TableConfig {
});

static TableConfig fromJson(Map<String, dynamic> json) {
func(String key, double defaultVal) => json.containsKey(key)
double func(String key, double defaultVal) => json.containsKey(key)
? double.tryParse(json[key].toString())!
: defaultVal;

Expand All @@ -31,7 +31,7 @@ class TableConfig {

final double tableBorderWidth = 2.0;

clone() => TableConfig(
TableConfig clone() => TableConfig(
colDefaultWidth: colDefaultWidth,
rowDefaultHeight: rowDefaultHeight,
colMinimumWidth: colMinimumWidth,
Expand Down

0 comments on commit 97e61b4

Please sign in to comment.