File tree 8 files changed +126
-1
lines changed
8 files changed +126
-1
lines changed Original file line number Diff line number Diff line change
1
+ abstract class BodyElement {
2
+ String get type;
3
+ Map <String , dynamic > toMap ();
4
+ }
Original file line number Diff line number Diff line change
1
+ import 'body_element.dart' ;
2
+
1
3
class Canvas {
2
4
String backgroundColor;
3
5
List <String > bodyElementIds;
6
+ List <BodyElement > bodyElements;
4
7
bool isHidden = false ;
5
8
bool isPublished = false ;
6
9
String name;
7
10
11
+ Canvas ({
12
+ this .backgroundColor,
13
+ this .bodyElementIds,
14
+ this .isHidden,
15
+ this .isPublished,
16
+ this .name,
17
+ });
18
+
8
19
Map <String , dynamic > toMap () {
9
20
return {
10
21
'background_color' : backgroundColor,
Original file line number Diff line number Diff line change 1
1
library facebook_canvas;
2
2
3
- export 'canvas.dart' ;
3
+ export 'body_element.dart' ;
4
+ export 'inline_style.dart' ;
5
+ export 'rich_text.dart' ;
6
+ export 'text.dart' ;
7
+ export 'canvas.dart' ;
Original file line number Diff line number Diff line change
1
+ class InlineStyle {
2
+ int length;
3
+ int offset;
4
+ String style;
5
+
6
+ InlineStyle ({
7
+ this .length,
8
+ this .offset,
9
+ this .style,
10
+ });
11
+
12
+ Map <String , dynamic > toMap () {
13
+ return {
14
+ 'length' : length,
15
+ 'offset' : offset,
16
+ 'style' : style,
17
+ };
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ import 'inline_style.dart' ;
2
+
3
+ class RichText {
4
+ List <InlineStyle > inlineStyles;
5
+ String plainText;
6
+
7
+ RichText (this .plainText, [this .inlineStyles = const []]);
8
+
9
+ Map <String , dynamic > toMap () {
10
+ return {
11
+ 'inline_styles' :
12
+ inlineStyles.map ((inlineStyle) => inlineStyle? .toMap ()).toList (),
13
+ 'plain_text' : plainText,
14
+ };
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ import 'rich_text.dart' ;
2
+ import 'body_element.dart' ;
3
+
4
+ enum TextAlignment {
5
+ left,
6
+ center,
7
+ right,
8
+ }
9
+
10
+ class Text implements BodyElement {
11
+ String type = 'canvas_text' ;
12
+
13
+ String backgroundColor;
14
+ double bottomPadding;
15
+ String fontFamily;
16
+ int fontSize;
17
+ double lineHeight;
18
+ String name;
19
+ RichText richText;
20
+ TextAlignment textAlignment;
21
+ String textColor;
22
+ double topPadding;
23
+
24
+ Text ({
25
+ this .backgroundColor,
26
+ this .bottomPadding,
27
+ this .fontFamily,
28
+ this .fontSize,
29
+ this .lineHeight,
30
+ this .name,
31
+ this .richText,
32
+ this .textAlignment = TextAlignment .center,
33
+ this .textColor,
34
+ this .topPadding,
35
+ });
36
+
37
+ Map <String , dynamic > toMap () {
38
+ return {
39
+ 'background_color' : backgroundColor,
40
+ 'bottom_padding' : bottomPadding,
41
+ 'font_family' : fontFamily,
42
+ 'font_size' : fontSize,
43
+ 'line_height' : lineHeight,
44
+ 'name' : name,
45
+ 'rich_text' : richText? .toMap (),
46
+ 'text_alignment' : textAlignment
47
+ .toString ()
48
+ .substring ('TextAlignment.' .length)
49
+ .toUpperCase (),
50
+ 'text_color' : textColor,
51
+ 'top_padding' : topPadding,
52
+ };
53
+ }
54
+ }
Original file line number Diff line number Diff line change 1
1
name : facebook_canvas
2
2
version : 0.1.0
3
3
description : Facebook Canvas elements in Dart.
4
+
5
+ dev_dependencies :
6
+ test :
Original file line number Diff line number Diff line change
1
+ import 'package:test/test.dart' ;
2
+
3
+ import 'package:facebook_canvas/text.dart' ;
4
+
5
+ void main () {
6
+ test ('.toMap()' , () {
7
+ final text = new Text ();
8
+ text.textAlignment = TextAlignment .center;
9
+
10
+ final map = text.toMap ();
11
+
12
+ expect (map['text_alignment' ], equals ('CENTER' ));
13
+ });
14
+ }
You can’t perform that action at this time.
0 commit comments