Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor mobile toolbar and divider block component #583

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ EdgeInsets _padding(Node node) {
EdgeInsets _indentPadding(Node node, TextDirection textDirection) {
switch (textDirection) {
case TextDirection.ltr:
return const EdgeInsets.only(left: 30.0);
return const EdgeInsets.only(left: 24.0);
case TextDirection.rtl:
return const EdgeInsets.only(right: 30.0);
return const EdgeInsets.only(right: 24.0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
class NestedListWidget extends StatelessWidget {
const NestedListWidget({
super.key,
this.indentPadding = const EdgeInsets.only(left: 30),
this.indentPadding = const EdgeInsets.only(left: 28),
required this.child,
required this.children,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
);
}

typedef DividerBlockWrapper = Widget Function(
BuildContext context,
Node node,
Widget child,
);

class DividerBlockComponentBuilder extends BlockComponentBuilder {
DividerBlockComponentBuilder({
super.configuration,
this.lineColor = Colors.grey,
this.height = 10,
this.wrapper,
});

final Color lineColor;
final double height;
final DividerBlockWrapper? wrapper;

@override
BlockComponentWidget build(BlockComponentContext blockComponentContext) {
Expand All @@ -34,6 +42,7 @@
configuration: configuration,
lineColor: lineColor,
height: height,
wrapper: wrapper,
showActions: showActions(node),
actionBuilder: (context, state) => actionBuilder(
blockComponentContext,
Expand All @@ -55,10 +64,12 @@
super.configuration = const BlockComponentConfiguration(),
this.lineColor = Colors.grey,
this.height = 10,
this.wrapper,
});

final Color lineColor;
final double height;
final DividerBlockWrapper? wrapper;

@override
State<DividerBlockComponentWidget> createState() =>
Expand Down Expand Up @@ -119,6 +130,10 @@
);
}

if (widget.wrapper != null) {
child = widget.wrapper!(context, node, child);

Check warning on line 134 in lib/src/editor/block_component/divider_block_component/divider_block_component.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/editor/block_component/divider_block_component/divider_block_component.dart#L134

Added line #L134 was not covered by tests
}

return child;
}

Expand Down
48 changes: 25 additions & 23 deletions lib/src/editor/toolbar/mobile/mobile_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,31 @@ class MobileToolbar extends StatelessWidget {
if (selection == null) {
return const SizedBox.shrink();
}
return MobileToolbarStyle(
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
clearDiagonalLineColor: clearDiagonalLineColor,
itemHighlightColor: itemHighlightColor,
itemOutlineColor: itemOutlineColor,
tabbarSelectedBackgroundColor: tabbarSelectedBackgroundColor,
tabbarSelectedForegroundColor: tabbarSelectedForegroundColor,
primaryColor: primaryColor,
onPrimaryColor: onPrimaryColor,
outlineColor: outlineColor,
toolbarHeight: toolbarHeight,
borderRadius: borderRadius,
buttonHeight: buttonHeight,
buttonSpacing: buttonSpacing,
buttonBorderWidth: buttonBorderWidth,
buttonSelectedBorderWidth: buttonSelectedBorderWidth,
child: MobileToolbarWidget(
// Use selection as key to force rebuild toolbar widget when selection changed.
// key: ValueKey(selection),
editorState: editorState,
selection: selection,
toolbarItems: toolbarItems,
return RepaintBoundary(
child: MobileToolbarStyle(
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
clearDiagonalLineColor: clearDiagonalLineColor,
itemHighlightColor: itemHighlightColor,
itemOutlineColor: itemOutlineColor,
tabbarSelectedBackgroundColor: tabbarSelectedBackgroundColor,
tabbarSelectedForegroundColor: tabbarSelectedForegroundColor,
primaryColor: primaryColor,
onPrimaryColor: onPrimaryColor,
outlineColor: outlineColor,
toolbarHeight: toolbarHeight,
borderRadius: borderRadius,
buttonHeight: buttonHeight,
buttonSpacing: buttonSpacing,
buttonBorderWidth: buttonBorderWidth,
buttonSelectedBorderWidth: buttonSelectedBorderWidth,
child: MobileToolbarWidget(
// Use selection as key to force rebuild toolbar widget when selection changed.
// key: ValueKey(selection),
editorState: editorState,
selection: selection,
toolbarItems: toolbarItems,
),
),
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:flutter_test/flutter_test.dart';

import '../../../infra/testable_editor.dart';

const _padding = 24.0;

void main() async {
group('indentCommand - widget test indent padding', () {
testWidgets("indent LTR line under LTR line", (tester) async {
Expand All @@ -17,7 +19,7 @@ void main() async {
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 30);
expect(nestedBlock?.indentPadding.left, _padding);
expect(nestedBlock?.indentPadding.right, 0);

await editor.dispose();
Expand All @@ -34,7 +36,7 @@ void main() async {
final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 30);
expect(nestedBlock?.indentPadding.left, _padding);
expect(nestedBlock?.indentPadding.right, 0);

await editor.dispose();
Expand All @@ -55,7 +57,7 @@ void main() async {
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, 30);
expect(nestedBlock?.indentPadding.right, _padding);

await editor.dispose();
});
Expand All @@ -75,7 +77,7 @@ void main() async {
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, 30);
expect(nestedBlock?.indentPadding.right, _padding);

await editor.dispose();
});
Expand All @@ -95,7 +97,7 @@ void main() async {
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, 30);
expect(nestedBlock?.indentPadding.right, _padding);

await editor.dispose();
});
Expand All @@ -120,7 +122,7 @@ void main() async {
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, 30);
expect(nestedBlock?.indentPadding.right, _padding);

final selection = Selection.single(
path: [0, 0],
Expand All @@ -134,7 +136,7 @@ void main() async {
final nestedBlockAfter = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();

expect(nestedBlockAfter?.indentPadding.left, 30);
expect(nestedBlockAfter?.indentPadding.left, _padding);
expect(nestedBlockAfter?.indentPadding.right, 0);

await editor.dispose();
Expand Down
Loading