Skip to content

PageTurn + Flutter WebView #9

Description

@ggirotto

Hi guys. I'm trying to use your plugin with Flutter WebView to render an epub file. The problem is that it seems that the PageTurn plugin doesn't work as expected when using Flutter WebView. All the pages are blank when using them together. Below the example main.dart I'm running:

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:page_turn/page_turn.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  final _controller = GlobalKey<PageTurnState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageTurn(
        key: _controller,
        backgroundColor: Colors.white,
        showDragCutoff: false,
        lastPage: Container(child: Center(child: Text('Last Page!'))),
        children: <Widget>[
          for (var i = 0; i < 20; i++) WebViewWidget(),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.search),
        onPressed: () {
          _controller.currentState.goToPage(2);
        },
      ),
    );
  }
}

class WebViewWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final htmlExample = "<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
    return WebView(
        initialUrl: Uri.dataFromString(
              htmlExample,
              mimeType: 'text/html',
              encoding: Encoding.getByName('utf-8')
            ).toString(),
        javascriptMode: JavascriptMode.unrestricted,
        initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow,
      );
  }
}

And the pubspec.yaml:

name: page_turn_webview
description: A new Flutter project.

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # Webview
  webview_flutter: ^0.3.20+2
  page_turn: ^1.0.1


dev_dependencies:
  flutter_test:
    sdk: flutter

  uses-material-design: true

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions