wv_user_agent 1.0.0+1 copy "wv_user_agent: ^1.0.0+1" to clipboard
wv_user_agent: ^1.0.0+1 copied to clipboard

A simple Flutter plugin for retrieving the actual user agent of a device using the native WebView.

example/lib/main.dart

import 'package:wv_user_agent/wv_user_agent.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _userAgent = 'Loading...';
  late WebViewController _controller;

  @override
  void initState() {
    super.initState();
    _loadUserAgent();
  }

  // Fetches the actual User-Agent from the native WebView
  Future<void> _loadUserAgent() async {
    final ua = await WvUserAgent.userAgent;
    setState(() {
      _userAgent = ua;
    });

    // Initialize WebView with the fetched User-Agent
    _controller =
        WebViewController()
          ..setJavaScriptMode(JavaScriptMode.unrestricted)
          ..setUserAgent(_userAgent)
          ..loadRequest(Uri.parse('https://www.whatismybrowser.com/'));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('User Agent Test')),
        body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text('User Agent: $_userAgent', textAlign: TextAlign.center),
            ),
            Expanded(child: WebViewWidget(controller: _controller)),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
6
downloads

Publisher

verified publisherjakkimcfly.com

Weekly Downloads

A simple Flutter plugin for retrieving the actual user agent of a device using the native WebView.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on wv_user_agent

Packages that implement wv_user_agent