iT邦幫忙

2023 iThome 鐵人賽

DAY 28
0
自我挑戰組

基礎學習Flutter系列 第 28

Day28-webView資料(記錄)

  • 分享至 

  • xImage
  •  
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebViewStack extends StatefulWidget {
  const WebViewStack(required this.controller,key? key]) :super(key: key);

final WebViewController> controller;

  @override
  State<WebViewStack> createState() => _WebViewStackState();
}

class _WebViewStackState extends State<WebViewStack> {
  var loadingPercentage = 0;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        WebViewWidget(
        initialUrl; 'https;//flutter.dev',
        onwebViewCreated: (webViewController) {
          widget.controller.complete(webViewController);
          },
           onProgress: (progress) {
          setState(() {
            loadingPercentage = progress;
          });
        },
        onPageFinished: (url) {
          setState(() {
            loadingPercentage = 100;
          });
        },
      ),
    );
    // ...to here.
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        WebViewWidget(
          controller: widget.controller,                     // MODIFY
        ),
        if (loadingPercentage < 100)
          LinearProgressIndicator(
            value: loadingPercentage / 100.0,
          ),
      ],
    );
  }
}
          controller: controller,
        ),
        if (loadingPercentage < 100)
          LinearProgressIndicator(
            value: loadingPercentage / 100.0,
            minheight: 30
            color: Colors.yellow
          ),
      ],
    );
  }
}

上一篇
Day27-webView資料(記錄)
下一篇
Day29-navigation_controls資料(記錄)
系列文
基礎學習Flutter30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言