如何使用FlatterWebView获取html元数据
我需要使用Flatter_webview从html头部获取元数据。 在这种情况下,我需要从如何使用FlatterWebView获取html元数据,webview,flutter,Webview,Flutter,我需要使用Flatter_webview从html头部获取元数据。 在这种情况下,我需要从 <!-- Chrome, Firefox OS and Opera --> <meta name="theme-color" content="#4285f4"> 所以我可以在我的应用程序上使用网站主题颜色 我如何才能做到这一点?如果您想从网页中获取元数据标记,则可以使用“alice:^0.0.4”库 首先在pubspec.yaml的“alice:^0.0.4”中声明 下面是
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#4285f4">
所以我可以在我的应用程序上使用网站主题颜色
我如何才能做到这一点?如果您想从网页中获取元数据标记,则可以使用“alice:^0.0.4”库 首先在pubspec.yaml的“alice:^0.0.4”中声明 下面是我为您创建的完整示例,您可以看到我打印了body、bodyBytes、Header以及contentLength,从中可以获得所有“”标记:
导入“包装:颤振/材料.省道”;
导入“package:alice/alice.dart”;
导入“dart:convert”;
导入“dart:io”;
将“package:http/http.dart”导入为http;
进口“包装:dio/dio.dart”;
Alice=Alice(showNotification:true);
void main(){
runApp(新的MyApp());
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
爱丽丝;
迪奥迪奥;
HttpClient-HttpClient;
@凌驾
void initState(){
alice=alice(showNotification:true);
dio=dio();
add(alice.getDioInterceptor());
httpClient=httpClient();
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回材料PP(
navigatorKey:alice.getNavigatorKey(),
debugShowCheckedModeBanner:false,
家:脚手架(
appBar:appBar(
标题:const Text('Alice HTTP Inspector示例'),
),
正文:中(
儿童:
列(mainAxisAlignment:mainAxisAlignment.center,子项:[
升起的按钮(
子项:文本(“运行HTTP请求”),
onPressed:\u运行HttpRequests,
),
升起的按钮(
子项:文本(“运行HTTP Insepctor”),
onPressed:_runHttpInspector,
),
])),
),
);
}
void\u runHttpRequests()异步{
Map body={“title”:“foo”,“body”:“bar”,“userId”:“1”};
http
.post('https://www.google.com,body:body)
.然后((回应){
onHttpResponse(响应,body:body);
打印(响应.正文);
打印(响应.bodyBytes);
打印(响应.标题);
打印(response.contentLength);
});
邮政署(”https://www.google.com“,数据:正文);
}
void_runHttpInspector(){
alice.showInspector();
}
}
import 'package:flutter/material.dart';
import 'package:alice/alice.dart';
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:dio/dio.dart';
Alice alice = Alice(showNotification: true);
void main() {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Alice alice;
Dio dio;
HttpClient httpClient;
@override
void initState() {
alice = Alice(showNotification: true);
dio = Dio();
dio.interceptors.add(alice.getDioInterceptor());
httpClient = HttpClient();
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: alice.getNavigatorKey(),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Alice HTTP Inspector example'),
),
body: Center(
child:
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
RaisedButton(
child: Text("Run HTTP Requests"),
onPressed: _runHttpRequests,
),
RaisedButton(
child: Text("Run HTTP Insepctor"),
onPressed: _runHttpInspector,
),
])),
),
);
}
void _runHttpRequests() async {
Map<String, dynamic> body = {"title": "foo", "body": "bar", "userId": "1"};
http
.post('https://www.google.com', body: body)
.then((response) {
alice.onHttpResponse(response, body: body);
print(response.body);
print(response.bodyBytes);
print(response.headers);
print(response.contentLength);
});
dio.post("https://www.google.com", data: body);
}
void _runHttpInspector() {
alice.showInspector();
}
}