Skip to content

Commit

Permalink
Update Flutter Web WebView Support
Browse files Browse the repository at this point in the history
- Flutter Web now supports WebViews.
  • Loading branch information
rayliverified committed Feb 24, 2024
1 parent 0f9ebf7 commit e410379
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
13 changes: 5 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,12 @@ List<Widget> blocks = [
const BlockWrapper(NativePerformance()),
const BlockWrapper(LearnFromDevelopers()),
const BlockWrapper(WhoUsesFlutter()),
// Disabled codelab block for performance.
const ResponsiveVisibility(
hiddenConditions: [Condition.smallerThan(name: DESKTOP)],
child: BlockWrapper(FlutterCodelab()),
),
const BlockWrapper(FlutterNewsRow()),
const BlockWrapper(InstallFlutter()),
const Footer(),
];

// Disabled codelab block for performance.
// ResponsiveVisibility(
// hiddenWhen: [Condition.smallerThan(name: DESKTOP)],
// child: ResponsiveConstraints(
// constraintsWhen: blockWidthConstraints,
// child: FlutterCodelab()),
// ),
55 changes: 24 additions & 31 deletions lib/ui/blocks.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:ui' as ui;

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_website/components/components.dart';
Expand Down Expand Up @@ -1043,20 +1042,21 @@ class _LearnFromDevelopersState extends State<LearnFromDevelopers> {
padding: const EdgeInsets.symmetric(horizontal: 25),
child: AspectRatio(
aspectRatio: videoAspectRatio,
child: (kIsWeb)
? Image.asset(
"assets/images/video_thumbnail_learn_from_developers.png",
fit: BoxFit.contain)
// TODO: Disable multiple embedded iframes to prevent flicker.
child: WebViewWidget(
key: webViewKey,
controller: WebViewController()
..loadRequest(Uri.parse(videoUrl)),
)
// TODO: Legacy WebView on Web workarounds.
// (kIsWeb)
// ? Image.asset(
// "assets/images/video_thumbnail_learn_from_developers.png",
// fit: BoxFit.contain)
// HtmlElementView(
// key: webViewKey,
// viewType: webViewKey.toString(),
// )
: WebViewWidget(
key: webViewKey,
controller: WebViewController()
..loadRequest(Uri.parse(videoUrl)),
),
,
),
),
),
Expand Down Expand Up @@ -1246,8 +1246,6 @@ class _FlutterCodelabState extends State<FlutterCodelab>
final double videoAspectRatio = 1.75;

late Map<String, Widget> codelabExamples;
// TODO: Breaks mobile builds. Official Flutter WebView plugin is working on Web support.
HtmlElementView? codelabHtmlElementView;
UniqueKey webViewKey = UniqueKey();

@override
Expand Down Expand Up @@ -1295,24 +1293,19 @@ class _FlutterCodelabState extends State<FlutterCodelab>
padding: const EdgeInsets.fromLTRB(25, 16, 25, 16),
child: AspectRatio(
aspectRatio: videoAspectRatio,
child: (kIsWeb)
? Container(
decoration: BoxDecoration(
border: Border.all(
color: const Color(0xFFD3D3D3), width: 1),
borderRadius:
const BorderRadius.all(Radius.circular(0)),
),
child: HtmlElementView(
key: webViewKey,
viewType: codelabSelected,
),
)
: WebViewWidget(
key: webViewKey,
controller: WebViewController()
..loadRequest(Uri.parse(codelabUrlSelected)),
),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: const Color(0xFFD3D3D3), width: 1),
borderRadius:
const BorderRadius.all(Radius.circular(0)),
),
child: WebViewWidget(
key: webViewKey,
controller: WebViewController()
..loadRequest(Uri.parse(codelabUrlSelected)),
),
),
),
),
),
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.10.0"
webview_flutter_web:
dependency: "direct main"
description:
name: webview_flutter_web
sha256: "7f7cb8cfe5a5dee3b55d660a367c00838be56540ccb4097e84601bb6cb354af3"
url: "https://pub.dev"
source: hosted
version: "0.2.2+4"
webview_flutter_wkwebview:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
url_launcher: ^6.2.5
video_player: ^2.8.2
webview_flutter: ^4.7.0
webview_flutter_web: ^0.2.2+4
universal_html: ^2.2.4
google_fonts: ^6.1.0
responsive_framework:
Expand Down

0 comments on commit e410379

Please sign in to comment.