link editor: preset link from attributes (#597)

pull/599/head
Andy Trand 3 years ago committed by GitHub
parent a1be256ff9
commit 9732f5093c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      lib/src/widgets/toolbar/link_dialog.dart
  2. 5
      lib/src/widgets/toolbar/link_style_button.dart

@ -4,16 +4,26 @@ import '../../models/themes/quill_dialog_theme.dart';
import '../../translations/toolbar.i18n.dart';
class LinkDialog extends StatefulWidget {
const LinkDialog({this.dialogTheme, Key? key}) : super(key: key);
const LinkDialog({this.dialogTheme, this.link, Key? key})
: super(key: key);
final QuillDialogTheme? dialogTheme;
final String? link;
@override
LinkDialogState createState() => LinkDialogState();
}
class LinkDialogState extends State<LinkDialog> {
String _link = '';
late String _link;
late TextEditingController _controller;
@override
void initState() {
super.initState();
_link = widget.link ?? '';
_controller = TextEditingController(text: _link);
}
@override
Widget build(BuildContext context) {
@ -27,6 +37,7 @@ class LinkDialogState extends State<LinkDialog> {
floatingLabelStyle: widget.dialogTheme?.labelTextStyle),
autofocus: true,
onChanged: _linkChanged,
controller: _controller,
),
actions: [
TextButton(

@ -99,7 +99,10 @@ class _LinkStyleButtonState extends State<LinkStyleButton> {
showDialog<String>(
context: context,
builder: (ctx) {
return LinkDialog(dialogTheme: widget.dialogTheme);
final link = widget.controller
.getSelectionStyle()
.attributes[Attribute.link.key]?.value;
return LinkDialog(dialogTheme: widget.dialogTheme, link: link);
},
).then(_linkSubmitted);
}

Loading…
Cancel
Save