Flutter Webview页面下弹框

import 'package:flutter/material.dart';
import 'package:redenvelope/constant/colors.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
//二维码扫描插件
import 'package:flutter/services.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/rendering.dart';
import 'package:cool_ui/cool_ui.dart';
//文章详情界面
class WebViewtouzi extends StatefulWidget {
  String title;
  String url;
  var  actions;
  WebViewtouzi({
    Key key,
    @required this.title,
    @required this.url,
    @required this.actions,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return new WebViewPageState();
  }
}

class WebViewPageState extends State<WebViewtouzi> {

  bool isLoad = true;

  final flutterWebViewPlugin = new FlutterWebviewPlugin();

  @override
  void initState() {
    super.initState();
    flutterWebViewPlugin.onStateChanged.listen((state) {
      debugPrint('state:_' + state.type.toString());
      if (state.type == WebViewState.finishLoad) {
        // 加载完成
        setState(() {
          isLoad = false;
        });
      } else if (state.type == WebViewState.startLoad) {
        setState(() {
          isLoad = true;
        });
      }
    });
  }

  Container foot=  Container(child:Text(""));
  @override
  Widget build(BuildContext context) {
    return new WebviewScaffold(
      url: widget.url,
      appBar: new AppBar(
        backgroundColor: AppColors.colorAppBarBackground,
        elevation:0,
        centerTitle:true,
        /*actions: <Widget>[
          IconButton(
            icon:Icon(Icons.share,size:20) ,
            onPressed: (){
              print(123);
              setState(() {


                foot=new Container(
                  height: 200,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      SizedBox(height: 20,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: <Widget>[
                        Text('分享到',style: TextStyle(fontSize:16,color: Colors.deepOrange),),
                        FlatButton(
                            child: Text('取消',style: TextStyle(fontSize:16,color: Colors.black45),),
                            onPressed: () async {
                                setState(() {
                                  foot=  Container(child:Text(""));
                                });
                            }
                        ),
                        ]
                      ),

                      SizedBox(height: 40,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: <Widget>[
                          FlatButton(
                              child: Column(
                                children: <Widget>[
                                  Icon(FontAwesomeIcons.yenSign,color: Colors.orange,),
                                  SizedBox(height: 10,),
                                  Text("好友"),
                                ],
                              ),
                              onPressed: () async {

                              }
                          ),
                          FlatButton(
                              child: Column(
                                children: <Widget>[
                                  Icon(FontAwesomeIcons.weixin,color: Colors.lightGreen,),
                                  SizedBox(height: 10,),
                                  Text("微信"),
                                ],
                              ),
                              onPressed: (){

                              }
                          ),
                          FlatButton(
                              child: Column(
                                children: <Widget>[
                                  Icon(FontAwesomeIcons.alipay,color: Colors.blue,),
                                  SizedBox(height: 10,),
                                  Text("朋友圈"),
                                ],
                              ),
                              onPressed: (){

                              }
                          ),



                        ],
                      ),

                    ],
                  )
              );
              });
            },),

        ],*/
        leading: IconButton(
          icon:Icon(Icons.arrow_back_ios,size:20) ,
          onPressed: (){
            Navigator.pop(context);
          },),
        title: new Text(widget.title,
            style: new TextStyle(color: Colors.white,fontSize: 18)),

        bottom: new PreferredSize(
            preferredSize: const Size.fromHeight(1.0),
            child: isLoad
                ? new LinearProgressIndicator()
                : new Divider(
                    height: 1.0,
                    color: Theme.of(context).primaryColor,
                  )
        ),
      ),
      bottomNavigationBar:foot,
      withZoom: false,
      withLocalStorage: true,
      withJavascript: true,
    );
  }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要实现 Flutter WebView 页面自适应高度,可以使用 flutter_webview_plugin 插件。该插件提供了一个 onStateChanged 回调函数,可以监听 WebView 页面的状态改变。当页面加载完成后,可以获取 WebView 页面的高度,并将其应用到 WebView 上,从而实现自适应高度。 以下是一个简单的示例代码,演示如何实现 Flutter WebView 页面自适应高度: ```dart import 'package:flutter/material.dart'; import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; class MyWebView extends StatefulWidget { final String url; MyWebView({required this.url}); @override _MyWebViewState createState() => _MyWebViewState(); } class _MyWebViewState extends State<MyWebView> { double webViewHeight = 100.0; @override Widget build(BuildContext context) { return Scaffold( body: Container( height: webViewHeight, child: WebviewScaffold( url: widget.url, withZoom: false, withJavascript: true, withLocalStorage: true, hidden: true, initialChild: Container( color: Colors.white, child: Center( child: CircularProgressIndicator(), ), ), appBar: AppBar( title: Text('WebView Demo'), ), onStateChanged: (state) { if (state.type == WebViewState.finishLoad) { setState(() { webViewHeight = double.parse(state.height.toString()); }); } }, ), ), ); } } ``` 在上面的代码中,我们定义了一个 MyWebView 类,使用 WebviewScaffold 来渲染 WebView 页面。在 onStateChanged 回调函数中,我们监听 WebView 页面的状态改变,并在页面加载完成后获取 WebView 的高度,并将其应用到 WebView 上。这样,就可以实现 WebView 页面的自适应高度了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值