-
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from fluttercandies/dev
Dev
- Loading branch information
Showing
5 changed files
with
100 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}, | ||
), | ||
), | ||
|
@@ -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)), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|