示例#1
0
        static List <Widget> _CodeBlock(string text)
        {
            List <Widget> codeBlockList = new List <Widget>();

            if (text.isEmpty())
            {
                codeBlockList.Add(new Container());
            }
            else
            {
                var codeStringList = text.Split(Environment.NewLine.ToCharArray());
                codeBlockList.Add(new Container(color: codeBlockBackgroundColor, height: 16));
                for (int i = 0; i < codeStringList.Length; i++)
                {
                    string codeBlockGroup = "";
                    for (int j = 0; j < codeBlockNumber && i < codeStringList.Length; j++)
                    {
                        codeBlockGroup += codeStringList[i];
                        if (i == codeStringList.Length - 1 && codeStringList.Length % codeBlockNumber != 0)
                        {
                            break;
                        }

                        if (j < codeBlockNumber - 1)
                        {
                            codeBlockGroup += Environment.NewLine;
                            i++;
                        }
                    }

                    var codeWidget = new TipMenu(
                        new List <TipMenuItem> {
                        new TipMenuItem(
                            "复制",
                            () => Clipboard.setData(new ClipboardData(text: codeBlockGroup))
                            )
                    },
                        new Container(
                            color: codeBlockBackgroundColor,
                            padding: EdgeInsets.symmetric(horizontal: 16),
                            child: new Text(
                                data: codeBlockGroup,
                                style: CTextStyle.PCodeStyle
                                )
                            )
                        );
                    codeBlockList.Add(item: codeWidget);
                }

                codeBlockList.Add(new Container(color: codeBlockBackgroundColor, height: 16));
                codeBlockList.Add(new Container(color: CColors.White, height: 24));
            }

            return(codeBlockList);
        }
示例#2
0
 static CustomButton _buildToolbarButton(string text, VoidCallback onPressed)
 {
     return(new CustomButton(
                child: new Text(data: text, style: CustomTextSelectionControlsUtils._kToolbarButtonFontStyle),
                decoration: new BoxDecoration(color: CustomTextSelectionControlsUtils._kToolbarBackgroundColor),
                padding: CustomTextSelectionControlsUtils._kToolbarButtonPadding,
                onPressed: () => {
         onPressed();
         TipMenu.dismiss();
     }
                ));
 }