flutter webview 用于展示协议

发布时间:2022-05-24 22:16:38

在应用中都需要展示协议,于是就想到Webview,

项目地址:https://pub.dev/packages/webview_flutter

引入依赖

webview_flutter: ^3.0.4

展示协议的代码:

import 'package:giftbook/base/DeviceConstant.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'dart:core';

import 'base/DeviceConstant.dart';

class Protocol extends StatefulWidget {
  const Protocol({Key? key}) : super(key: key);

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

class ProtocolPageState extends State<Protocol> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    // Clean up the focus node
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    String initUrl=DeviceConstant.androidUrl;
    if(!DeviceConstant.isAndroid){
      initUrl=DeviceConstant.iosUrl;
    }
    return Scaffold(
      appBar: AppBar(
        title: const Text("隐私协议"),
      ),
      body:  WebView(
        initialUrl:initUrl,
      ),
      //bottomNavigationBar 方便返回操作
      bottomNavigationBar: TextButton( onPressed: () {
        Navigator.of(context).pop();
      }, child: const Text("返回"),),
    );
  }
}


Card image cap
应用宝
Card image cap
APP STORE
Card image cap
应用宝
Card image cap
小米