Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrier989 committed Mar 17, 2023
1 parent cf0d5ae commit fda5f35
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 73 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
## 0.6.1
* Small fixes.

## 0.6.0
* Many improvements.

Expand Down
31 changes: 12 additions & 19 deletions README.md
Expand Up @@ -38,18 +38,7 @@ void main() {
home: Scaffold(
body: SafeArea(
child: WebBrowser(
initialUrl: 'https://flutter.dev/',
policy: BrowserPolicy(
allowedDomains: {
// Allow navigation to "flutter.dev" and any subdomain.
// Other websites will be opened in the user's browser.
'**.flutter.dev',
// And some other websites...
'**.dart.dev',
'**.youtube.com',
},
)
initialUriString: 'https://flutter.dev/',
),
),
),
Expand All @@ -58,6 +47,16 @@ void main() {
```

# Designs available in this package
### Cupertino design
* [CupertinoBrowserTopBar](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserTopBar-class.html)
* [CupertinoBrowserBottomBar](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserBottomBar-class.html)
with:
* [CupertinoBrowserBackButton](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserBackButton-class.html)
* [CupertinoBrowserForwardButton](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserForwardButton-class.html)
* [CupertinoBrowserRefreshButton](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserRefreshButton-class.html)

<img src="screenshots/cupertino.png">

### Material design
* [MaterialBrowserTopBar](https://pub.dev/documentation/web_browser/latest/web_browser.material/MaterialBrowserTopBar-class.html)
* [MaterialBrowserBottomBar](https://pub.dev/documentation/web_browser/latest/web_browser.material/MaterialBrowserBottomBar-class.html)
Expand All @@ -66,13 +65,7 @@ void main() {
* [MaterialBrowserForwardButton](https://pub.dev/documentation/web_browser/latest/web_browser.material/MaterialBrowserForwardButton-class.html)
* [MaterialBrowserRefreshButton](https://pub.dev/documentation/web_browser/latest/web_browser.material/MaterialBrowserRefreshButton-class.html)

### Cupertino design
* [CupertinoBrowserTopBar](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserTopBar-class.html)
* [CupertinoBrowserBottomBar](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserBottomBar-class.html)
with:
* [CupertinoBrowserBackButton](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserBackButton-class.html)
* [CupertinoBrowserForwardButton](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserForwardButton-class.html)
* [CupertinoBrowserRefreshButton](https://pub.dev/documentation/web_browser/latest/web_browser.cupertino/CupertinoBrowserRefreshButton-class.html)
<img src="screenshots/material.png">

## Auto-design (default)
By default, the package chooses Material or Cupertino design based on whether the app is
Expand Down
1 change: 1 addition & 0 deletions example/android/app/src/debug/AndroidManifest.xml
Expand Up @@ -5,4 +5,5 @@
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
2 changes: 2 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Expand Up @@ -31,4 +31,6 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
1 change: 1 addition & 0 deletions example/android/app/src/profile/AndroidManifest.xml
Expand Up @@ -5,4 +5,5 @@
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
54 changes: 17 additions & 37 deletions example/lib/main.dart
@@ -1,49 +1,29 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:web_browser/web_browser.dart';

void main() {
// const app = CupertinoApp(
// title: 'Example',
// home: CupertinoPageScaffold(
// child: SafeArea(
// child: Browser(
// initialUriString: 'https://dart.dev/',
// policy: BrowserPolicy(
// allowedDomains: {
// // Allow navigation to flutter.dev and any subdomain.
// // Other websites will be opened in the user's browser.
// '**.flutter.dev',
//
// // And some other websites...
// '**.dart.dev',
// '**.youtube.com',
// },
// ),
// ),
// ),
// ),
// );
const app = MaterialApp(
const app = CupertinoApp(
title: 'Example',
home: Scaffold(
body: SafeArea(
debugShowCheckedModeBanner: false,
home: CupertinoPageScaffold(
child: SafeArea(
child: Browser(
initialUriString: 'https://dart.dev/',
policy: BrowserPolicy(
allowedDomains: {
// Allow navigation to flutter.dev and any subdomain.
// Other websites will be opened in the user's browser.
'**.flutter.dev',

// And some other websites...
'**.dart.dev',
'**.youtube.com',
},
),
initialUriString: 'https://flutter.dev/',
),
),
),
);
// const app = MaterialApp(
// title: 'Example',
// debugShowCheckedModeBanner: false,
// home: Scaffold(
// body: SafeArea(
// child: Browser(
// initialUriString: 'https://flutter.dev/',
// ),
// ),
// ),
// );

runApp(app);
}
1 change: 1 addition & 0 deletions lib/basic.dart
Expand Up @@ -20,3 +20,4 @@ library web_browser.basic;

export 'src/basic/basic_browser_address_field.dart';
export 'src/basic/basic_browser_bottom_dialog.dart';
export 'src/basic/basic_browser_error_widget.dart';
10 changes: 8 additions & 2 deletions lib/src/basic/basic_browser_error_widget.dart
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:web_browser/src/web_browser/browser_localizations.dart';
import 'package:webview_flutter/webview_flutter.dart';

/// A widget that may be used to replace [WebViewWidget] when an error occurs.
Expand All @@ -20,9 +21,14 @@ class BasicBrowserErrorWidget extends StatelessWidget {
required WebResourceError error,
required Widget? refreshButton,
}) {
final localizations = Localizations.of<BrowserLocalizations>(
context,
BrowserLocalizations,
) ??
const BrowserLocalizations();
return BasicBrowserErrorWidget(
title: const Text(
'Could not reach the website :(',
title: Text(
localizations.couldNotReach,
textAlign: TextAlign.center,
),
body: Column(
Expand Down
12 changes: 8 additions & 4 deletions lib/src/web_browser/browser.dart
Expand Up @@ -16,12 +16,11 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart' as share_plus;
import 'package:web_browser/src/basic/basic_browser_error_widget.dart';
import 'package:web_browser/src/web_browser/browser_controller.dart';
import 'package:web_browser/src/web_browser/browser_policy.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../../auto.dart';
import '../../basic.dart';
import '../../web_browser.dart';

/// A web browser widget with navigation buttons and other features.
///
Expand Down Expand Up @@ -96,7 +95,12 @@ class Browser extends StatefulWidget {
/// Default callback for [onError].
static Widget defaultOnError(BuildContext context,
BrowserController controller, WebResourceError error) {
const label = Text('Try again');
final localizations = Localizations.of<BrowserLocalizations>(
context,
BrowserLocalizations,
) ??
const BrowserLocalizations();
final label = Text(localizations.tryAgain);
void onPressed() {
Browser.of(context).controller.refresh();
}
Expand Down
19 changes: 13 additions & 6 deletions lib/src/web_browser/browser_controller.dart
Expand Up @@ -83,13 +83,18 @@ class BrowserController extends ChangeNotifier {
if (!kIsWeb) {
try {
if (_isAndroid) {
// Do other platforms than Android give "canGoBlack" data?
_webViewController.canGoBack().then((value) {
_canGoBack = value;
if (value != _canGoBack) {
_canGoBack = value;
notifyListeners();
}
}, onError: (error) {});
}
_webViewController.canGoForward().then((value) {
_canGoForward = value;
if (value != _canGoForward) {
_canGoForward = value;
notifyListeners();
}
}, onError: (error) {});
} catch (error) {
// Ignore error
Expand All @@ -111,9 +116,11 @@ class BrowserController extends ChangeNotifier {
webViewNavigationDelegate?.onPageFinished?.call(uri);
},
onWebResourceError: (error) {
_error = error;
_isLoading = false;
notifyListeners();
if (error.isForMainFrame ?? true) {
_error = error;
_isLoading = false;
notifyListeners();
}
webViewNavigationDelegate?.onWebResourceError?.call(error);
},
));
Expand Down
8 changes: 6 additions & 2 deletions lib/src/web_browser/browser_localizations.dart
Expand Up @@ -21,13 +21,17 @@ class BrowserLocalizations {

final String forward;
final String refresh;
final String copy;
final String share;
final String couldNotReach;
final String tryAgain;

const BrowserLocalizations({
this.back = 'Back',
this.forward = 'Forward',
this.copy = 'Copy',
this.refresh = 'Refresh',
this.share = 'Share',
this.couldNotReach = 'Could not reach the website.',
this.tryAgain = 'Try again.',
});

/// Constructs [LocalizationsDelegate] for the localization.
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
@@ -1,8 +1,8 @@
name: web_browser
version: 0.6.0
version: 0.6.1
description:
A cross-platform Flutter widget for displaying websites and other web content. Has optional
navigation buttons.
A cross-platform Flutter widget for displaying websites and other web content. Has navigation
Cupertino/Material buttons and takes care of complex platform differences.
homepage: https://github.com/dint-dev/web_browser

environment:
Expand Down
Binary file added screenshots/cupertino.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/material.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fda5f35

Please sign in to comment.