skip to Main Content
<!DOCTYPE html>
<html>

<head>
    <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    This is a placeholder for base href that will be replaced by the value of
    the `--base-href` argument provided to `flutter build`.
  -->
    <base href="">

    <meta charset="UTF-8">
    <meta content="IE=Edge" http-equiv="X-UA-Compatible">
    <meta name="description" content="A new Flutter project.">

    <!-- iOS meta tags & icons -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="afri_pro">
    <link rel="apple-touch-icon" href="icons/Icon-192.png">

    <title>AfriPro</title>
    <link rel="manifest" href="manifest.json">
    <link rel="stylesheet" type="text/css" href="splash/style.css">

    <script src="https://unpkg.com/[email protected]/bin/canvaskit.js"></script>
    <link rel="preload" href="https://unpkg.com/[email protected]/bin/canvaskit.wasm" as="fetch" crossOrigin="anonymous">
</head>
<style>
    .loading {
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0;
        position: absolute;
        top: 50%;
        left: 50%;
        -ms-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
    }
    
    .loader {
        border: 16px solid #f3f3f3;
        border-radius: 50%;
        border: 15px solid;
        border-top: 16px solid blue;
        border-right: 16px solid white;
        border-bottom: 16px solid blue;
        border-left: 16px solid white;
        width: 120px;
        height: 120px;
        -webkit-animation: spin 2s linear infinite;
        animation: spin 2s linear infinite;
    }
    
    @-webkit-keyframes spin {
        0% {
            -webkit-transform: rotate(0deg);
        }
        100% {
            -webkit-transform: rotate(360deg);
        }
    }
    
    @keyframes spin {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }
</style>

<body style="position: fixed; inset: 0px; overflow: hidden; padding: 0px; margin: 0px; user-select: none; touch-action: none; font: 14px sans-serif; color: red;">
    <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->


    <!--  <div class="loading">-->
    <!--    <div class="loader"></div>-->
    <!--  </div>-->

    <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js"></script>
    <script>
        
        };


        // Initialize Firebase
        firebase.initializeApp(firebaseConfig);
    </script>
    <!--  <script src="firebase-messaging-sw.js"></script>-->
    <script>
        if ("serviceWorker" in navigator) {
            window.addEventListener("load", function() {
                navigator.serviceWorker.register("/firebase-messaging-sw.js");
            });
        }
    </script>
    <script type="text/javascript">
        let useHtml = "html";
        if (useHtml) {
            window.flutterWebRenderer = "html";
        } else {
            window.flutterWebRenderer = "canvaskit";
        }
    </script>
    <script>
        var serviceWorkerVersion = '1941516564';
        var scriptLoaded = false;

        function loadMainDartJs() {
            if (scriptLoaded) {
                return;
            }
            scriptLoaded = true;
            var scriptTag = document.createElement('script');
            scriptTag.src = 'main.dart.js';
            scriptTag.type = 'application/javascript';
            document.body.append(scriptTag);
        }

        if ('serviceWorker' in navigator) {
            // Service workers are supported. Use them.
            window.addEventListener('load', function() {
                // Wait for registration to finish before dropping the <script> tag.
                // Otherwise, the browser will load the script multiple times,
                // potentially different versions.
                var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
                navigator.serviceWorker.register(serviceWorkerUrl)
                    .then((reg) => {
                        function waitForActivation(serviceWorker) {
                            serviceWorker.addEventListener('statechange', () => {
                                if (serviceWorker.state == 'activated') {
                                    console.log('Installed new service worker.');
                                    loadMainDartJs();
                                }
                            });
                        }
                        if (!reg.active && (reg.installing || reg.waiting)) {
                            // No active web worker and we have installed or are installing
                            // one for the first time. Simply wait for it to activate.
                            waitForActivation(reg.installing || reg.waiting);
                        } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
                            // When the app updates the serviceWorkerVersion changes, so we
                            // need to ask the service worker to update.
                            console.log('New service worker available.');
                            reg.update();
                            waitForActivation(reg.installing);
                        } else {
                            // Existing service worker is still good.
                            console.log('Loading app from service worker.');
                            loadMainDartJs();
                        }
                    });

                // If service worker doesn't succeed in a reasonable amount of time,
                // fallback to plaint <script> tag.
                setTimeout(() => {
                    if (!scriptLoaded) {
                        console.warn(
                            'Failed to load app from service worker. Falling back to plain <script> tag.',
                        );
                        loadMainDartJs();
                    }
                }, 4000);
            });
        } else {
            // Service workers not supported. Just drop the <script> tag.
            loadMainDartJs();
        }
    </script>
    <picture id="splash">
        <source srcset="splash/img/light-1x.png 1x, splash/img/light-2x.png 2x, splash/img/light-3x.png 3x, splash/img/light-4x.png 4x" media="(prefers-color-scheme: light) or (prefers-color-scheme: no-preference)">
        <source srcset="splash/img/dark-1x.png 1x, splash/img/dark-2x.png 2x, splash/img/dark-3x.png 3x, splash/img/dark-4x.png 4x" media="(prefers-color-scheme: dark)">
        <img class="center" src="splash/img/light-1x.png" />
    </picture>
</body>

</html>

i am done building my app on VsCode with Flutter, after I had run without debugging on chrome browser it works perfectly fine.

These are the steps i took.

  1. I try to run the flutter build webcommand it builds.
  2. After building, i copy the build/web files to my Cpanel folder named after the url
  3. It works but doesn’t load completely unlike when it ran on my chrome on debug mode.

I’ll paste the snippet of my index.html

This is the content of the build folder uploaded

The content of the build folder i uploaded

This is what i have tried:

  1. Editing the <base href="/"> to <base href="/subfolder containing the files">
  2. Comparing the old version files to this, i don’t really see any significant difference.

What would be the problem guys?

NB: The previous version of the app works fine but when i upload the new version i get this bug.

2

Answers


  1. Chosen as BEST ANSWER

    I have fixed this!

    I found out by inspecting the page on my google chrome that the file .env was not found (Error 404), and these is where the most important configs for firing up my web app was.

    So i took the below steps

    Steps:

    1. I renamed the env file name in my build/web/assets folder from ".env" to "dotenv".
    2. In my "main.dart.js" file, i had to use CMD + F to find the ".env" keyword and then rename it to "dotenv".

    After doing this i had to clear my browser cache and reloaded my app, and it was firing again after over 5 days of looking for a solution!!!


  2.   <base href="">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search