diff --git a/analysis_options.yaml b/analysis_options.yaml index 21bc10a..76d90b3 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1,6 @@ include: package:solid_lints/analysis_options.yaml + +dart_code_metrics: + rules: + - no-magic-number: + allow-only-once: true \ No newline at end of file diff --git a/example/lib/app.dart b/example/lib/app.dart index b1d064a..84fd3c0 100644 --- a/example/lib/app.dart +++ b/example/lib/app.dart @@ -28,11 +28,16 @@ class _AppState extends State { @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), + ), + ], ), ); } diff --git a/lib/utils/language_tool_mistake_popup.dart b/lib/utils/language_tool_mistake_popup.dart index fb1edfc..ddf2ec4 100644 --- a/lib/utils/language_tool_mistake_popup.dart +++ b/lib/utils/language_tool_mistake_popup.dart @@ -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: () { @@ -56,14 +56,19 @@ 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, @@ -71,7 +76,7 @@ class LanguageToolMistakePopup { 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, @@ -81,7 +86,7 @@ class LanguageToolMistakePopup { mistake.type.name, style: TextStyle( color: Colors.grey.shade700, - fontSize: 13, + fontSize: _mistakeNameFontSize, fontWeight: FontWeight.w500, ), ), @@ -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, @@ -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);