add parsing font size from string

pull/31/head
ritheshSalyan 4 years ago
parent 0871c287e6
commit 793e5b6660
  1. 30
      app/assets/sample_data.json
  2. 2
      app/lib/pages/home_page.dart
  3. 4
      lib/models/documents/attribute.dart
  4. 6
      lib/widgets/text_line.dart

@ -451,7 +451,7 @@
},
{
"attributes": {
"size": 12.0
"size": "small"
},
"insert": "Small"
},
@ -460,7 +460,7 @@
},
{
"attributes": {
"size": 35.0
"size": "large"
},
"insert": "Large"
},
@ -469,10 +469,34 @@
},
{
"attributes": {
"size": 60.0
"size": "huge"
},
"insert": "Huge"
},
{
"attributes": {
"size": "15.0"
},
"insert": "font size 15"
},
{
"insert": " "
},
{
"attributes": {
"size": "35"
},
"insert": "font size 35"
},
{
"insert": " "
},
{
"attributes": {
"size": "50"
},
"insert": "font size 50"
},
{
"insert": "\n"
}

@ -71,7 +71,7 @@ class _HomePageState extends State<HomePage> {
onPressed: (){
int option = Random().nextInt(30);
print(option);
_controller.formatSelection(SizeAttribute(option.toDouble()));
_controller.formatSelection(SizeAttribute("${option.toDouble()}"));
},
),
body: RawKeyboardListener(

@ -206,8 +206,8 @@ class FontAttribute extends Attribute<double> {
FontAttribute(double val) : super('font', AttributeScope.INLINE, val);
}
class SizeAttribute extends Attribute<double> {
SizeAttribute(double val) : super('size', AttributeScope.INLINE, val);
class SizeAttribute extends Attribute<String> {
SizeAttribute(String val) : super('size', AttributeScope.INLINE, val);
}
class LinkAttribute extends Attribute<String> {

@ -137,6 +137,7 @@ class TextLine extends StatelessWidget {
Attribute size = textNode.style.attributes[Attribute.size.key];
if (size != null && size.value != null) {
switch (size.value) {
case 'small':
res = res.merge(defaultStyles.sizeSmall);
@ -148,6 +149,11 @@ class TextLine extends StatelessWidget {
res = res.merge(defaultStyles.sizeHuge);
break;
default:
double fontSize = double.tryParse(size.value);
if(fontSize!=null){
res = res.merge(TextStyle(fontSize: fontSize));
}
else
throw "Invalid size ${size.value}";
}
}

Loading…
Cancel
Save