web_browser
웹 브라우저 위젯입니다. webview_flutter와 달리 크로스 플랫폼 네비게이션 및 URL 공유 위젯을 포함하고 있습니다. Android, iOS, 브라우저 및 기타 플랫폼에서 작동합니다.
Flutter에서 웹사이트를 표시합니다. 탐색/공유 버튼, 피싱 방지 디자인 등이 포함되어 있습니다.
^1.0.2{"sdk":"flutter"}^4.0.6^3.4.2^0.2.2+1^3.2.1^6.3.1^2.0.1{"sdk":"flutter"}아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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:
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.
In pubspec.yaml:
dependencies:
web_browser: ^0.7.4
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/',
),
),
),
));
}
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:
https://raw.githubusercontent.com/dint-dev/web_browser/HEAD/screenshots/cupertino.png
https://raw.githubusercontent.com/dint-dev/web_browser/HEAD/screenshots/material.png
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.',
// ...
),
),
];
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,
)
),
),
),
));
}
For end-users privacy, it is good to clear:
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);
// ...
}
To access WebViewController by using browserController.webViewController.