1

I need to get meta data from html head using flutter_webview. In this case I need to get value from

<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#4285f4">

so I can use website theme color on my app.

how can I do this?

1 Answer 1

2

If you want to get meta data tag from webpage then you can use "alice: ^0.0.4" library.

First declare that in "alice: ^0.0.4" in pubspec.yaml

Below is the full example i have created for you where you can see i have printed body, bodyBytes, headers as well contentLength from which we can get all "" tags:

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();
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.