public TextStyle textStyle(SyntaxHighlighterStyle style)
 {
     if (this.type == _HighlightType.number)
     {
         return(style.numberStyle);
     }
     else if (this.type == _HighlightType.comment)
     {
         return(style.commentStyle);
     }
     else if (this.type == _HighlightType.keyword)
     {
         return(style.keywordStyle);
     }
     else if (this.type == _HighlightType._string)
     {
         return(style.stringStyle);
     }
     else if (this.type == _HighlightType.punctuation)
     {
         return(style.punctuationStyle);
     }
     else if (this.type == _HighlightType.klass)
     {
         return(style.classStyle);
     }
     else if (this.type == _HighlightType.constant)
     {
         return(style.constantStyle);
     }
     else
     {
         return(style.baseStyle);
     }
 }
예제 #2
0
        public override Widget build(BuildContext context)
        {
            SyntaxHighlighterStyle style = Theme.of(context).brightness == Brightness.dark
                ? SyntaxHighlighterStyle.darkThemeStyle()
                : SyntaxHighlighterStyle.lightThemeStyle();

            Widget body;

            if (this._exampleCode == null)
            {
                body = new Center(
                    child: new CircularProgressIndicator()
                    );
            }
            else
            {
                body = new SingleChildScrollView(
                    child: new Padding(
                        padding: EdgeInsets.all(16.0f),
                        child: new RichText(
                            text: new TextSpan(
                                style: new TextStyle(fontFamily: "monospace", fontSize: 10.0f),
                                children: new List <TextSpan> {
                    new DartSyntaxHighlighter(style).format(this._exampleCode)
                }
                                )
                            )
                        )
                    );
            }

            return(new Scaffold(
                       appBar: new AppBar(
                           leading: new IconButton(
                               icon: new Icon(
                                   Icons.clear
                                   ),
                               onPressed: () => { Navigator.pop(context); }
                               ),
                           title: new Text("Example code")
                           ),
                       body: body
                       ));
        }
 public DartSyntaxHighlighter(SyntaxHighlighterStyle _style = null)
 {
     this._spans = new List <_HighlightSpan> {
     };
     this._style = _style ?? SyntaxHighlighterStyle.darkThemeStyle();
 }