搜索插件、代码仓与 APP 分类

插件详情v0.7.4

web_browser

一个网页浏览器组件。与 webview_flutter 不同,它自带跨平台的导航和 URL 共享组件。可在 Android、iOS、浏览器及其他平台上使用。

AndroidiOSmacOS
近 30 天下载
100
喜欢数
71
Pub 分数
140

安装插件

flutter pub add web_browser

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

web_browser 包为 Flutter 提供了一个跨平台的网页浏览器小部件,具备内置的导航控件和 URL 共享功能。与 webview_flutter 不同,它旨在无缝地在 Android、iOS、macOS 和 Web 平台上运行,并保持一致的 UI 组件。该包简化了嵌入网页内容的过程,同时保留了各平台特有的行为和用户体验标准。该包包含直观的导航工具,如后退/前进按钮和可分享的 URL,非常适合需要集成浏览功能但又不想重新发明常见浏览器特性的应用。

适合场景

  • 在移动和桌面应用程序中嵌入网页内容
  • 构建基于应用的浏览器并实现导航
  • 在应用内分享链接
  • 创建混合网页原生应用
  • 在多个平台上启用应用内浏览

主要特点

  • 跨平台兼容性(Android、iOS、macOS、Web)
  • 内置导航控件
  • URL 分享集成
  • 跨平台一致的用户界面
  • 轻量且易于集成

适合对象

  • 使用网页内容构建多平台应用程序的开发人员
  • 需要简单浏览器功能的应用
  • 需要从嵌入式网页视图中共享URL的项目
  • 希望避免自定义 WebView 实现的团队
  • 寻求原生浏览体验的混合应用开发者

使用建议

  • 与原生 WebView 相比,自定义选项有限
  • 依赖于平台特定的渲染行为
  • 在某些平台上可能需要额外的权限
  • 不适合用于复杂网页应用托管
  • 性能在旧设备上可能有所不同

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Pub Package Github Actions CI

Overview

The package gives you Browser, a Flutter widget for displaying web pages.

The package is built on top of webview_flutter and it adds navigation widgets that:

  • Display the domain.
  • Allow user to tap "back", "forward", "refresh", or share the URL using a native dialog of each platform.
  • Display website loading error messages in a visually pleasant and easy-to-understand way.

Browser has been tested in Android, iOS, and browsers. By adding relevant "webview_flutter" plugin dependencies to your "pubspec.yaml", you can use this package in Windows, Mac OS X, and Linux too.

Licensed under the Apache License 2.0.

Links

Setting up

1.Setup

In pubspec.yaml:

dependencies:
  web_browser: ^0.7.4

2.Display web browser

import 'package:flutter/material.dart';
import 'package:web_browser/web_browser.dart';

void main() {
  runApp(const MaterialApp(
    home: Scaffold(
      body: SafeArea(
        child: Browser(
          initialUriString: 'https://flutter.dev/',
        ),
      ),
    ),
  ));
}

Manual

Default designs

The package contains two designs, Cupertino (web_browser.cupertino) and Material (web_browser.material). By default, the package chooses a Cupertino or Material design based on whether the app is CupertinoApp or MaterialApp. You can override the defaults by using relevant parameters of Browser() constructor.

The Cupertino and Material navigation bars look like this:

Localization

Use BrowserLocalizations to localize the widgets.

void main() {
  runApp(MaterialApp(
    localizations: [
      ...browserLocalizationsList,
      // ...
    ],
    // ...
  ));
}

final browserLocalizationsList = [
  // Spanish localization
  BrowserLocalizations.forLocale(
    locale: Locale('es'),
    load: (locale) async => BrowserLocalizations(
      couldNotReach: 'No se pudo acceder al sitio web.',
      // ...
    ),
  ),
];

Setting various parameters

You can give various parameters to Browser:

import 'package:flutter/material.dart';
import 'package:web_browser/web_browser.dart';

void main() {
  runApp(const MaterialApp(
    home: Scaffold(
      body: SafeArea(
        child: Browser(
          initialUriString: 'https://flutter.dev/',
          controller: BrowserController(
            // "User-Agent" HTTP header.
            userAgent: 'Your user agent',
            
            // Can user zoom into the content? Default is true.
            isZoomingEnabled: false,
          )
        ),
      ),
    ),
  ));
}

Cache clearing

For end-users privacy, it is good to clear:

  • Cookies
  • Caches
  • Local storage

You can enable this by setting:

import 'package:web_browser/web_browser.dart';

void main() {
  // Clear when the app is started
  BrowserController.resetGlobalStateAtStart = true;
  
  // Clear every now and then.
  BrowserController.globalStateExpiration = const Duration(days: 1);
  
  // ...
}

Accessing WebViewController

To access WebViewController by using browserController.webViewController.

所属分类

依赖

依赖清单 6 项

源码仓库

使用此插件的项目

暂无相关数据。