0

I have a problem with the visualization of a web page with webview_flutter, I have to display a web view, when I run the code on ios the view is displayed correctly, when I run the same code on android I have a blank page, how do I solve this thing? To what it is due, I report below the source codes

Pubspec.yaml

ReportView.dart

import 'dart:io';

import 'package:appsafetyeurope/model/Manutenzione.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

String URLLOAD = "https://marconisoftware.com";

class ReportView extends StatefulWidget {
  final Manutenzione man;
  final String token;
  final String url;

  const ReportView(this.man, this.token, this.url);

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

class ReportViewState extends State<ReportView> {
  void _handleLoad(String value) {}

  @override
  void initState() {
    super.initState();
    // Enable virtual display.
    if (Platform.isAndroid) {
      //WebView.platform = SurfaceAndroidWebView();
      WebView.platform = AndroidWebView();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            leading: IconButton(
              icon: Icon(Icons.arrow_back_ios),
              iconSize: 20.0,
              onPressed: () {
                Navigator.pop(context);
              },
            ),
            centerTitle: true,
            title: Text('Report')),
        body: IndexedStack(
          index: 0,
          children: [
            Column(
              children: <Widget>[
                Expanded(
                    child: WebView(
                  javascriptMode: JavascriptMode.unrestricted,
                  onWebViewCreated: (WebViewController webViewController) {
                    Map<String, String> headers = {"Cmdbuild-authorization": widget.token};
                    webViewController.loadUrl(
                        widget.url +
                            "/services/rest/v3/reports/286763/Activity%20report.pdf?extension=pdf&parameters=%7B%22ProcessId%22%3A" +
                            widget.man.id.toString() +
                            "%7D",
                        headers: headers);
                  },
                  onPageFinished: _handleLoad,
                )),
              ],
            ),
            Container(
              color: Colors.white,
              child: Center(
                child: CircularProgressIndicator(),
              ),
            ),
          ],
        ));
  }
}
riki
  • 1,502
  • 5
  • 17
  • 45
  • Try [this](https://stackoverflow.com/a/63878200/1456151) too see what errors do you get. Also [this](https://stackoverflow.com/questions/54126511/how-to-fix-white-screen-in-webview-flutter) can be helpful, google `flutter webViewController android blank screen` – Doger Jun 14 '22 at 18:24
  • @Doger your solution not works – riki Jun 15 '22 at 06:37

0 Answers0