新路线[webview]未全高显示

时间:2019-02-23 09:11:46

标签: dart flutter

webview上按一行后,我正在将应用程序屏幕导航到listview。我创建了两个routes,它已经从webview正确导航到listview

但是webview的高度与设备屏幕的高度不匹配,即,当我热重新加载应用程序时,它在屏幕下方显示了先前的路线(listview)。 webview没有覆盖。

下面是我的main.dart文件。

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:connectivity/connectivity.dart';
import 'package:toast/toast.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

void main() => runApp(new MyApp());
bool isData = false;

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Shop App',
      theme
          : new ThemeData(
          primaryColor: Color.fromRGBO(58, 66, 86, 1.0), fontFamily: 'Raleway'),
      home: MyHomePage(title: 'Shop App'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;


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

class _MyHomePageState extends State<MyHomePage> {

  List<bool> inputs = new List<bool>();
  List list = List();
  var isLoading = false;
  var connectivityResult;
  _fetchJSON() async {
    setState(() {
      isLoading = true;
    });
    var response = await http.get(
      'http://indiagovt.org/android/flutter.php',
      headers: {"Accept": "Application/json"},
    );
    if(response.statusCode == 200) {
      list = json.decode(response.body) as List;
      setState(() {
        isLoading = false;
      });
    } else {
      print('Something went wrong');
    }
  }

  @override
  void initState() {
    super.initState();
    setState(() {
      _fetchJSON();
    });
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
      appBar: new AppBar(
        title: new Text('Shop App'),
      ),
      body: isLoading ? Center (
        child: CircularProgressIndicator(),
      ):
          new ListView.builder(
          itemCount: list.length,
          itemBuilder: (BuildContext context, int index){
              return new Card(
                child: new Container(
                  padding: new EdgeInsets.all(10.0),
                  child: new Column(
                    children: <Widget>[
                      new ListTile(
                        title: new Text(list [index]['title']),
                        subtitle: new Text(list [index]['descr']),
                        leading: CircleAvatar(
                          child: Image.network(
                            list [index]['icon'],
                          ),
                        ),
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => webView(url: list[index]['link'], title: list[index]['name']),//goes to the next page & passes value of url and title to it
                            ),
                          );
                        },
                      )
                    ],
                  ),

                ),
              );
          }
      ),
    );
  }
}

class webView extends StatelessWidget {
  final String url;
  final String title;
  webView({Key key, @required this.url, @required this.title}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
        appBar: AppBar(
          title: Text(title),
        ),
        body: new MaterialApp(
          routes: {
            "/": (_) => new WebviewScaffold(
              url: url,
              appBar: new AppBar(

              ),
              withJavascript: true,
              withLocalStorage: true,

            )
          },
        )
    );
  }

}

应用截图: Home Screen/ ListView Screenshot WebView屏幕截图: WebView Screenshot

请帮助我解决此问题。

0 个答案:

没有答案