Readonly mode launch url

pull/13/head
singerdmx 4 years ago
parent 4e5f5f4adf
commit 4ea9446a03
  1. 8
      app/lib/pages/home_page.dart
  2. 56
      app/pubspec.lock
  3. 1
      app/pubspec.yaml
  4. 14
      lib/widgets/editor.dart
  5. 2
      lib/widgets/text_block.dart

@ -6,6 +6,7 @@ import 'package:flutter_quill/models/documents/document.dart';
import 'package:flutter_quill/widgets/controller.dart';
import 'package:flutter_quill/widgets/editor.dart';
import 'package:flutter_quill/widgets/toolbar.dart';
import 'package:url_launcher/url_launcher.dart';
class HomePage extends StatefulWidget {
@override
@ -78,10 +79,17 @@ class _HomePageState extends State<HomePage> {
enableInteractiveSelection: true,
expands: false,
padding: EdgeInsets.zero,
onLaunchUrl: _launchUrl,
),
),
),
],
);
}
void _launchUrl(String url) async {
if (await canLaunch(url)) {
await launch(url);
}
}
}

@ -74,6 +74,11 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
matcher:
dependency: transitive
description:
@ -95,6 +100,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.1"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
quill_delta:
dependency: transitive
description:
@ -177,6 +189,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "5.7.10"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+4"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+9"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.9"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5+1"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+3"
vector_math:
dependency: transitive
description:
@ -186,4 +240,4 @@ packages:
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.17.0 <2.0.0"
flutter: ">=1.22.0 <2.0.0"

@ -23,6 +23,7 @@ environment:
dependencies:
flutter:
sdk: flutter
url_launcher: ^5.7.10
# The following adds the Cupertino Icons font to your application.

@ -22,6 +22,9 @@ import 'cursor.dart';
import 'default_styles.dart';
import 'delegate.dart';
const urlPattern =
r"^((https?|http)://)?([-A-Z0-9.]+)(/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#/%=~_|!:,.;]*)?$";
abstract class EditorState extends State<RawEditor> {
TextEditingValue getTextEditingValue();
@ -252,6 +255,8 @@ class _QuillEditorState extends State<QuillEditor>
class _QuillEditorSelectionGestureDetectorBuilder
extends EditorTextSelectionGestureDetectorBuilder {
static final urlRegExp = new RegExp(urlPattern, caseSensitive: false);
final _QuillEditorState _state;
_QuillEditorSelectionGestureDetectorBuilder(this._state) : super(_state);
@ -313,10 +318,11 @@ class _QuillEditorSelectionGestureDetectorBuilder
Leaf segment = segmentResult.node as Leaf;
if (segment.style.containsKey(Attribute.link.key) &&
getEditor().widget.onLaunchUrl != null) {
if (getEditor().widget.readOnly) {
getEditor()
.widget
.onLaunchUrl(segment.style.attributes[Attribute.link.key].value);
String link = segment.style.attributes[Attribute.link.key].value;
if (getEditor().widget.readOnly &&
link != null &&
urlRegExp.firstMatch(link) != null) {
getEditor().widget.onLaunchUrl(link);
}
}
}

@ -596,7 +596,7 @@ class _NumberPoint extends StatelessWidget {
}
if (this.indentLevelCounts.containsKey(level + 1)) {
// last visited level is done, going up
this.indentLevelCounts[level + 1] = 0;
this.indentLevelCounts.remove(level + 1);
}
int count = (this.indentLevelCounts[level] ?? 0) + 1;
this.indentLevelCounts[level] = count;

Loading…
Cancel
Save