一、flutter_html
涉及的 api 接口:
http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=20
二、Flutter 解析 html
https://pub.dev/packages/flutter_html
 
flutter_html 案例代码  ---- 下面有WebView 案例代码
import '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: <Widget>[
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;
},
)
],
)
);
}
}
WebView 加载的远程 web 页面:
http://www.phonegap100.com/newscontent.php?aid=198
 
二、Flutter WebView 组件 inappbrowser的使用
https://pub.dev/packages/flutter_inappbrowser 
 
注意事项 Android: minSdkVersion 最小版本为17 在app文件夹下面的build.gradle 如果报错就替换 build.gradle
使用文件引入 import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
如高版本flutter_inappbrowser出错  就使用flutter_inappbrowser: ^1.2.1
 
//build.gradle 文件源码
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
} def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
} def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
} def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
} apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android {
compileSdkVersion 28 sourceSets {
main.java.srcDirs += 'src/main/kotlin'
} lintOptions {
disable 'InvalidPackage'
} defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.itying.flutter_app01"
minSdkVersion 17
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
} flutter {
source '../..'
} dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
WebView 案例代码
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart'; class WebView extends StatefulWidget{
WebView({Key key});
_WebView createState() => _WebView();
} class _WebView extends State {
@override
initState() {
super.initState();
}
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(title: Text('webView'),),
body: Column(
children: <Widget>[
Expanded(
child: InAppWebView(
initialUrl: "http://www.phonegap100.com/newscontent.php?aid=198",
),
)
]
)
);
}
}

最新文章

  1. myeclipse 内存不够用报错PermGen space 和 An internal error has occurred.
  2. Hadoop---Google MapReduce(转)
  3. react1
  4. BZOJ4110 : [Wf2015]Evolution in Parallel
  5. ios面试(2015.10.30)
  6. 代码中特殊的注释技术——TODO、FIXME和XXX的用处
  7. 技术英文单词贴--E
  8. 自定义控件winfrom
  9. WPF解析PDF为图片
  10. jsp与servlet之间的参数传递【转】
  11. AIDL-Android接口描述语言实现跨进程通讯
  12. js监控视频播放的事件并打印log
  13. C# 通过Attribute制作的一个消息拦截器
  14. (简单) HDU 3308 LCIS,线段树+区间合并。
  15. 关于sleep()和interrupt()及主线程和线程
  16. 如何使用JS实现banner图滚动
  17. 学以致用二十七-----Centos7.5二进制安装mysql5.7.23
  18. [51CTO]服务器虚拟化开源技术主流架构之争
  19. sql中根据逗号分隔,查出多行数据
  20. 启停无线网卡bat脚本

热门文章

  1. C#中删除目录以及目录下文件的方法
  2. 创建基于ASP.NET core 3.1 的RazorPagesMovie项目(三)-已搭建基架的Razor页面解释和更新
  3. (ubuntu系统)安装opencv-python后,报错libSM.so.6: cannot open shared object file: No such file or directory
  4. Leetcode Week1 Regular Expression Matching
  5. maven-设置aliyun远程库
  6. 爬虫爱用的一些python技巧
  7. AspxGridView 客户端点击获取对应的列值
  8. (四)tensorflow-基础(数据类型,张量操作,数学运算)
  9. phpstorm实用技巧
  10. python求极值点(波峰波谷)