搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。