flutter_html 和 WebView 解析html
2021-04-15 11:29
标签:min webview image fonts htm wait element http view flutter_html 和 WebView 解析html 标签:min webview image fonts htm wait element http view 原文地址:https://www.cnblogs.com/zhaofeis/p/12363180.htmlimport ‘dart:convert‘;
import ‘package:flutter/material.dart‘;
import ‘package:dio/dio.dart‘;
import ‘package:flutter_html/flutter_html.dart‘;
import ‘package:html/dom.dart‘ as dom;
class FlutterHtml extends StatefulWidget{
FlutterHtml({Key key});
_FlutterHtml createState() => _FlutterHtml();
}
class _FlutterHtml extends State {
var _html = [];
@override
initState() {
super.initState();
_getData();
}
_getData() async{
var response = await Dio().get(‘http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=20‘);
var res = json.decode(response.data)[‘result‘];
setState(() {
_html = res;
});
print(res);
}
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(title: Text(‘FlutterHtml‘),),
body: ListView(
children:
Html(
data: "${ _html.length > 0 ? _html[0][‘content‘] : 1}",
//Optional parameters:
padding: EdgeInsets.all(8.0),
backgroundColor: Colors.white70,
defaultTextStyle: TextStyle(fontFamily: ‘serif‘),
linkStyle: const TextStyle(
color: Colors.redAccent,
),
onLinkTap: (url) {
// open url in a webview
},
onImageTap: (src) {
// Display the image in large form.
},
customTextStyle: (dom.Node node, TextStyle baseStyle) {
if (node is dom.Element) {
switch (node.localName) {
case "p":
return baseStyle.merge(TextStyle(height: 2, fontSize: 20));
}
}
return baseStyle;
},
)
],
)
);
}
}minSdkVersion 最小版本为17 全局搜索改
WebView 案例代码
上一篇:1.Web介绍与HTTP基础
下一篇:html基本标签
文章标题:flutter_html 和 WebView 解析html
文章链接:http://soscw.com/index.php/essay/75971.html