Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageTurn + Flutter WebView #9

Open
ggirotto opened this issue Aug 17, 2020 · 0 comments
Open

PageTurn + Flutter WebView #9

ggirotto opened this issue Aug 17, 2020 · 0 comments

Comments

@ggirotto
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant