Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在颤振中处理API中的RichText?_Flutter_Dart - Fatal编程技术网

Flutter 如何在颤振中处理API中的RichText?

Flutter 如何在颤振中处理API中的RichText?,flutter,dart,Flutter,Dart,如何处理从API调用传入的RichText? 我收到一个字符串,其中包含了作为标记的内联样式。我发现这个酒吧包: 这是相当有用的。然而,它并不能处理所有事情。例如,我在处理blockquote时遇到困难 另外,建议用什么方法来处理带有内联标记的字符串?您可以使用flatter\u html来呈现html字符串 您可以使用flatter\u html来呈现html字符串 “带内联标记的字符串”不是完整的规范。您是否有可以参考的特定文档或格式名称?如果它的字面意思是“RichText”,我甚至不相信

如何处理从API调用传入的RichText? 我收到一个字符串,其中包含了作为标记的内联样式。我发现这个酒吧包: 这是相当有用的。然而,它并不能处理所有事情。例如,我在处理blockquote时遇到困难


另外,建议用什么方法来处理带有内联标记的字符串?

您可以使用flatter\u html来呈现html字符串


您可以使用flatter\u html来呈现html字符串

“带内联标记的字符串”不是完整的规范。您是否有可以参考的特定文档或格式名称?如果它的字面意思是“RichText”,我甚至不相信它会像明文一样可读。“带有内联标签的字符串”不是一个完整的规范。您是否有可以参考的特定文档或格式名称?如果它是字面上的“RichText”,我甚至不相信它会像明文一样可读。
These Three are the Main Package for this :

import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_html/html_parser.dart';
import 'package:flutter_html/style.dart';


Example : 
    import 'package:flutter/material.dart';
    import 'package:flutter_html/flutter_html.dart';
    import 'package:flutter_html/html_parser.dart';
    import 'package:flutter_html/style.dart';
    
    void main() => runApp(new MyApp());
    
    class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
            primarySwatch: Colors.deepPurple,
          ),
          home: new MyHomePage(title: 'flutter_html Example'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      _MyHomePageState createState() => new _MyHomePageState();
    }
    
    const htmlData = """
    <h1>Header 1</h1>
    <h2>Header 2</h2>
    <h3>Header 3</h3>
    <h4>Header 4</h4>
    <h5>Header 5</h5>
    <h6>Header 6</h6>
    <h3>Ruby Support:</h3>
          <p>
            <ruby>
              漢<rt>かん</rt>
              字<rt>じ</rt>
            </ruby>
            &nbsp;is Japanese Kanji.
          </p>
          <h3>Support for <code>sub</code>/<code>sup</code></h3>
          Solve for <var>x<sub>n</sub></var>: log<sub>2</sub>(<var>x</var><sup>2</sup>+<var>n</var>) = 9<sup>3</sup>
          <p>One of the most <span>common</span> equations in all of physics is <br /><var>E</var>=<var>m</var><var>c</var><sup>2</sup>.</p>
          <h3>Inline Styles:</h3>
          <p>The should be <span style='color: blue;'>BLUE style='color: blue;'</span></p>
          <p>The should be <span style='color: red;'>RED style='color: red;'</span></p>
          <p>The should be <span style='color: rgba(0, 0, 0, 0.10);'>BLACK with 10% alpha style='color: rgba(0, 0, 0, 0.10);</span></p>
          <p>The should be <span style='color: rgb(0, 97, 0);'>GREEN style='color: rgb(0, 97, 0);</span></p>
          <p>The should be <span style='background-color: red; color: rgb(0, 97, 0);'>GREEN style='color: rgb(0, 97, 0);</span></p>
          <p style="text-align: center;"><span style="color: rgba(0, 0, 0, 0.95);">blasdafjklasdlkjfkl</span></p>
          <p style="text-align: right;"><span style="color: rgba(0, 0, 0, 0.95);">blasdafjklasdlkjfkl</span></p>
          <p style="text-align: justify;"><span style="color: rgba(0, 0, 0, 0.95);">blasdafjklasdlkjfkl</span></p>
          <p style="text-align: center;"><span style="color: rgba(0, 0, 0, 0.95);">blasdafjklasdlkjfkl</span></p>
          <h3>Table support (with custom styling!):</h3>
          <p>
          <q>Famous quote...</q>
          </p>
          <table>
          <colgroup>
            <col width="50%" />
            <col span="2" width="25%" />
          </colgroup>
          <thead>
          <tr><th>One</th><th>Two</th><th>Three</th></tr>
          </thead>
          <tbody>
          <tr>
            <td rowspan='2'>Rowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan</td><td>Data</td><td>Data</td>
          </tr>
          <tr>
            <td colspan="2"><img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' /></td>
          </tr>
          </tbody>
          <tfoot>
          <tr><td>fData</td><td>fData</td><td>fData</td></tr>
          </tfoot>
          </table>
          <h3>Custom Element Support:</h3>
          <flutter></flutter>
          <flutter horizontal></flutter>
          <h3>SVG support:</h3>
          <svg id='svg1' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'>
                <circle r="32" cx="35" cy="65" fill="#F00" opacity="0.5"/>
                <circle r="32" cx="65" cy="65" fill="#0F0" opacity="0.5"/>
                <circle r="32" cx="50" cy="35" fill="#00F" opacity="0.5"/>
          </svg>
          <h3>List support:</h3>
          <ol>
                <li>This</li>
                <li><p>is</p></li>
                <li>an</li>
                <li>
                ordered
                <ul>
                <li>With<br /><br />...</li>
                <li>a</li>
                <li>nested</li>
                <li>unordered
                <ol>
                <li>With a nested</li>
                <li>ordered list.</li>
                </ol>
                </li>
                <li>list</li>
                </ul>
                </li>
                <li>list! Lorem ipsum dolor sit amet.</li>
                <li><h2>Header 2</h2></li>
                <h2><li>Header 2</li></h2>
          </ol>
          <h3>Link support:</h3>
          <p>
            Linking to <a href='https://github.com'>websites</a> has never been easier.
          </p>
          <h3>Image support:</h3>
          <p>
            <img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' />
            <a href='https://google.com'><img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' /></a>
            <img alt='Alt Text of an intentionally broken image' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30d' />
          </p>
          <h3>Video support:</h3>
          <video controls>
            <source src="https://www.w3schools.com/html/mov_bbb.mp4" />
          </video>
          <h3>Audio support:</h3>
          <audio controls>
            <source src="https://www.w3schools.com/html/mov_bbb.mp4" />
          </audio>
          <h3>IFrame support:</h3>
          <iframe src="https://google.com"></iframe>
    """;
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: AppBar(
            title: Text('flutter_html Example'),
            centerTitle: true,
          ),
          body: SingleChildScrollView(
            child: Html(
              data: htmlData,
              //Optional parameters:
              style: {
                "html": Style(
                  backgroundColor: Colors.black12,
    //              color: Colors.white,
                ),
    //            "h1": Style(
    //              textAlign: TextAlign.center,
    //            ),
                "table": Style(
                  backgroundColor: Color.fromARGB(0x50, 0xee, 0xee, 0xee),
                ),
                "tr": Style(
                  border: Border(bottom: BorderSide(color: Colors.grey)),
                ),
                "th": Style(
                  padding: EdgeInsets.all(6),
                  backgroundColor: Colors.grey,
                ),
                "td": Style(
                  padding: EdgeInsets.all(6),
                  alignment: Alignment.topLeft,
                ),
                "var": Style(fontFamily: 'serif'),
              },
              customRender: {
                "flutter": (RenderContext context, Widget child, attributes, _) {
                  return FlutterLogo(
                    style: (attributes['horizontal'] != null)
                        ? FlutterLogoStyle.horizontal
                        : FlutterLogoStyle.markOnly,
                    textColor: context.style.color,
                    size: context.style.fontSize.size * 5,
                  );
                },
              },
              onLinkTap: (url) {
                print("Opening $url...");
              },
              onImageTap: (src) {
                print(src);
              },
              onImageError: (exception, stackTrace) {
                print(exception);
              },
            ),
          ),
        );
      }
    }