Skip to content

Commit

Permalink
linter issues fixed; popup calculate position fixed;
Browse files Browse the repository at this point in the history
  • Loading branch information
drooxie committed May 23, 2023
1 parent 4303978 commit 1d1763a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
5 changes: 5 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
include: package:solid_lints/analysis_options.yaml

dart_code_metrics:
rules:
- no-magic-number:
allow-only-once: true
15 changes: 10 additions & 5 deletions example/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ class _AppState extends State<App> {
@override
Widget build(BuildContext context) {
return Material(
child: LanguageToolTextField(
style: const TextStyle(),
decoration: const InputDecoration(),
coloredController: _controller,
mistakePopup: LanguageToolMistakePopup(width: 250, height: 150),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
LanguageToolTextField(
style: const TextStyle(),
decoration: const InputDecoration(),
coloredController: _controller,
mistakePopup: LanguageToolMistakePopup(width: 250, height: 150),
),
],
),
);
}
Expand Down
39 changes: 24 additions & 15 deletions lib/utils/language_tool_mistake_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LanguageToolMistakePopup {
final Offset _popupPosition = _calculatePosition(context, mistakeOffset);
final _popupBuilderToUse = popupBuilder ?? _defaultPopupBuilder;

_overlayEntry = OverlayEntry(
final _createdEntry = OverlayEntry(
builder: (context) => GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Expand All @@ -56,22 +56,27 @@ class LanguageToolMistakePopup {
),
),
);

Overlay.of(context).insert(_overlayEntry!);
Overlay.of(context).insert(_createdEntry);
_overlayEntry = _createdEntry;
}

Widget _defaultPopupBuilder(
Mistake mistake,
ColoredTextEditingController controller,
) {
const _borderRadius = 10.0;
const _mistakeNameFontSize = 13.0;
const _mistakeMessageFontSize = 15.0;
const _replacementsButtonsRowHeight = 35.0;

return Container(
padding: const EdgeInsets.all(10),
width: width,
height: height,
decoration: BoxDecoration(
boxShadow: const [BoxShadow(color: Colors.grey, blurRadius: 20)],
color: Colors.white,
borderRadius: BorderRadius.circular(10),
borderRadius: BorderRadius.circular(_borderRadius),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand All @@ -81,7 +86,7 @@ class LanguageToolMistakePopup {
mistake.type.name,
style: TextStyle(
color: Colors.grey.shade700,
fontSize: 13,
fontSize: _mistakeNameFontSize,
fontWeight: FontWeight.w500,
),
),
Expand All @@ -93,14 +98,14 @@ class LanguageToolMistakePopup {
mistake.message,
style: const TextStyle(
// fontStyle: FontStyle.italic,
fontSize: 15,
fontSize: _mistakeMessageFontSize,
),
),
),
),
const SizedBox(height: 10),
SizedBox(
height: 35,
height: _replacementsButtonsRowHeight,
child: ListView.separated(
separatorBuilder: (context, index) => const SizedBox(
width: 5,
Expand Down Expand Up @@ -137,18 +142,22 @@ class LanguageToolMistakePopup {
width: width,
height: height,
);
const _defaultPopupPadding = 10.0;
const _popupBorderPadding = 10.0;
const _popupYDistance = 30.0;

double dx = _popupRect.left;
dx = max(_defaultPopupPadding, dx);

if (dx + width > _screenSize.width) {
dx = _screenSize.width - width - _defaultPopupPadding;
// limiting X offset left border
dx = max(_popupBorderPadding, dx);
// limiting X offset right border
if ((dx + width) > _screenSize.width) {
dx = (_screenSize.width - width) - _popupBorderPadding;
}

double dy = mistakeOffset.dy + 30;
if (dy <= MediaQuery.of(context).padding.top + _defaultPopupPadding) {
dy = mistakeOffset.dy - _defaultPopupPadding * 3;
// under the mistake
double dy = mistakeOffset.dy + _popupYDistance;
// if not enough space underneath, rendering above the mistake
if ((dy + height) > _screenSize.height) {
dy = (mistakeOffset.dy - height) - _popupYDistance;
}

return Offset(dx, dy);
Expand Down

0 comments on commit 1d1763a

Please sign in to comment.