Skip to content

Commit

Permalink
Merge pull request #37 from fluttercandies/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
zmtzawqlp authored Aug 7, 2019
2 parents daa176e + c6bb072 commit 5da12f1
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
88 changes: 75 additions & 13 deletions example/lib/common/my_extended_text_selection_controls.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,78 @@
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<TextSelectionPoint> 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: () {
//mailto:<email address>?subject=<subject>&body=<body>, e.g.
launch(
"mailto:[email protected]?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));
},
),
),
Expand All @@ -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;

Expand All @@ -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)),
);
}
}
31 changes: 16 additions & 15 deletions example/lib/photo_view_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,22 @@ class _PhotoViewDemoState extends State<PhotoViewDemo> {
ScreenUtil.instance.setSp(28),
color: Colors.grey),
maxLines: 10,
overFlowTextSpan: OverFlowTextSpan(
children: <TextSpan>[
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>[
// 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,
Expand Down
5 changes: 2 additions & 3 deletions lib/src/extended_image_border_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
homepage: https://github.com/fluttercandies/extended_image

Expand Down

0 comments on commit 5da12f1

Please sign in to comment.