Flutter webview的定制化


目前我有一个需求,就是开发一个新闻APP,类似于头条,有新闻的展示,用户的评论和点赞、收藏等等,这个后端接口已经设计好了,这个功能主要通过访问url使用webview来实现该功能,一言不合就开始撸代码了:

  • 加载flutter webview插件
  • 定制化webview的显示界面
  • 对官方插件的二次定制
  • 完成对url的加载监听

1. 加载flutter webview插件

flutter_webview_plugin: ^0.3.0+2

2. 定制化webview的显示界面

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZZKov487-1660268716054)(https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c955e9a094b74537a4b2f17ec18b84da~tplv-k3u1fbpfcp-watermark.image)]

本页面主要由三部分组成,最上面那部分是flutter的原生页面,中间部分是webview页面,最下方是由bottomNavigationBar组件实现,如代码所示。

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
          title: Text('网页详情'),
          leading: IconButton(
            icon:Icon(Icons.arrow_back_ios,size:20) ,
            onPressed: (){
              _webviewReference.hide();
              String url = 'http://www.appshuo.club/appview/p/';
              MyRouter.pushNoParams(context, MyRouter.homePage);
            },),
          bottom: PreferredSize(
            child: _progressBar(lineProgress, context),
            preferredSize: Size.fromHeight(0.1),
          )
      ),
      body: SafeArea(
      child:  SingleChildScrollView(
              child: Padding(
          padding: EdgeInsets.all(10),
      child: Column(
          children: [
            Padding(
              padding: EdgeInsets.only(bottom: 10),
             child:Row(
              children: [
                CircleAvatar(
                  radius: 20.0,
                  backgroundImage: NetworkImage(widget.article.user.photo),
                  backgroundColor: Colors.white,
                ),
                Padding(
                  padding: const EdgeInsets.only(left: 10.0),
                  child: Text(widget.article.user.nickname),
                ),
                Padding(
                  padding: const EdgeInsets.only(left: 15.0),
                  child: Text('阅读',style: TextStyle(color: Colors.black38,fontSize: 13.0)),
                ),
                Padding(
                  padding: const EdgeInsets.only(left: 3.0),
                  child: Text('${widget.article.readcount}',style:
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值