Giter VIP home page Giter VIP logo

web_browser's Introduction

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.

web_browser's People

Contributors

terrier989 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

web_browser's Issues

Is there a way to observe events

I want to be able to keep a history of my users actions on various websites. This is a core functionality of the app. How can I do this?

Access WebPage Content

Currently, there doesn't seem to be a way to access webpage contents, such as innerHtml. I tried to use WebBrowserController's evaluateJavascript method, but as it returns a Future, I'm not able to get data from it.

White Screen on Example Homescreen

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

and just a white screen..

Selfsigned HTTPS Certificate

Hello everybody,

i use a Raspberry Pi as a Server with nginx and selfsigned https certificate with it. When i surf the site i need to accept the certificate on chrome to visit the site and use my webcam as camera. It works fine in normal Browser on mobile and desktop. But when i try it over the web_browser Flutter App it shows only a white site, nothing to accept or error.. is there a trick to get it running?

Thanks a lot!

Remove IFrameElement border on web.

I've dug through the docs and code and can't seem to find a way to remove the border from the IFrame used in the web version, when I was embedding the frame myself I was able to set the IFrameElement.style.border property to none to remove the frame, is there any way to do this?

Web Browser in Windows

How to use this plugin in Windows? I am not able to run this example application in a Windows machine. Please help me in running the example app for Windows.

on window controll.evaluateJavascript fail

controll.evaluateJavascript('console.log('11111');');

Error: Expected a value of type 'JsObject', but got one of type '_DOMWindowCrossFrame'
    at Object.throw_ [as throw] (http://localhost:55502/dart_sdk.js:5334:11)
    at Object.castError (http://localhost:55502/dart_sdk.js:5305:15)
    at Object.cast [as as] (http://localhost:55502/dart_sdk.js:5621:17)
    at Function.as_C [as as] (http://localhost:55502/dart_sdk.js:5249:19)
    at web_browser_impl_browser._WebBrowserController.new.evaluateJavascript (http://localhost:55502/packages/web_browser/src/web_browser_navigation_bar.dart.lib.js:1851:34)
    at evaluateJavascript.next (<anonymous>)
    at runBody (http://localhost:55502/dart_sdk.js:39052:34)
    at Object._async [as async] (http://localhost:55502/dart_sdk.js:39083:7)
    at web_browser_impl_browser._WebBrowserController.new.evaluateJavascript (http://localhost:55502/packages/web_browser/src/web_browser_navigation_bar.dart.lib.js:1850:20)
    at http://localhost:55502/packages/flutter_video/cut_video_page.dart.lib.js:222:26
    at http://localhost:55502/dart_sdk.js:33443:33
    at internalCallback (http://localhost:55502/dart_sdk.js:25104:11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.