Skip to content

Commit

Permalink
Add PointerInterceptor widget that prevents mouse events from being…
Browse files Browse the repository at this point in the history
… captured by an underlying HtmlElementView in web
  • Loading branch information
dab246 committed Jul 25, 2024
1 parent 87e7d05 commit 4ebe87c
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 111 deletions.
225 changes: 114 additions & 111 deletions lib/src/utils/mistake_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:languagetool_textfield/src/domain/mistake.dart';
import 'package:languagetool_textfield/src/domain/typedefs.dart';
import 'package:languagetool_textfield/src/utils/extensions/string_extension.dart';
import 'package:languagetool_textfield/src/utils/popup_overlay_renderer.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';

/// Builder class that uses specified [popupRenderer] and [mistakeBuilder]
/// to create mistake popup
Expand Down Expand Up @@ -112,129 +113,131 @@ class LanguageToolMistakePopup extends StatelessWidget {

final availableSpace = _calculateAvailableSpace(context);

return ConstrainedBox(
constraints: BoxConstraints(
maxWidth: maxWidth,
maxHeight: availableSpace,
),
child: Container(
margin: EdgeInsets.symmetric(
horizontal: horizontalMargin,
vertical: verticalMargin,
),
decoration: BoxDecoration(
color: const Color.fromRGBO(241, 243, 248, 1.0),
borderRadius: BorderRadius.circular(_borderRadius),
boxShadow: const [BoxShadow(color: Colors.grey, blurRadius: 8)],
return PointerInterceptor(
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: maxWidth,
maxHeight: availableSpace,
),
padding: const EdgeInsets.only(
top: 8,
bottom: 4,
left: 4,
right: 4,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 4),
child: Row(
children: [
Expanded(
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 5.0),
child: Image.asset(
LangToolImages.logo,
width: _iconSize,
height: _iconSize,
package: 'languagetool_textfield',
child: Container(
margin: EdgeInsets.symmetric(
horizontal: horizontalMargin,
vertical: verticalMargin,
),
decoration: BoxDecoration(
color: const Color.fromRGBO(241, 243, 248, 1.0),
borderRadius: BorderRadius.circular(_borderRadius),
boxShadow: const [BoxShadow(color: Colors.grey, blurRadius: 8)],
),
padding: const EdgeInsets.only(
top: 8,
bottom: 4,
left: 4,
right: 4,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 4),
child: Row(
children: [
Expanded(
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 5.0),
child: Image.asset(
LangToolImages.logo,
width: _iconSize,
height: _iconSize,
package: 'languagetool_textfield',
),
),
),
const Text('Correct'),
],
const Text('Correct'),
],
),
),
),
IconButton(
icon: const Icon(
Icons.close,
size: 12,
IconButton(
icon: const Icon(
Icons.close,
size: 12,
),
constraints: const BoxConstraints(),
padding: EdgeInsets.zero,
splashRadius: _dismissSplashRadius,
onPressed: () {
_dismissDialog();
controller.onClosePopup();
},
),
constraints: const BoxConstraints(),
padding: EdgeInsets.zero,
splashRadius: _dismissSplashRadius,
onPressed: () {
_dismissDialog();
controller.onClosePopup();
},
),
],
),
),
Container(
margin: const EdgeInsets.only(top: 8),
padding: const EdgeInsets.all(padding),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(_borderRadius),
],
),
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.only(
bottom: _paddingBetweenTitle,
),
child: Text(
mistake.type.name.capitalize(),
style: TextStyle(
color: Colors.grey.shade700,
fontSize: _mistakeNameFontSize,
fontWeight: FontWeight.w600,
letterSpacing: _titleLetterSpacing,
Container(
margin: const EdgeInsets.only(top: 8),
padding: const EdgeInsets.all(padding),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(_borderRadius),
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.only(
bottom: _paddingBetweenTitle,
),
child: Text(
mistake.type.name.capitalize(),
style: TextStyle(
color: Colors.grey.shade700,
fontSize: _mistakeNameFontSize,
fontWeight: FontWeight.w600,
letterSpacing: _titleLetterSpacing,
),
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: padding),
child: Text(
mistake.message,
style: const TextStyle(
fontSize: _mistakeMessageFontSize,
Padding(
padding: const EdgeInsets.only(bottom: padding),
child: Text(
mistake.message,
style: const TextStyle(
fontSize: _mistakeMessageFontSize,
),
),
),
),
Wrap(
spacing: _replacementButtonsSpacing,
runSpacing: kIsWeb
? _replacementButtonsSpacing
: _replacementButtonsSpacingMobile,
children: mistake.replacements
.map(
(replacement) => ElevatedButton(
onPressed: () => _fixTheMistake(replacement),
style: mistakeStyle ??
ElevatedButton.styleFrom(
elevation: 0,
minimumSize: const Size(40, 36),
padding: const EdgeInsets.symmetric(
horizontal: 8,
Wrap(
spacing: _replacementButtonsSpacing,
runSpacing: kIsWeb
? _replacementButtonsSpacing
: _replacementButtonsSpacingMobile,
children: mistake.replacements
.map(
(replacement) => ElevatedButton(
onPressed: () => _fixTheMistake(replacement),
style: mistakeStyle ??
ElevatedButton.styleFrom(
elevation: 0,
minimumSize: const Size(40, 36),
padding: const EdgeInsets.symmetric(
horizontal: 8,
),
),
),
child: Text(replacement),
),
)
.toList(),
),
],
child: Text(replacement),
),
)
.toList(),
),
],
),
),
),
),
],
],
),
),
),
),
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies:
sdk: flutter
http: ^1.0.0
throttling: ^2.0.1
pointer_interceptor: ^0.10.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 4ebe87c

Please sign in to comment.