diff --git a/CHANGELOG.md b/CHANGELOG.md index 1511a3ad..1f9c84df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [0.5.4] + +* Issues: + Fix issue about borderRadius and border + Fix demo error about extended_text + ## [0.5.3] * Improve codes base on v1.7.8 diff --git a/example/lib/common/my_extended_text_selection_controls.dart b/example/lib/common/my_extended_text_selection_controls.dart index f393720f..fda728f8 100644 --- a/example/lib/common/my_extended_text_selection_controls.dart +++ b/example/lib/common/my_extended_text_selection_controls.dart @@ -1,28 +1,67 @@ import 'package:extended_text/extended_text.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'dart:math' as math; + +// Minimal padding from all edges of the selection toolbar to all edges of the +// viewport. + +const double _kToolbarScreenPadding = 8.0; +const double _kToolbarHeight = 44.0; +const double _kHandleSize = 22.0; /// -/// create by zmtzawqlp on 2019/6/10 +/// create by zmtzawqlp on 2019/8/3 /// class MyExtendedMaterialTextSelectionControls - extends ExtendedMaterialTextSelectionControls { + extends MaterialExtendedTextSelectionControls { + MyExtendedMaterialTextSelectionControls(); @override - Widget buildToolbar(BuildContext context, Rect globalEditableRegion, - Offset position, TextSelectionDelegate delegate) { + Widget buildToolbar( + BuildContext context, + Rect globalEditableRegion, + double textLineHeight, + Offset position, + List endpoints, + TextSelectionDelegate delegate, + ) { assert(debugCheckHasMediaQuery(context)); assert(debugCheckHasMaterialLocalizations(context)); + + // The toolbar should appear below the TextField + // when there is not enough space above the TextField to show it. + final TextSelectionPoint startTextSelectionPoint = endpoints[0]; + final TextSelectionPoint endTextSelectionPoint = + (endpoints.length > 1) ? endpoints[1] : null; + final double x = (endTextSelectionPoint == null) + ? startTextSelectionPoint.point.dx + : (startTextSelectionPoint.point.dx + endTextSelectionPoint.point.dx) / + 2.0; + final double availableHeight = globalEditableRegion.top - + MediaQuery.of(context).padding.top - + _kToolbarScreenPadding; + final double y = (availableHeight < _kToolbarHeight) + ? startTextSelectionPoint.point.dy + + globalEditableRegion.height + + _kToolbarHeight + + _kToolbarScreenPadding + : startTextSelectionPoint.point.dy - textLineHeight * 2.0; + final Offset preciseMidpoint = Offset(x, y); + return ConstrainedBox( constraints: BoxConstraints.tight(globalEditableRegion.size), child: CustomSingleChildLayout( - delegate: ExtendedTextSelectionToolbarLayout( + delegate: MaterialExtendedTextSelectionToolbarLayout( MediaQuery.of(context).size, globalEditableRegion, - position, + preciseMidpoint, ), child: _TextSelectionToolbar( + handleCut: canCut(delegate) ? () => handleCut(delegate) : null, handleCopy: canCopy(delegate) ? () => handleCopy(delegate) : null, + handlePaste: canPaste(delegate) ? () => handlePaste(delegate) : null, handleSelectAll: canSelectAll(delegate) ? () => handleSelectAll(delegate) : null, handleLike: () { @@ -30,6 +69,10 @@ class MyExtendedMaterialTextSelectionControls launch( "mailto:zmtzawqlp@live.com?subject=extended_text_share&body=${delegate.textEditingValue.text}"); delegate.hideToolbar(); + //clear selecction + delegate.textEditingValue = delegate.textEditingValue.copyWith( + selection: TextSelection.collapsed( + offset: delegate.textEditingValue.selection.end)); }, ), ), @@ -39,11 +82,18 @@ class MyExtendedMaterialTextSelectionControls /// Manages a copy/paste text selection toolbar. class _TextSelectionToolbar extends StatelessWidget { - const _TextSelectionToolbar( - {Key key, this.handleCopy, this.handleSelectAll, this.handleLike}) - : super(key: key); + const _TextSelectionToolbar({ + Key key, + this.handleCopy, + this.handleSelectAll, + this.handleCut, + this.handlePaste, + this.handleLike, + }) : super(key: key); + final VoidCallback handleCut; final VoidCallback handleCopy; + final VoidCallback handlePaste; final VoidCallback handleSelectAll; final VoidCallback handleLike; @@ -53,22 +103,34 @@ class _TextSelectionToolbar extends StatelessWidget { final MaterialLocalizations localizations = MaterialLocalizations.of(context); + if (handleCut != null) + items.add(FlatButton( + child: Text(localizations.cutButtonLabel), onPressed: handleCut)); if (handleCopy != null) items.add(FlatButton( child: Text(localizations.copyButtonLabel), onPressed: handleCopy)); + if (handlePaste != null) + items.add(FlatButton( + child: Text(localizations.pasteButtonLabel), + onPressed: handlePaste, + )); if (handleSelectAll != null) items.add(FlatButton( child: Text(localizations.selectAllButtonLabel), onPressed: handleSelectAll)); + if (handleLike != null) items.add(FlatButton(child: Icon(Icons.favorite), onPressed: handleLike)); + // If there is no option available, build an empty widget. + if (items.isEmpty) { + return Container(width: 0.0, height: 0.0); + } + return Material( elevation: 1.0, - child: Container( - height: 44.0, - child: Row(mainAxisSize: MainAxisSize.min, children: items), - ), + child: Wrap(children: items), + borderRadius: BorderRadius.all(Radius.circular(10.0)), ); } } diff --git a/example/lib/photo_view_demo.dart b/example/lib/photo_view_demo.dart index 92f4c0e8..7316b1f8 100644 --- a/example/lib/photo_view_demo.dart +++ b/example/lib/photo_view_demo.dart @@ -129,21 +129,22 @@ class _PhotoViewDemoState extends State { ScreenUtil.instance.setSp(28), color: Colors.grey), maxLines: 10, - overFlowTextSpan: OverFlowTextSpan( - children: [ - TextSpan(text: ' \u2026 '), - TextSpan( - text: "more detail", - style: TextStyle( - color: Colors.blue, - ), - recognizer: TapGestureRecognizer() - ..onTap = () { - launch( - "https://github.com/fluttercandies/extended_text"); - }) - ], - ), + overflow: TextOverflow.ellipsis, +// overFlowTextSpan: OverFlowTextSpan( +// children: [ +// TextSpan(text: ' \u2026 '), +// TextSpan( +// text: "more detail", +// style: TextStyle( +// color: Colors.blue, +// ), +// recognizer: TapGestureRecognizer() +// ..onTap = () { +// launch( +// "https://github.com/fluttercandies/extended_text"); +// }) +// ], +// ), selectionEnabled: true, textSelectionControls: _myExtendedMaterialTextSelectionControls, diff --git a/lib/src/extended_image_border_painter.dart b/lib/src/extended_image_border_painter.dart index 8b99addc..e486c076 100644 --- a/lib/src/extended_image_border_painter.dart +++ b/lib/src/extended_image_border_painter.dart @@ -60,9 +60,8 @@ class ExtendedImageBorderPainter extends CustomPainter { border.paint(canvas, outputRect, shape: shape); break; case BoxShape.rectangle: - if (borderRadius != null) - border.paint(canvas, outputRect, - shape: shape, borderRadius: borderRadius); + border.paint(canvas, outputRect, + shape: shape, borderRadius: borderRadius); break; } } diff --git a/pubspec.yaml b/pubspec.yaml index 3c5e29cd..ab19fcd3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: extended_image description: extended official image which support placeholder(loading)/ failed state,cache network,zoom pan image,photo view,slide out page,crop,save,paint etc. -version: 0.5.3 +version: 0.5.4 author: zmtzawqlp homepage: https://github.com/fluttercandies/extended_image