diff --git a/lib/src/utils/string_helper.dart b/lib/src/utils/string_helper.dart index 44abfd8a..e3d8b7e0 100644 --- a/lib/src/utils/string_helper.dart +++ b/lib/src/utils/string_helper.dart @@ -1,3 +1,5 @@ +import 'package:flutter/cupertino.dart'; + Map parseKeyValuePairs(String s, Set targetKeys) { final result = {}; final pairs = s.split(';'); @@ -14,3 +16,37 @@ Map parseKeyValuePairs(String s, Set targetKeys) { return result; } + +Alignment getAlignment(String? s) { + const _defaultAlignment = Alignment.center; + if (s == null) { + return _defaultAlignment; + } + + final _index = [ + 'topLeft', + 'topCenter', + 'topRight', + 'centerLeft', + 'center', + 'centerRight', + 'bottomLeft', + 'bottomCenter', + 'bottomRight' + ].indexOf(s); + if (_index < 0) { + return _defaultAlignment; + } + + return [ + Alignment.topLeft, + Alignment.topCenter, + Alignment.topRight, + Alignment.centerLeft, + Alignment.center, + Alignment.centerRight, + Alignment.bottomLeft, + Alignment.bottomCenter, + Alignment.bottomRight + ][_index]; +} diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index 4d344d5f..7cf198e7 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -165,33 +165,7 @@ Widget defaultEmbedBuilder( final m = _attrs['mobileMargin'] == null ? 0.0 : double.parse(_attrs['mobileMargin']!); - var a = Alignment.center; - if (_attrs['mobileAlignment'] != null) { - final _index = [ - 'topLeft', - 'topCenter', - 'topRight', - 'centerLeft', - 'center', - 'centerRight', - 'bottomLeft', - 'bottomCenter', - 'bottomRight' - ].indexOf(_attrs['mobileAlignment']!); - if (_index >= 0) { - a = [ - Alignment.topLeft, - Alignment.topCenter, - Alignment.topRight, - Alignment.centerLeft, - Alignment.center, - Alignment.centerRight, - Alignment.bottomLeft, - Alignment.bottomCenter, - Alignment.bottomRight - ][_index]; - } - } + final a = getAlignment(_attrs['mobileAlignment']); return Padding( padding: EdgeInsets.all(m), child: imageUrl.startsWith('http')