Refactor code

pull/635/head
X Code 3 years ago
parent 7a4b05934b
commit 97cb20298f
  1. 8
      lib/src/models/documents/attribute.dart
  2. 6
      lib/src/utils/string.dart
  3. 21
      lib/src/widgets/embeds/default_embed_builder.dart

@ -89,6 +89,14 @@ class Attribute<T> {
static final ScriptAttribute script = ScriptAttribute('');
static const String mobileWidth = 'mobileWidth';
static const String mobileHeight = 'mobileHeight';
static const String mobileMargin = 'mobileMargin';
static const String mobileAlignment = 'mobileAlignment';
static final Set<String> inlineKeys = {
Attribute.bold.key,
Attribute.italic.key,

@ -1,5 +1,7 @@
import 'package:flutter/cupertino.dart';
import '../models/documents/attribute.dart';
Map<String, String> parseKeyValuePairs(String s, Set<String> targetKeys) {
final result = <String, String>{};
final pairs = s.split(';');
@ -29,8 +31,8 @@ String replaceStyleString(String s, double width, double height) {
result[_key] = pair.substring(_index + 1).trim();
}
result['mobileWidth'] = width.toString();
result['mobileHeight'] = height.toString();
result[Attribute.mobileWidth] = width.toString();
result[Attribute.mobileHeight] = height.toString();
final sb = StringBuffer();
for (final pair in result.entries) {
sb

@ -29,19 +29,24 @@ Widget defaultEmbedBuilder(BuildContext context, QuillController controller,
var image;
final style = node.style.attributes['style'];
if (isMobile() && style != null) {
final _attrs = parseKeyValuePairs(style.value.toString(),
{'mobileWidth', 'mobileHeight', 'mobileMargin', 'mobileAlignment'});
final _attrs = parseKeyValuePairs(style.value.toString(), {
Attribute.mobileWidth,
Attribute.mobileHeight,
Attribute.mobileMargin,
Attribute.mobileAlignment
});
if (_attrs.isNotEmpty) {
assert(
_attrs['mobileWidth'] != null && _attrs['mobileHeight'] != null,
_attrs[Attribute.mobileWidth] != null &&
_attrs[Attribute.mobileHeight] != null,
'mobileWidth and mobileHeight must be specified');
final w = double.parse(_attrs['mobileWidth']!);
final h = double.parse(_attrs['mobileHeight']!);
final w = double.parse(_attrs[Attribute.mobileWidth]!);
final h = double.parse(_attrs[Attribute.mobileHeight]!);
_widthHeight = Tuple2(w, h);
final m = _attrs['mobileMargin'] == null
final m = _attrs[Attribute.mobileMargin] == null
? 0.0
: double.parse(_attrs['mobileMargin']!);
final a = getAlignment(_attrs['mobileAlignment']);
: double.parse(_attrs[Attribute.mobileMargin]!);
final a = getAlignment(_attrs[Attribute.mobileAlignment]);
image = Padding(
padding: EdgeInsets.all(m),
child: imageByUrl(imageUrl, width: w, height: h, alignment: a));

Loading…
Cancel
Save