Esempio n. 1
0
        Widget _parseNode(HtmlNode node)
        {
            if (this.customRender != null)
            {
                Widget customWidget = this.customRender(node, this._parseNodeList(node.ChildNodes));
                if (customWidget != null)
                {
                    return(customWidget);
                }
            }

            if (node.NodeType is HtmlNodeType.Element)
            {
                if (!_supportedElements.Contains(node.Name))
                {
                    return(new Container());
                }

                switch (node.Name)
                {
                case "a":
                    return(new GestureDetector(
                               child: DefaultTextStyle.merge(
                                   child: new Wrap(
                                       children: this._parseNodeList(node.ChildNodes)
                                       ),
                                   style: this.linkStyle
                                   ),
                               onTap: () => {
                        if (node.Attributes.Contains("href") && this.onLinkTap != null)
                        {
                            string url = node.Attributes["href"].Value;
                            this.onLinkTap(url);
                        }
                    }));

                case "abbr":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   decoration: TextDecoration.underline,
                                   decorationStyle: TextDecorationStyle.solid
                                   )
                               ));

                case "acronym":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   decoration: TextDecoration.underline,
                                   decorationStyle: TextDecorationStyle.solid
                                   )
                               ));

                case "address":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontStyle: FontStyle.italic
                                   )
                               ));

                case "article":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "aside":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "b":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "bdi":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "bdo":
                    if (node.Attributes["dir"] != null)
                    {
                        return(new Directionality(
                                   child: new Wrap(
                                       children: this._parseNodeList(node.ChildNodes)
                                       ),
                                   textDirection: node.Attributes["dir"].Value == "rtl"
                                    ? TextDirection.rtl
                                    : TextDirection.ltr
                                   ));
                    }

                    //Direction attribute is required, just render the text normally now.
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "big":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontSize: 20.0f
                                   )
                               ));

                case "blockquote":
                    return(new Padding(
                               padding:
                               EdgeInsets.fromLTRB(40.0f, this.blockSpacing, 40.0f, this.blockSpacing),
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   )
                               ));

                case "body":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "br":
                    if (this._isNotFirstBreakTag(node))
                    {
                        return(new Container(width: this.width, height: this.blockSpacing));
                    }

                    return(new Container(width: this.width));

                case "caption":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   alignment: WrapAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "center":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes),
                                   alignment: WrapAlignment.center
                                   )));

                case "cite":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontStyle: FontStyle.italic
                                   )
                               ));

                case "code":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontFamily: "monospace"
                                   )
                               ));

                case "data":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "dd":
                    return(new Padding(
                               padding: EdgeInsets.only(left: 40.0f),
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   )));

                case "del":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   decoration: TextDecoration.lineThrough
                                   )
                               ));

                case "dfn":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontStyle: FontStyle.italic
                                   )
                               ));

                case "div":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "dl":
                    return(new Padding(
                               padding: EdgeInsets.only(top: this.blockSpacing, bottom: this.blockSpacing),
                               child: new Column(
                                   children: this._parseNodeList(node.ChildNodes),
                                   crossAxisAlignment: CrossAxisAlignment.start
                                   )));

                case "dt":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "em":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontStyle: FontStyle.italic
                                   )
                               ));

                case "figcaption":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "figure":
                    return(new Padding(
                               padding:
                               EdgeInsets.fromLTRB(40.0f, this.blockSpacing, 40.0f, this.blockSpacing),
                               child: new Column(
                                   children: this._parseNodeList(node.ChildNodes),
                                   crossAxisAlignment: CrossAxisAlignment.center
                                   )));

                case "font":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "footer":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "h1":
                    return(DefaultTextStyle.merge(
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   ),
                               style: new TextStyle(
                                   fontSize: 28.0f,
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "h2":
                    return(DefaultTextStyle.merge(
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   ),
                               style: new TextStyle(
                                   fontSize: 21.0f,
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "h3":
                    return(DefaultTextStyle.merge(
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   ),
                               style: new TextStyle(
                                   fontSize: 16.0f,
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "h4":
                    return(DefaultTextStyle.merge(
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   ),
                               style: new TextStyle(
                                   fontSize: 14.0f,
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "h5":
                    return(DefaultTextStyle.merge(
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   ),
                               style: new TextStyle(
                                   fontSize: 12.0f,
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "h6":
                    return(DefaultTextStyle.merge(
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   ),
                               style: new TextStyle(
                                   fontSize: 10.0f,
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "header":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "hr":
                    return(new Padding(
                               padding: EdgeInsets.only(top: 7.0f, bottom: 7.0f),
                               child: new Divider(height: 1.0f, color: Colors.black38)
                               ));

                case "i":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontStyle: FontStyle.italic
                                   )
                               ));

                case "img":
                    return(new Builder(
                               builder: (BuildContext context) => {
                        if (this.showImages)
                        {
                            if (node.Attributes["src"] != null)
                            {
                                if (node.Attributes["src"].Value.StartsWith("data:image") &&
                                    node.Attributes["src"].Value.Contains("base64,"))
                                {
                                    return Image.memory(Convert.FromBase64String(
                                                            node.Attributes["src"].Value.Split(new string[] { "base64," },
                                                                                               StringSplitOptions.None)[1].Trim()));
                                }

                                return Image.network(node.Attributes["src"].Value);
                            }
                            else if (node.Attributes["alt"] != null)
                            {
                                //Temp fix for https://github.com/flutter/flutter/issues/736
                                if (node.Attributes["alt"].Value.EndsWith(" "))
                                {
                                    return new Container(
                                        padding: EdgeInsets.only(right: 2.0f),
                                        child: new Text(node.Attributes["alt"].Value));
                                }
                                else
                                {
                                    return new Text(node.Attributes["alt"].Value);
                                }
                            }
                        }

                        return new Container();
                    }
                               ));

                case "ins":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   decoration: TextDecoration.underline
                                   )
                               ));

                case "kbd":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontFamily: "monospace"
                                   )
                               ));

                case "li":
                    string     type        = node.ParentNode.Name; // Parent type; usually ol or ul
                    EdgeInsets markPadding = EdgeInsets.symmetric(horizontal: 4.0f);
                    Widget     mark;
                    switch (type)
                    {
                    case "ul":
                        mark = new Container(child: new Text("•"), padding: markPadding);
                        break;

                    case "ol":
                        int index = node.ParentNode.ChildNodes.IndexOf(node) + 1;
                        mark = new Container(child: new Text($"{index}."), padding: markPadding);
                        break;

                    default:         //Fallback to middle dot
                        mark = new Container(width: 0.0f, height: 0.0f);
                        break;
                    }

                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: new List <Widget> {
                        mark,
                        new Wrap(
                            crossAxisAlignment: WrapCrossAlignment.center,
                            children: this._parseNodeList(node.ChildNodes))
                    }
                                   )
                               ));

                case "main":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "mark":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   color: Colors.black,
                                   background: this._getPaint(Colors.yellow)
                                   )
                               ));

                case "nav":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "noscript":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   alignment: WrapAlignment.start,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "ol":
                    return(new Column(
                               children: this._parseNodeList(node.ChildNodes),
                               crossAxisAlignment: CrossAxisAlignment.start
                               ));

                case "p":
                    return(new Padding(
                               padding: EdgeInsets.only(top: this.blockSpacing, bottom: this.blockSpacing),
                               child: new Container(
                                   width: this.width,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       alignment: WrapAlignment.start,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   )
                               ));

                case "pre":
                    return(new Padding(
                               padding: EdgeInsets.all(this.blockSpacing),
                               child: DefaultTextStyle.merge(
                                   child: new Text(node.InnerHtml),
                                   style: new TextStyle(
                                       fontFamily: "monospace"
                                       )
                                   )
                               ));

                case "q":
                    List <Widget> children = new List <Widget>();
                    children.Add(new Text("\""));
                    children.AddRange(this._parseNodeList(node.ChildNodes));
                    children.Add(new Text("\""));
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: children
                                   ),
                               style: new TextStyle(
                                   fontStyle: FontStyle.italic
                                   )
                               ));

                case "rp":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "rt":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "ruby":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "s":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   decoration: TextDecoration.lineThrough
                                   )
                               ));

                case "samp":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontFamily: "monospace"
                                   )
                               ));

                case "section":
                    return(new Container(
                               width: this.width,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "small":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontSize: 10.0f
                                   )
                               ));

                case "span":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "strike":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   decoration: TextDecoration.lineThrough
                                   )
                               ));

                case "strong":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "sub":
                case "sup":
                    //Use builder to capture the parent font to inherit the font styles
                    return(new Builder(builder: (BuildContext context) => {
                        DefaultTextStyle parent = DefaultTextStyle.of(context);
                        TextStyle parentStyle = parent.style;

                        var painter = new TextPainter(
                            text: new TextSpan(
                                text: node.InnerText,
                                style: parentStyle
                                ),
                            textDirection: TextDirection.ltr);
                        painter.layout();
                        //print(painter.size);

                        //Get the height from the default text
                        var height = painter.size.height *
                                     1.35f;     //compute a higher height for the text to increase the offset of the Positioned text

                        painter = new TextPainter(
                            text: new TextSpan(
                                text: node.InnerText,
                                style: parentStyle.merge(new TextStyle(
                                                             fontSize:
                                                             parentStyle.fontSize * RichTextParserUtils.OFFSET_TAGS_FONT_SIZE_FACTOR))
                                ),
                            textDirection: TextDirection.ltr);
                        painter.layout();
                        //print(painter.size);

                        //Get the width from the reduced/positioned text
                        var width = painter.size.width;

                        //print("Width: $width, Height: $height");

                        return DefaultTextStyle.merge(
                            child: new Wrap(
                                crossAxisAlignment: WrapCrossAlignment.center,
                                children: new List <Widget> {
                            new Stack(
                                fit: StackFit.loose,
                                children: new List <Widget> {
                                //The Stack needs a non-positioned object for the next widget to respect the space so we create
                                //a sized box to fill the required space
                                new SizedBox(
                                    width: width,
                                    height: height
                                    ),
                                DefaultTextStyle.merge(
                                    child: new Positioned(
                                        child: new Wrap(children: this._parseNodeList(node.ChildNodes)),
                                        bottom: node.Name == "sub" ? 0 : (int?)null,
                                        top: node.Name == "sub" ? (int?)null : 0
                                        ),
                                    style: new TextStyle(
                                        fontSize: parentStyle.fontSize *
                                        RichTextParserUtils.OFFSET_TAGS_FONT_SIZE_FACTOR)
                                    )
                            }
                                )
                        }
                                )
                            );
                    }));

                case "table":
                    return(new Column(
                               children: this._parseNodeList(node.ChildNodes),
                               crossAxisAlignment: CrossAxisAlignment.start
                               ));

                case "tbody":
                    return(new Column(
                               children: this._parseNodeList(node.ChildNodes),
                               crossAxisAlignment: CrossAxisAlignment.start
                               ));

                case "td":
                    int colspan = 1;
                    if (node.Attributes["colspan"] != null)
                    {
                        int.TryParse(node.Attributes["colspan"].Value, out colspan);
                    }

                    return(new Expanded(
                               flex: colspan,
                               child: new Wrap(
                                   crossAxisAlignment: WrapCrossAlignment.center,
                                   children: this._parseNodeList(node.ChildNodes)
                                   )
                               ));

                case "template":
                    //Not usually displayed in HTML
                    return(new Container());

                case "tfoot":
                    return(new Column(
                               children: this._parseNodeList(node.ChildNodes),
                               crossAxisAlignment: CrossAxisAlignment.start
                               ));

                case "th":
                    int _colspan = 1;
                    if (node.Attributes["colspan"] != null)
                    {
                        int.TryParse(node.Attributes["colspan"].Value, out _colspan);
                    }

                    return(DefaultTextStyle.merge(
                               child: new Expanded(
                                   flex: _colspan,
                                   child: new Wrap(
                                       crossAxisAlignment: WrapCrossAlignment.center,
                                       alignment: WrapAlignment.center,
                                       children: this._parseNodeList(node.ChildNodes)
                                       )
                                   ),
                               style: new TextStyle(
                                   fontWeight: FontWeight.bold
                                   )
                               ));

                case "thead":
                    return(new Column(
                               children: this._parseNodeList(node.ChildNodes),
                               crossAxisAlignment: CrossAxisAlignment.start
                               ));

                case "time":
                    return(new Wrap(
                               children: this._parseNodeList(node.ChildNodes)
                               ));

                case "tr":
                    return(new Row(
                               children: this._parseNodeList(node.ChildNodes),
                               crossAxisAlignment: CrossAxisAlignment.center
                               ));

                case "tt":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontFamily: "monospace"
                                   )
                               ));

                case "u":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   decoration: TextDecoration.underline
                                   )
                               ));

                case "ul":
                    return(new Column(
                               children: this._parseNodeList(node.ChildNodes),
                               crossAxisAlignment: CrossAxisAlignment.start
                               ));

                case "var":
                    return(DefaultTextStyle.merge(
                               child: new Wrap(
                                   children: this._parseNodeList(node.ChildNodes)
                                   ),
                               style: new TextStyle(
                                   fontStyle: FontStyle.italic
                                   )
                               ));
                }
            }
            else if (node.NodeType is HtmlNodeType.Text)
            {
                //We don't need to worry about rendering extra whitespace
                if (node.InnerText.Trim() == "" && node.InnerText.IndexOf(" ") == -1)
                {
                    return(new Wrap());
                }

                if (node.InnerText.Trim() == "" && node.InnerText.IndexOf(" ") != -1)
                {
                    (node as HtmlTextNode).Text = " ";
                }

                string finalText = this.trimStringHtml(node.InnerText);
                //Temp fix for https://github.com/flutter/flutter/issues/736
                if (finalText.EndsWith(" "))
                {
                    return(new Container(
                               padding: EdgeInsets.only(right: 2.0f), child: new Text(finalText)));
                }
                else
                {
                    return(new Text(finalText));
                }
            }

            return(new Wrap());
        }
Esempio n. 2
0
        public override Widget build(BuildContext context)
        {
            this._context = context;
            if (!this._isShow)
            {
                return(new MainScreen());
            }

            var topPadding = 0f;

            if (Application.platform != RuntimePlatform.Android)
            {
                topPadding = MediaQuery.of(context).padding.top;
            }

            var    isShowLogo = SplashManager.getSplash().isShowLogo;
            Widget logo       = new Container();

            if (isShowLogo)
            {
                logo = new Positioned(
                    top: topPadding + 24,
                    left: 16,
                    child: new Icon(
                        Icons.LogoWithUinty,
                        size: 35,
                        color: new Color(value: this.hexColor)
                        )
                    );
            }

            return(new Container(
                       color: CColors.White,
                       child: new Stack(
                           children: new List <Widget> {
                new Column(
                    children: new List <Widget> {
                    new GestureDetector(
                        child: new Container(
                            width: MediaQuery.of(context).size.width,
                            height: MediaQuery.of(context).size.height,
                            child: Image.memory(SplashManager.readImage(), fit: BoxFit.cover)
                            ),
                        onTap: this.pushPage
                        )
                }
                    ),
                new Positioned(
                    top: topPadding + 24,
                    right: 16,
                    child: new GestureDetector(
                        child: new Container(
                            decoration: new BoxDecoration(
                                Color.fromRGBO(0, 0, 0, 0.5f),
                                borderRadius: BorderRadius.all(16)
                                ),
                            width: 65,
                            height: 32,
                            alignment: Alignment.center,
                            child: new Text($"跳过 {this._lastSecond}", style: new TextStyle(
                                                fontSize: 14,
                                                fontFamily: "PingFangSC-Regular",
                                                color: CColors.White
                                                ))
                            ),
                        onTap: this.pushCallback
                        )
                    ),
                logo
            }
                           )
                       ));
        }
Esempio n. 3
0
        public override Widget build(BuildContext context)
        {
            if (this.data.isNullOrEmpty() || this.favoriteTagDict.isNullOrEmpty())
            {
                return(new Container());
            }

            var collectionId = this.data[0];
            var rankData     = this.rankDict.ContainsKey(key: collectionId)
                ? this.rankDict[key : collectionId]
                               : new RankData();
            var favoriteTagArticle = this.favoriteTagArticleDict.ContainsKey(key: rankData.itemId)
                ? this.favoriteTagArticleDict[key : rankData.itemId]
                                     : new FavoriteTagArticle();
            var favoriteTag = this.favoriteTagDict.ContainsKey(key: rankData.itemId)
                ? this.favoriteTagDict[key : rankData.itemId]
                              : new FavoriteTag();
            var title  = rankData.resetTitle.isNotEmpty() ? rankData.resetTitle : favoriteTag.name;
            var images = new List <string>();

            favoriteTagArticle.list.ForEach(article => { images.Add(item: article.thumbnail.url); });
            return(new Container(
                       color: CColors.White,
                       height: 184,
                       child: new Stack(
                           fit: StackFit.expand,
                           children: new List <Widget> {
                Image.asset(
                    "image/recommend-blogger-bg",
                    fit: BoxFit.fill
                    ),
                new Column(
                    children: new List <Widget> {
                    new MoreListTile(
                        "image/leader-board",
                        "推荐榜单",
                        EdgeInsets.only(16, 16),
                        onPress: this.onPressMore
                        ),
                    new GestureDetector(
                        onTap: () => this.onPressItem?.Invoke(text: rankData.id),
                        child: new Container(
                            color: CColors.Transparent,
                            padding: EdgeInsets.all(16),
                            child: new Stack(
                                children: new List <Widget> {
                        new Column(
                            children: new List <Widget> {
                            new Container(height: 8),
                            new Container(
                                height: 104,
                                decoration: new BoxDecoration(
                                    new Color(0xFF3B516A),
                                    borderRadius: BorderRadius.all(6)
                                    )
                                )
                        }
                            ),
                        new Positioned(
                            right: 16,
                            bottom: 8,
                            child: new Text(
                                "UNITY",
                                style: new TextStyle(
                                    fontSize: 40,
                                    fontFamily: "Roboto-Bold",
                                    color: new Color(0xFF4F6378)
                                    )
                                )
                            ),
                        Positioned.fill(
                            new Row(
                                children: new List <Widget> {
                            new Padding(
                                padding: EdgeInsets.only(16, right: 16, bottom: 16),
                                child: new CoverImages(
                                    images: images,
                                    80,
                                    0,
                                    8,
                                    8,
                                    true
                                    )
                                ),
                            new Expanded(
                                child: new Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: new List <Widget> {
                                new Container(height: 20),
                                new Text(
                                    data: title,
                                    maxLines: 2,
                                    overflow: TextOverflow.ellipsis,
                                    style: new TextStyle(
                                        height: 1.27f,
                                        fontSize: 20,
                                        fontFamily: "Roboto-Medium",
                                        color: CColors.White
                                        )
                                    ),
                                new Container(height: 4),
                                new Text(
                                    $"文章 {favoriteTag.stasitics.count}",
                                    style: new TextStyle(
                                        height: 1.53f,
                                        fontSize: 12,
                                        fontFamily: "Roboto-Regular",
                                        color: new Color(0xFFCCCCCC)
                                        )
                                    )
                            }
                                    )
                                ),
                            new SizedBox(width: 16)
                        }
                                )
                            )
                    }
                                )
                            )
                        )
                }
                    )
            }
                           )
                       ));
        }
Esempio n. 4
0
        public override Widget build(BuildContext context)
        {
            if (!_everBuild)
            {
                _everBuild = true;
                widget.OnBuild?.Invoke();
            }

            var sendByMe = widget.Msg.author.id == Window.currentUserId;

            Widget content        = null;
            var    mediaQueryData = MediaQuery.of(context);
            var    maxWidth       = mediaQueryData.size.width * 0.7f;

            if (mediaQueryData.size.width > 750)
            {
                maxWidth -= 262.5f;
            }

            if (!string.IsNullOrEmpty(widget.Msg.deletedTime))
            {
                content = new Container(
                    padding: EdgeInsets.all(12),
                    constraints: new BoxConstraints(
                        maxWidth: maxWidth
                        ),
                    decoration: new BoxDecoration(
                        color: sendByMe ? new Color(0xffc5e8ff) : new Color(0xfff0f0f0),
                        borderRadius: BorderRadius.circular(10)
                        ),
                    child: new SelectableText(
                        textSpan: new TextSpan(
                            text: "此条消息已被删除",
                            style: DeletedTextStyle
                            ),
                        focusNode: _focusNode,
                        selectionColor: new Color(0xffd8d8d8)
                        )
                    );
            }
            else if (widget.Msg.content != null && widget.Msg.content.isNotEmpty())
            {
                var contentChildren = new List <Widget>
                {
                    new SelectableText(
                        textSpan: ParseMessage(
                            widget.Msg.content ?? "",
                            widget.Users,
                            textStyle: widget.Msg.id == null ? SendingTextStyle : null,
                            defaultOnTapUp: OnTapUp
                            ),
                        focusNode: _focusNode,
                        selectionColor: new Color(0xffd8d8d8),
                        onTapUp: OnTapUp
                        ),
                };
                if (!widget.Msg.embeds.isEmpty())
                {
                    contentChildren.Add(new Container(height: 6));
                    contentChildren.Add(new MessageEmbed(
                                            message: widget.Msg,
                                            onClickUrl: (details, url) =>
                    {
                        OnTapUp(details);
                        if (details.kind == PointerDeviceKind.mouse &&
                            details.device == InputUtils.MouseLeftKeyDevice)
                        {
                            Launch(url);
                        }
                    }));
                }

                content = new GestureDetector(
                    onTapUp: OnTapUp,
                    child: new Container(
                        padding: EdgeInsets.all(12),
                        constraints: new BoxConstraints(
                            maxWidth: maxWidth
                            ),
                        decoration: new BoxDecoration(
                            color: sendByMe ? new Color(0xffc5e8ff) : new Color(0xfff0f0f0),
                            borderRadius: BorderRadius.circular(10)
                            ),
                        child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: contentChildren
                            )
                        )
                    );
            }
            else if (widget.Msg.attachments.Count > 0)
            {
                var attachment  = widget.Msg.attachments.first();
                var contentType = attachment.contentType;
                if (contentType == "image/png" ||
                    contentType == "image/jpg" ||
                    contentType == "image/jpeg" ||
                    contentType == "image/gif")
                {
                    Widget image = null;
                    if (attachment.local)
                    {
                        image = new ImageWithProgress(
                            image: new FileImage(
                                attachment.url
                                ),
                            attachment.progress
                            );
                    }
                    else
                    {
                        image = new Image(
                            image: ProxiedImage(
                                $"{attachment.url}.200x0x1.jpg",
                                cookie: $"LS={Window.loginSession};"
                                ),
                            fit: BoxFit.cover
                            );
                    }

                    content = new GestureDetector(
                        onTapUp: OnTapUp,
                        child: new Container(
                            constraints: new BoxConstraints(
                                maxWidth: 282
                                ),
                            child: new ClipRRect(
                                borderRadius: BorderRadius.circular(5),
                                child: new AspectRatio(
                                    aspectRatio: attachment.width == 0 || attachment.height == 0
                                        ? 1
                                        : (float)attachment.width / attachment.height,
                                    child: image
                                    )
                                )
                            )
                        );
                }
                else
                {
                    AssetImage image;
                    if (contentType == "application/pdf")
                    {
                        image = new AssetImage("Images/FilePdf@4x");
                    }
                    else if (contentType.StartsWith("video/"))
                    {
                        image = new AssetImage("Images/FileVideo@4x");
                    }
                    else
                    {
                        image = new AssetImage("Images/FileGeneral@4x");
                    }

                    content = new GestureDetector(
                        onTapUp: OnTapUp,
                        child: new Container(
                            padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
                            decoration: new BoxDecoration(
                                color: new Color(0xfff0f0f0),
                                borderRadius: BorderRadius.all(10)
                                ),
                            width: 262,
                            child: new Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: new List <Widget>
                    {
                        new Expanded(
                            child: new Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: new List <Widget>
                        {
                            new Text(
                                attachment.filename,
                                style: new TextStyle(
                                    fontSize: 16,
                                    color: new Color(0xff000000),
                                    fontFamily: "PingFang"
                                    )
                                ),
                            new Container(
                                margin: EdgeInsets.only(top: 4),
                                child: new Text(
                                    ReadableSize(attachment.size),
                                    style: new TextStyle(
                                        fontSize: 12,
                                        color: new Color(0xff797979),
                                        fontFamily: "PingFang"
                                        )
                                    )
                                )
                        }
                                )
                            ),
                        new Container(
                            margin: EdgeInsets.only(left: 16),
                            width: 42,
                            height: 48,
                            child: new Image(
                                image: image,
                                width: 42,
                                height: 48,
                                fit: BoxFit.cover
                                )
                            )
                    }
                                )
                            )
                        );
                }
            }
            else
            {
                return(new Container(height: 0, width: 0));
            }

            var decoratedContent = new List <Widget>
            {
                content,
            };

            if (_rightClickFocus.hasFocus)
            {
                decoratedContent.Add(
                    new Positioned(
                        top: 0,
                        right: 0,
                        bottom: 0,
                        left: 0,
                        child: new Container(
                            decoration: new BoxDecoration(
                                borderRadius: BorderRadius.all(10),
                                color: new Color(0x1a000000)
                                )
                            )
                        )
                    );
            }

            if (_fetchingUrl)
            {
                decoratedContent.Add(
                    new Positioned(
                        top: 0,
                        right: 0,
                        bottom: 0,
                        left: 0,
                        child: new Container(
                            decoration: new BoxDecoration(
                                borderRadius: BorderRadius.all(10),
                                color: new Color(0x1a000000)
                                ),
                            alignment: Alignment.center,
                            child: new Loading(
                                size: 24,
                                isWhite: true
                                )
                            )
                        )
                    );
            }

            var children = new List <Widget>
            {
                new Container(
                    margin: EdgeInsets.only(
                        left: sendByMe ? 10 : 24,
                        right: sendByMe ? 24 : 10
                        ),
                    child: new Avatar(
                        widget.Msg.author,
                        size: 40
                        )
                    ),
                new Expanded(
                    child: new Column(
                        crossAxisAlignment: sendByMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: new List <Widget>
                {
                    new Container(
                        height: 20,
                        alignment: sendByMe?Alignment.centerRight: Alignment.centerLeft,
                        margin: EdgeInsets.only(bottom: 6),
                        child: new Text(
                            widget.Msg.author.fullName,
                            style: new TextStyle(
                                fontSize: 12,
                                fontWeight: FontWeight.w500,
                                color: new Color(0xff797979),
                                fontFamily: "PingFang"
                                )
                            )
                        ),
                    new Stack(
                        children: decoratedContent
                        ),
                }
                        )
                    ),
            };

            if (sendByMe)
            {
                children.Reverse();
            }

            Widget result = new Container(
                margin: EdgeInsets.symmetric(vertical: 8),
                child: new Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: children
                    )
                );

            var resultChildren = new List <Widget> {
            };

            if (widget.IsNew)
            {
                resultChildren.Add(
                    new Container(
                        height: 36,
                        alignment: Alignment.center,
                        child: new Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: new List <Widget>
                {
                    new Expanded(
                        child: new Container(
                            margin: EdgeInsets.only(right: 8),
                            height: 1,
                            color: new Color(0xffd8d8d8)
                            )
                        ),
                    new Container(
                        alignment: Alignment.center,
                        child: new Text(
                            "以下为新消息",
                            style: new TextStyle(
                                fontSize: 12,
                                fontWeight: FontWeight.w500,
                                color: new Color(0xff959595),
                                fontFamily: "PingFang"
                                )
                            )
                        ),
                    new Expanded(
                        child: new Container(
                            margin: EdgeInsets.only(left: 8),
                            height: 1,
                            color: new Color(0xffd8d8d8)
                            )
                        ),
                }
                            )
                        )
                    );
            }

            if (widget.ShowTime)
            {
                resultChildren.Add(
                    new Container(
                        height: 36,
                        child: new Center(
                            child: new Text(
                                DateTimeString(widget.CreateTime),
                                style: new TextStyle(
                                    fontSize: 12,
                                    fontWeight: FontWeight.w500,
                                    color: new Color(0xff797979),
                                    fontFamily: "PingFang"
                                    )
                                )
                            )
                        )
                    );
            }

            resultChildren.Add(result);

            return(new Column(
                       children: resultChildren
                       ));
        }
Esempio n. 5
0
        public override Widget build(BuildContext context)
        {
            if (this.bloggerIds.isNullOrEmpty())
            {
                return(new Container());
            }

            var children = new List <Widget> {
                new SizedBox(width: 10)
            };

            if (this.bloggerIds.Count <= 3)
            {
                for (int i = 0; i < this.bloggerIds.Count; i++)
                {
                    var bloggerId = this.bloggerIds[i];
                    var rankData  = this.rankDict.ContainsKey(key: bloggerId)
                        ? this.rankDict[key : bloggerId]
                                    : new RankData();
                    if (this.userDict.ContainsKey(key: rankData.itemId))
                    {
                        var user = this.userDict[key : rankData.itemId];
                        if (i == this.bloggerIds.Count - 1)
                        {
                            children.Add(new Container(
                                             padding: EdgeInsets.only(right: 10),
                                             child: this._buildBlogger(user: user, resetTitle: rankData.resetTitle)
                                             ));
                        }
                        else
                        {
                            children.Add(this._buildBlogger(user: user, resetTitle: rankData.resetTitle));
                        }
                    }
                }
            }
            else
            {
                var _showBloggerCount = 3;
                for (int index = 0; index < _showBloggerCount; index++)
                {
                    var bloggerId = this.bloggerIds[index : index];
                    var rankData  = this.rankDict.ContainsKey(key: bloggerId)
                        ? this.rankDict[key : bloggerId]
                                    : new RankData();
                    if (this.userDict.ContainsKey(key: rankData.itemId))
                    {
                        var user = this.userDict[key : rankData.itemId];
                        children.Add(this._buildBlogger(user: user, resetTitle: rankData.resetTitle));
                    }
                }

                children.Add(new Container(
                                 padding: EdgeInsets.only(right: 10),
                                 child: this._buildMoreBlogger(
                                     this.bloggerIds.GetRange(
                                         _showBloggerCount,
                                         this.bloggerIds.Count - _showBloggerCount > 3
                            ? 3
                            : this.bloggerIds.Count - _showBloggerCount
                                         )
                                     )
                                 ));
            }

            return(new Container(
                       color: CColors.White,
                       height: 302,
                       child: new Stack(
                           fit: StackFit.expand,
                           children: new List <Widget> {
                Image.asset(
                    "image/recommend-blogger-bg",
                    fit: BoxFit.fill
                    ),
                new Column(
                    children: new List <Widget> {
                    new MoreListTile(
                        "image/blogger",
                        "推荐博主",
                        EdgeInsets.only(16, 16, bottom: 16),
                        onPress: this.onPressBloggerMore
                        ),
                    new Container(
                        height: 230,
                        child: new ListView(
                            scrollDirection: Axis.horizontal,
                            children: children
                            )
                        )
                }
                    )
            }
                           )
                       ));
        }
Esempio n. 6
0
        Widget _buildBlogger(User user, string resetTitle)
        {
            UserType userType = UserType.unFollow;

            if (!this.isLoggedIn)
            {
                userType = UserType.unFollow;
            }
            else
            {
                if (UserInfoManager.getUserInfo().userId == user.id)
                {
                    userType = UserType.me;
                }
                else if (user.followUserLoading ?? false)
                {
                    userType = UserType.loading;
                }
                else if (this.followMap.ContainsKey(key: user.id))
                {
                    userType = UserType.follow;
                }
            }

            return(new GestureDetector(
                       onTap: () => this.onPressItem?.Invoke(text: user.id),
                       child: new Container(
                           width: 160,
                           margin: EdgeInsets.all(6),
                           decoration: new BoxDecoration(
                               color: CColors.White,
                               borderRadius: BorderRadius.all(6),
                               boxShadow: new List <BoxShadow> {
                new BoxShadow(
                    CColors.Black.withOpacity(0.08f),
                    blurRadius: 10,
                    spreadRadius: 1.0f
                    )
            }
                               ),
                           child: new ClipRRect(
                               borderRadius: BorderRadius.all(6),
                               child: new Column(
                                   children: new List <Widget> {
                new Container(
                    height: 88,
                    color: CColorUtils.GetSpecificDarkColorFromId(id: user.id),
                    child: new Stack(
                        fit: StackFit.expand,
                        children: new List <Widget> {
                    user.coverImage.isNotEmpty()
                                                ? Image.network(user.coverImage, fit: BoxFit.fill)
                                                : Image.asset(
                        "image/blogger-avatar-pattern",
                        fit: BoxFit.fill
                        ),
                    Positioned.fill(
                        new Center(
                            child: Avatar.User(user: user, 64, true)
                            )
                        )
                }
                        )
                    ),
                new Padding(
                    padding: EdgeInsets.only(16, 16, 16, 4),
                    child: new Text(data: user.fullName, style: CTextStyle.PXLargeMedium, maxLines: 1)
                    ),
                new Text(
                    $"粉丝{user.followCount ?? 0} • 文章{user.articleCount ?? 0}",
                    style: CTextStyle.PSmallBody4
                    ),
                new Text(resetTitle ?? "", style: CTextStyle.PSmallBody4),
                new Padding(
                    padding: EdgeInsets.only(top: 12),
                    child: new FollowButton(
                        userType: userType,
                        () => this._onFollow(userType: userType, userId: user.id)
                        )
                    )
            }
                                   )
                               )
                           )
                       ));
        }
Esempio n. 7
0
        public override Widget build(BuildContext context)
        {
            return(new Scaffold(
                       body: new ListView(
                           padding: EdgeInsets.symmetric(5, 15),
                           children: new List <Widget> {
                new Text("UIWidgets源码系列: Hello World", style: titleStyle, textAlign: TextAlign.center),
                new Text("什么是UIWidgets", style: h1Style),
                new Text(@"UIWidgets是Unity上的一个UI解决方案。UIWidgets是将目前流行的跨平台移动开发框架flutter (https://github.com/flutter/flutter) 在Unity上的移植。UIWidgets有如下优势:

1. 借助于flutter的强大UI能力,UIWidgets使得Unity游戏开发者能够在Unity游戏中嵌入复杂性和移动APP比肩的游戏UI,甚至于脱离游戏,完全由UI界面组成的应用。
2. Unity强大的3D渲染引擎可以让开发者直接用来在应用中嵌入复杂的3D场景。
3. 借助于Unity自身的跨平台特性,UIWidgets使开发者可以使用Unity直接编写出跨Windows、Linux、MacOS、WebGL和移动端应用。

UIWidgets的使用也很简单,不依赖任何第三方库,支持2018.3及以上的Unity版本。将源码clone到工程目录中的Packages文件夹下就可以开始使用了。此外UIWidgets已在Package Manager(国内镜像)和Asset Store上发布。不过推荐在github上clone源码,以保证获取到最新的代码。

本文假设您已经了解Unity的基本操作(新建工程、在场景中创建各种GameObject等)。如果没有,这些技能学习起来也非常简单。您可以访问Unity Learn (https://learn.unity.com) 查看官方的免费教程。", style: bodyStyle),
                new Text("使用UIWidgets做一个简单的APP", style: h1Style),
                new Text(@"1. 打开2018.3或更高版本的Unity,新建工程

2. 获取UIWidgets:
    i. 使用git(命令行或GUI版本)将 https://github.com/UnityTech/UIWidgets.git clone到工程目录的Packages文件夹下
    ii. 打开Window > Packages Manager,点击搜索框左边的""Advanced"",确保""Show preview packages""为被选中状态。随后,在列表中找到UIWidgets,然后点击右下角的""Install""
    iii. 打开Asset Store,搜索UIWidgets,下载并导入工程中。具体步骤和在Asset Store下载其他资源类似,在此不细讲。
    
3. 在工程目录中的Assets目录下新建脚本,命名为UIWidgetsExample.cs。将以下内容粘贴进去:", style: bodyStyle),
                new Container(
                    decoration: new BoxDecoration(
                        border: Border.all(color: codeBorderColor),
                        color: codeBackgroundColor
                        ),
                    padding: EdgeInsets.all(10),
                    margin: EdgeInsets.symmetric(10, 5),
                    child: new Text(@"using System.Collections.Generic;
using Unity.UIWidgets.animation
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.widgets;

namespace UIWidgetsSample {
    public class UIWidgetsExample : UIWidgetsPanel {
        protected override Widget createWidget() {
            return new ExampleApp();
        }

        class ExampleApp : StatefulWidget {
            public ExampleApp(Key key = null) : base(key) {
            }

            public override State createState() {
                return new ExampleState();
            }
        }

        class ExampleState : State<ExampleApp> {
            int counter = 0;

            public override Widget build(BuildContext context) {
                return new Column(
                    children: new List<Widget> {
                        new Text(""Counter: "" + this.counter),
                        new GestureDetector(
                            onTap: () => {
                                this.setState(() => {
                                this.counter++;
                            });
                        },
                        child: new Container(
                                padding: EdgeInsets.all(20),
                                color: Colors.blue,
                                child: new Text(""Click Me"")
                            )
                        )
                    }
                );
            }
        }
    }
}", style: codeStyle)
                    ),
                new Text(@"4. 在场景中新建一个Canvas:在Hierachy窗口中右键 -> UI -> Canvas。点击Scene窗口左上角的2D按钮打开2D视角。

5. 将UIWidgetsExample脚本添加到Canvas上:从Project中将脚本拖到场景中的Canvas上,或点击Canvas,在Inspector窗口中点击“Add Component”,在搜索框中输入“UI Widgets Example”,点击搜索到的选项。

这个简单的UIWidgets应用效果如下。", style: bodyStyle),
                Image.asset("Images/UIWidgetsHelloWorld",
                            fit: BoxFit.contain,
                            height: 300),
                new Text(@"点击“Click Me”按钮,可以看到Counter后面的数字增加。

如果你觉得上述例子过于简单,可以打开场景“Samples/UIWidgetSample/UIWidgetsGallery/gallery.scene”看一下目前UIWidgets能够做出的界面。这个demo应用展示了UIWidgets中的常用组件。
", style: bodyStyle),

                new Text(@"关于目前已有的成熟的UIWidgets做的产品,可以参考https://github.com/liangxiegame/awesome-uiwidgets提供的列表。", style: bodyStyle),
                new ComputeBufferMovieClip(),
            }
                           )
                       ));
        }
Esempio n. 8
0
        public static void checkForUpdates(CheckVersionType type)
        {
            if (type == CheckVersionType.setting)
            {
                CustomDialogUtils.showCustomDialog(
                    child: new CustomLoadingDialog(message: "正在检查更新")
                    );
            }

            SettingApi.CheckNewVersion(platform: Config.platform, store: Config.store, $"{Config.versionCode}")
            .Then(versionResponse => {
                if (type == CheckVersionType.setting)
                {
                    CustomDialogUtils.hiddenCustomDialog();
                }

                var status = versionResponse.status;
                if (status == "NEED_UPDATE" && versionResponse.url.isNotEmpty())
                {
                    if (type == CheckVersionType.initialize && !needNoticeNewVersion() || needForceUpdate())
                    {
                        return;
                    }
                    markUpdateNoticeTime();
                    CustomDialogUtils.showCustomDialog(
                        barrierColor: Color.fromRGBO(0, 0, 0, 0.5f),
                        child: new CustomAlertDialog(
                            null,
                            message: versionResponse.changeLog,
                            new List <Widget> {
                        new CustomButton(
                            child: new Center(
                                child: new Text(
                                    "稍后再说",
                                    style: CTextStyle.PLargeBody5.defaultHeight(),
                                    textAlign: TextAlign.center
                                    )
                                ),
                            onPressed: CustomDialogUtils.hiddenCustomDialog
                            ),
                        new CustomButton(
                            child: new Center(
                                child: new Text(
                                    "立即更新",
                                    style: CTextStyle.PLargeBlue.defaultHeight(),
                                    textAlign: TextAlign.center
                                    )
                                ),
                            onPressed: () => {
                            CustomDialogUtils.hiddenCustomDialog();
                            Application.OpenURL(url: versionResponse.url);
                        }
                            )
                    },
                            new Stack(
                                children: new List <Widget> {
                        Image.asset("image/updaterBg"),
                        new Align(
                            alignment: Alignment.bottomCenter,
                            child: new Container(height: 1, color: CColors.White)
                            )
                    }
                                )
                            )
                        );
                }
                else
                {
                    if (type == CheckVersionType.setting)
                    {
                        var customSnackBar = new CustomSnackBar(
                            "当前是最新版本",
                            color: CColors.TextBody
                            );
                        customSnackBar.show();
                    }
                }
            })
            .Catch(error => {
                if (type == CheckVersionType.setting)
                {
                    CustomDialogUtils.hiddenCustomDialog();
                }
            });
        }
Esempio n. 9
0
 public override Widget build(BuildContext context)
 {
     return(Image.asset("image/egg-gamepad"));
 }
        static Widget _Atomic(BuildContext context, string type, string contentType, string title, string dataUrl,
                              _OriginalImage originalImage, string videoStatus, string videoPoster,
                              string url, string downloadUrl, string attachmentId, Action <string> openUrl,
                              Action <string, bool, int> playVideo, Action loginAction, bool needUpdate, int limitSeconds,
                              Action <string> browserImage = null)
        {
            if (type == "ATTACHMENT" && contentType != "video/mp4")
            {
                return(new Container());
            }

            var playButton = Positioned.fill(
                new Container()
                );

            if (type == "VIDEO" || type == "ATTACHMENT")
            {
                playButton = Positioned.fill(
                    new Center(
                        child: videoStatus == "completed"
                            ? UserInfoManager.isLogin()
                                ? new CustomButton(
                            onPressed: () => {
                    if (type == "ATTACHMENT")
                    {
                        if (url.isEmpty())
                        {
                            playVideo(downloadUrl, false, 0);
                        }
                        else
                        {
                            playVideo($"{Config.apiAddress_cn}/playlist/{attachmentId}", needUpdate,
                                      limitSeconds);
                        }
                    }
                    else
                    {
                        if (url == null || url.Length <= 0)
                        {
                            return;
                        }

                        openUrl(url);
                    }
                },
                            child: new Container(
                                width: 60,
                                height: 60,
                                decoration: new BoxDecoration(
                                    CColors.H5White,
                                    borderRadius: BorderRadius.all(30)
                                    ),
                                child: new Icon(
                                    Icons.play_arrow,
                                    size: 45,
                                    color: CColors.Icon
                                    )
                                )
                            )
                                : (Widget) new GestureDetector(
                            onTap: () => { loginAction(); },
                            child: new Container(
                                color: CColors.Black.withOpacity(0.5f),
                                alignment: Alignment.center,
                                child: new Text("Login to view this video",
                                                style: CTextStyle.PXLargeWhite.merge(
                                                    new TextStyle(decoration: TextDecoration.underline)))
                                ))
                            : new Container(
                            color: CColors.Black.withOpacity(0.5f),
                            alignment: Alignment.center,
                            child: new Text("Video is processing, try it later", style: CTextStyle.PXLargeWhite)
                            )
                        )
                    );
            }

            var attachWidth  = MediaQuery.of(context).size.width - 32;
            var attachHeight = attachWidth * 9 / 16;

            if (type == "ATTACHMENT")
            {
                return(new Container(
                           color: CColors.White,
                           padding: EdgeInsets.only(bottom: 32),
                           alignment: Alignment.center,
                           child: new Container(
                               padding: EdgeInsets.only(16, right: 16),
                               child: new Column(
                                   children: new List <Widget> {
                    new Stack(
                        children: new List <Widget> {
                        new Container(
                            width: attachWidth,
                            height: attachHeight,
                            color: CColors.Black,
                            child: Image.network(
                                videoPoster,
                                fit: BoxFit.cover
                                )
                            ),
                        playButton
                    }
                        )
                }
                                   )
                               )
                           ));
            }

            var width = originalImage.width < MediaQuery.of(context).size.width - 32
                ? originalImage.width
                : MediaQuery.of(context).size.width - 32;
            var height   = width * originalImage.height / originalImage.width;
            var imageUrl = originalImage.url;

            if (imageUrl.isNotEmpty())
            {
                imageUrl = imageUrl.EndsWith(".gif") || imageUrl.EndsWith(".png")
                    ? imageUrl
                    : CImageUtils.SuitableSizeImageUrl(MediaQuery.of(context).size.width, imageUrl);
                imageUrls.Add(imageUrl);
            }

            var nodes = new List <Widget> {
                new Stack(
                    children: new List <Widget> {
                    new GestureDetector(
                        child: new Hero(
                            tag: imageUrl,
                            child: new PlaceholderImage(
                                imageUrl: imageUrl,
                                width: width,
                                height: height,
                                fit: BoxFit.cover,
                                useCachedNetworkImage: true
                                )
                            ), onTap: () => {
                        if (dataUrl.isNotEmpty())
                        {
                            openUrl(obj: dataUrl);
                        }
                        else
                        {
                            browserImage?.Invoke(imageUrl);
                        }
                    }
                        ),
                    playButton
                }
                    )
            };

            if (title != null)
            {
                var imageTitle = new Container(
                    decoration: new BoxDecoration(
                        border: new Border(
                            bottom: new BorderSide(
                                CColors.Separator,
                                2
                                )
                            )
                        ),
                    child: new Container(
                        margin: EdgeInsets.only(4, 8, 4, 4),
                        child: new Text(
                            title,
                            style: CTextStyle.PRegularBody4
                            )
                        )
                    );
                nodes.Add(imageTitle);
            }

            return(new Container(
                       color: CColors.White,
                       padding: EdgeInsets.only(bottom: 32),
                       alignment: Alignment.center,
                       child: new Container(
                           padding: EdgeInsets.only(16, right: 16),
                           child: new Column(
                               children: nodes
                               )
                           )
                       ));
        }
Esempio n. 11
0
        public override Widget build(BuildContext context)
        {
            ThemeData localTheme = Theme.of(context);

            return(new Padding(
                       padding: EdgeInsets.only(bottom: 16.0f),
                       child: new Row(
                           key: new ValueKey <int>(product.id),
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: new List <Widget> {
                new SizedBox(
                    width: shopping_cartUtils._leftColumnWidth,
                    child: new IconButton(
                        icon: new Icon(Icons.remove_circle_outline),
                        onPressed: onPressed
                        )
                    ),
                new Expanded(
                    child: new Padding(
                        padding: EdgeInsets.only(right: 16.0f),
                        child: new Column(
                            children: new List <Widget> {
                    new Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: new List <Widget> {
                        Image.file(
                            product.assetName,
                            //package: product.assetPackage,
                            fit: BoxFit.cover,
                            width: 75.0f,
                            height: 75.0f
                            ),
                        new SizedBox(width: 16.0f),
                        new Expanded(
                            child: new Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: new List <Widget> {
                            new Row(
                                children: new List <Widget> {
                                new Expanded(
                                    child: new Text($"Quantity: {quantity}")
                                    ),
                                new Text($"x  $ {product.price :F} ")
                            }
                                ),
                            new Text(
                                product.name,
                                style: localTheme.textTheme.subtitle1.copyWith(fontWeight: FontWeight.w600)
                                )
                        }
                                )
                            )
                    }
                        ),
                    new SizedBox(height: 16.0f),
                    new Divider(
                        color: shrineColorsUtils.kShrineBrown900,
                        height: 10.0f
                        )
                }
                            )
                        )
                    )
            }
                           )
                       ));
        }
Esempio n. 12
0
        public ImageFileFormSetField(
            string title = null,
            string lead  = "",
            FormFieldSetter <List <string> > onSaved = null,
            List <string> initialValue = null,
            bool autovalidate          = false,
            bool enabled = true
            ) : base(
                onSaved: onSaved,
                initialValue: initialValue,
                autovalidate: autovalidate,
                enabled: enabled,
                builder: state =>
        {
            var list = new List <Widget> {
                new Card(
                    child: new Container(
                        width: 64f,
                        height: 64f,
                        child: new ConstrainedBox(
                            constraints: BoxConstraints.expand(),
                            child: new FlatButton(
                                onPressed: () => {
                    var ret = DataUploader.OpenFile(
                        lead,
                        "",
                        "png, jpg"
                        );

                    if (state.value == null)
                    {
                        state.didChange(new List <string> { ret });
                    }
                    else
                    {
                        state.value.Add(ret);
                        state.didChange(state.value);
                    }
                },
                                padding: EdgeInsets.all(0f),
                                child: new Icon(Icons.add)
                                )
                            )
                        )
                    )
            };
            if (state.value != null)
            {
                list.AddRange(
                    state
                    .value
                    .Select((path, i) => new Card(
                                child: new Container(
                                    width: 64f,
                                    height: 64f,
                                    child: new ConstrainedBox(
                                        constraints: BoxConstraints.expand(),
                                        child: new FlatButton(
                                            onPressed: () => {
                    var ret = DataUploader.OpenFile(
                        lead,
                        "",
                        "png, jpg"
                        );
                    state.value[i] = ret;
                    state.didChange(state.value);
                },
                                            padding: EdgeInsets.all(0f),
                                            child: Image.file(path)
                                            )
                                        )
                                    )
                                )
                            )
                    );
            }

            return(new Column(
                       crossAxisAlignment: CrossAxisAlignment.start,
                       mainAxisSize: MainAxisSize.max,
                       children: new List <Widget> {
                new Container(
                    margin: EdgeInsets.only(top: 8f),
                    height: string.IsNullOrEmpty(title) ? new float?(0f) : null,
                    width: float.MaxValue,
                    child: string.IsNullOrEmpty(title) ? null : new Text(title)
                    ),
                new Container(
                    height: 72f,
                    child: new ListView(
                        scrollDirection: Axis.horizontal,
                        children: list
                        )
                    )
            }
                       ));
        },
                validator: value => {
            return(null);
        }
                ) {}
Esempio n. 13
0
 public ImageFileFormField(
     string title = null,
     string lead  = "",
     FormFieldSetter <string> onSaved = null,
     string initialValue = "",
     bool autovalidate   = false,
     bool enabled        = true
     ) : base(
         onSaved: onSaved,
         initialValue: initialValue,
         autovalidate: autovalidate,
         enabled: enabled,
         builder: state => new Column(
             crossAxisAlignment: CrossAxisAlignment.start,
             mainAxisSize: MainAxisSize.max,
             children: new List <Widget> {
     new Container(
         margin: EdgeInsets.only(top: 8f),
         height: string.IsNullOrEmpty(title) ? new float?(0f) : null,
         child: string.IsNullOrEmpty(title) ? null : new Text(title)
         ),
     new Card(
         child: new Container(
             width: 128,
             height: 128,
             child: new ConstrainedBox(
                 constraints: BoxConstraints.expand(),
                 child: new FlatButton(
                     onPressed: () => {
         var ret = DataUploader.OpenFile(
             lead,
             "",
             "png, jpg"
             );
         state.didChange(ret);
     },
                     padding: EdgeInsets.all(0f),
                     child: string.IsNullOrEmpty(state.value) ?
                     (Widget)(new Icon(Icons.add)) :
                     (Widget)Image.file(state.value)
                     )
                 )
             )
         ),
     new Container(
         height: string.IsNullOrEmpty(state.errorText) ? new float?(0f) : null,
         padding: EdgeInsets.only(top: 4f),
         child: new Text(
             state.errorText ?? "",
             style: new TextStyle(
                 color: Theme.of(state.context).errorColor
                 )
             )
         )
 }
             ),
         validator: value => {
     if (string.IsNullOrEmpty(value))
     {
         return("Please select an image.");
     }
     return(null);
 }
         ) {}
Esempio n. 14
0
        public override Widget build(BuildContext context)
        {
            ThemeData theme            = Theme.of(context);
            TextStyle titleStyle       = theme.textTheme.headline.copyWith(color: Colors.white);
            TextStyle descriptionStyle = theme.textTheme.subhead;

            return(new SafeArea(
                       top: false,
                       bottom: false,
                       child: new Container(
                           padding: EdgeInsets.all(8.0f),
                           height: height,
                           child: new Card(
                               shape: this.shape,
                               child: new Column(
                                   crossAxisAlignment: CrossAxisAlignment.start,
                                   children: new List <Widget> {
                new SizedBox(
                    height: 184.0f,
                    child: new Stack(
                        children: new List <Widget> {
                    Positioned.fill(
                        child: Image.asset(this.destination.assetName,
                                           fit: BoxFit.cover
                                           )
                        ),
                    new Positioned(
                        bottom: 16.0f,
                        left: 16.0f,
                        right: 16.0f,
                        child: new FittedBox(
                            fit: BoxFit.scaleDown,
                            alignment: Alignment.centerLeft,
                            child: new Text(this.destination.title,
                                            style: titleStyle
                                            )
                            )
                        )
                }
                        )
                    ),
                new Expanded(
                    child: new Padding(
                        padding: EdgeInsets.fromLTRB(16.0f, 16.0f, 16.0f, 0.0f),
                        child: new DefaultTextStyle(
                            softWrap: false,
                            overflow: TextOverflow.ellipsis,
                            style: descriptionStyle,
                            child: new Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: new List <Widget> {
                    new Padding(
                        padding: EdgeInsets.only(bottom: 8.0f),
                        child: new Text(this.destination.description[0],
                                        style: descriptionStyle.copyWith(color: Colors.black54)
                                        )
                        ),
                    new Text(this.destination.description[1]),
                    new Text(this.destination.description[2])
                }
                                )
                            )
                        )
                    ),
                ButtonTheme.bar(
                    child: new ButtonBar(
                        alignment: MainAxisAlignment.start,
                        children: new List <Widget> {
                    new FlatButton(
                        child: new Text("SHARE"),
                        textColor: Colors.amber.shade500,
                        onPressed: () => {
                        /* do nothing */
                    }
                        ),
                    new FlatButton(
                        child: new Text("EXPLORE"),
                        textColor: Colors.amber.shade500,
                        onPressed: () => {
                        /* do nothing */
                    }
                        )
                }
                        )
                    ),
            }
                                   )
                               )
                           )
                       ));
        }
Esempio n. 15
0
        Widget _buildKingKongItem(string title, string imageName, GestureTapCallback onPressItem)
        {
            Widget newDot;

            if (title == "榜单" && this.widget.leaderBoardUpdatedTime.HasValue &&
                LocalDataManager.needNoticeNewLeaderBoard(dateTime: this.widget.leaderBoardUpdatedTime.Value))
            {
                newDot = new Positioned(
                    top: 0,
                    right: 0,
                    child: new Container(
                        width: 18,
                        height: 18,
                        decoration: new BoxDecoration(
                            color: CColors.Error,
                            borderRadius: BorderRadius.only(9, 9, 9)
                            ),
                        alignment: Alignment.center,
                        child: new Text(
                            "新",
                            style: new TextStyle(
                                fontSize: 10,
                                fontFamily: "Roboto-Bold",
                                color: CColors.White
                                )
                            )
                        )
                    );
            }
            else
            {
                newDot = Positioned.fill(new Container());
            }

            return(new Expanded(
                       child: new GestureDetector(
                           onTap: onPressItem,
                           child: new Container(
                               color: CColors.Transparent,
                               padding: EdgeInsets.only(top: 16, bottom: 16),
                               child: new Column(
                                   children: new List <Widget> {
                new Container(
                    margin: EdgeInsets.only(bottom: 8),
                    child: new Stack(
                        children: new List <Widget> {
                    new Padding(
                        padding: EdgeInsets.symmetric(horizontal: 9),
                        child: Image.asset(
                            "image/kingkong-bg",
                            width: 48,
                            height: 48
                            )
                        ),
                    newDot,
                    Positioned.fill(
                        new Container(
                            padding: EdgeInsets.all(6),
                            child: Image.asset($"image/{imageName}")
                            )
                        )
                }
                        )
                    ),
                new Text(data: title, style: CTextStyle.PSmallBody4)
            }
                                   )
                               )
                           )
                       ));
        }
Esempio n. 16
0
            public override Widget build(BuildContext context)
            {
                var card = new Container(
                    margin: EdgeInsets.only(right: 45),
                    child: new Container(
                        child: new Column(
                            children: new List <Widget> {
                    new Container(
                        decoration: new BoxDecoration(
                            color: CLColors.white,
                            borderRadius: BorderRadius.only(topLeft: 3, topRight: 3)
                            ),
                        width: 200,
                        height: 124,
                        child: Image.network(
                            this.imageSrc,
                            fit: BoxFit.fill
                            )
                        ),
                    new Container(
                        color: CLColors.white,
                        width: 200,
                        height: 86,
                        padding: EdgeInsets.fromLTRB(14, 12, 14, 8),
                        child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.baseline,
                            children: new List <Widget> {
                        new Container(
                            height: 18,
                            padding: EdgeInsets.only(top: 3),
                            child:
                            new Text(this.category,
                                     style: new TextStyle(
                                         fontSize: 11,
                                         color: CLColors.text5
                                         )
                                     )
                            ),
                        new Container(
                            height: 20,
                            padding: EdgeInsets.only(top: 2),
                            child:
                            new Text(this.name,
                                     style: new TextStyle(
                                         fontSize: 14,
                                         color: CLColors.text6
                                         )
                                     )
                            ),
                        new Container(
                            height: 22,
                            padding: EdgeInsets.only(top: 4),
                            child: new Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: new List <Widget> {
                            new Container(
                                child: new Row(
                                    children: new List <Widget> {
                                new Container(
                                    margin: EdgeInsets.only(right: 10),
                                    child: new Text(
                                        "$" + this.price,
                                        style: new TextStyle(
                                            fontSize: 14,
                                            color: CLColors.text7,
                                            decoration: TextDecoration.lineThrough
                                            )
                                        )
                                    ),
                                new Container(
                                    child: new Text(
                                        "$" + this.priceDiscount,
                                        style: new TextStyle(
                                            fontSize: 14,
                                            color: CLColors.text8
                                            )
                                        )
                                    )
                            })
                                ),
                            this.showBadge
                                                            ? new Container(
                                width: 80,
                                height: 18,
                                color: CLColors.black,
                                child: new Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: new List <Widget> {
                                new Text(
                                    "Plus/Pro",
                                    style: new TextStyle(
                                        fontSize: 11,
                                        color: CLColors.white
                                        )
                                    )
                            }
                                    )
                                )
                                                            : new Container()
                        }
                                )
                            )
                    }
                            )
                        )
                }
                            )
                        )
                    );

                return(card);
            }
Esempio n. 17
0
        public override Widget build(BuildContext context)
        {
            if (this.bloggerIds == null || this.userDict.isEmpty() || !this.userDict.ContainsKey(this.bloggerIds[0]))
            {
                return(new Container());
            }

            Widget firstAvatar;

            if (this.bloggerIds.Count > 0)
            {
                var user = this.userDict[this.bloggerIds[0]];
                firstAvatar = this._buildAvatar(user: user, "image/blogger-badge1", 88, true);
            }
            else
            {
                firstAvatar = new Container();
            }

            Widget secondAvatar;

            if (this.bloggerIds.Count > 1)
            {
                var user = this.userDict[this.bloggerIds[1]];
                secondAvatar = this._buildAvatar(user: user, "image/blogger-badge2");
            }
            else
            {
                secondAvatar = new Container();
            }

            Widget thirdAvatar;

            if (this.bloggerIds.Count > 2)
            {
                var user = this.userDict[this.bloggerIds[2]];
                thirdAvatar = this._buildAvatar(user: user, "image/blogger-badge3");
            }
            else
            {
                thirdAvatar = new Container();
            }

            return(new Container(
                       height: 286,
                       padding: EdgeInsets.symmetric(horizontal: 16),
                       child: new Row(
                           children: new List <Widget> {
                new Expanded(
                    flex: 11,
                    child: new Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: new List <Widget> {
                    new Container(
                        margin: EdgeInsets.only(bottom: 24),
                        child: secondAvatar
                        ),
                    Image.asset("image/leaderboard-podium-2")
                }
                        )
                    ),
                new Expanded(
                    flex: 12,
                    child: new Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: new List <Widget> {
                    new Container(
                        margin: EdgeInsets.only(bottom: 24),
                        child: firstAvatar
                        ),
                    Image.asset("image/leaderboard-podium-1")
                }
                        )
                    ),
                new Expanded(
                    flex: 11,
                    child: new Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: new List <Widget> {
                    new Container(
                        margin: EdgeInsets.only(bottom: 24),
                        child: thirdAvatar
                        ),
                    Image.asset("image/leaderboard-podium-3")
                }
                        )
                    )
            }
                           )
                       ));
        }