/var/log/messages

Apr 6, 2019 - 1 minute read - Comments - programming

flutter で WebView

試してみました。戻るボタンの click event はどうやって捕まえるのかな。とりあえず実装控えを以下に。

ios/Runner/info.plist

以下を末端に追加。

    <key>io.flutter.embedded_views_preview</key>
    <string>YES</string>
</dict>
</plist>

pubspec.yaml

webview_flutter な記述を追加。

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  webview_flutter: ^0.1.0+1

dev_dependencies:
  flutter_test:
    sdk: flutter

lib/main.dart

import の追加。表示横固定分も追加。

mport 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';

以下は横固定な記載です。

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    // Set landscape orientation
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight,
    ]);
    return MaterialApp(
      title: 'Flutter Demo',

あるいは webview の表示部分が以下。

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: WebView(
        initialUrl: 'https://flutter.io',
        javaScriptMode: JavaScriptMode.unrestricted,
      ),

back button

何かわかれば追記します。

追記

とりあえず、以下な実装で誤魔化せてる風ですが若干微妙。

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
        centerTitle: true,
        leading: new IconButton(
          icon: new Icon(Icons.arrow_back, color: Colors.orange),
          onPressed: () => _webViewController.goBack(),
        ),
      ),
      body: WebView(
        initialUrl: 'https://flutter.io',
        javaScriptMode: JavaScriptMode.unrestricted,
        onWebViewCreated: (WebViewController webViewController) {
          _webViewController = webViewController;
        },
      ),

どうしたものか。

phoenix excersize (6) phoenix excersize (7)

comments powered by Disqus