Home > Blockchain >  I'm working on a flutter web project ,when i run in localhost it is working fine but after depl
I'm working on a flutter web project ,when i run in localhost it is working fine but after depl

Time:11-28

<!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`.
  -->


  <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="futurek">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png" />

  <title>futurek</title>
  <link rel="manifest" href="manifest.json">
</head>

<body>
  <!-- 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 -->
  <script>
    var serviceWorkerVersion = null;
    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>
  <script type="module">
    // Import the functions you need from the SDKs you need
    import { initializeApp } from "https://www.gstatic.com/firebasejs/9.14.0/firebase-app.js";
    import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.14.0/firebase-analytics.js";
    // TODO: Add SDKs for Firebase products that you want to use
    // https://firebase.google.com/docs/web/setup#available-libraries

    // Your web app's Firebase configuration
    // For Firebase JS SDK v7.20.0 and later, measurementId is optional
    const firebaseConfig = {
      apiKey: "AIzaSyCOmHqx7WK_DfPNEwdmGVPhwlGjqPvb3eo",
      authDomain: "final-gpkart22nov2022.firebaseapp.com",
      projectId: "final-gpkart22nov2022",
      storageBucket: "final-gpkart22nov2022.appspot.com",
      messagingSenderId: "331850581676",
      appId: "1:331850581676:web:47e15890971bd243e04109",
      measurementId: "G-TYBCD278ZL"
    };

    // Initialize Firebase
    const app = initializeApp(firebaseConfig);
    const analytics = getAnalytics(app);
  </script>
</body>

</html>

i above mentioned index.html file and here is my git repository link of project https://github.com/AbhiEntrepreneur/26nov_firebaseBlank

I am working on a flutter web project , after developing in vs code when i run in localhost it is working fine but after deploying in firebase on main domain it is showing white blank page on main url (Please help me out to resolve this issue ) ****

CodePudding user response:

copy and paste this outside your main(){} or any other file. for me it was like lib/src/data/helpers/constants.dart

const String apikey = "AIzaSyCOmHqx7WK_DfPNEwdmGVPhwlGjqPvb3eo";
const String authDomain = "final-gpkart22nov2022.firebaseapp.com";

// const String databaseURL =
//     "https://your_app_default_database.firebaseio.com"; 
//uncomment above line and copy your realtime database url from 
//firebase console if you are using realtime database.

const String projectId = "final-gpkart22nov2022";
const String storageBucket = "final-gpkart22nov2022.appspot.com";
const String messagingSenderId = "331850581676";
const String appId = "1:331850581676:web:47e15890971bd243e04109";

final Future<FirebaseApp> firebaseInitialization = 
Firebase.initializeApp(
 options: const FirebaseOptions(
apiKey: apikey,
authDomain: authDomain,
// databaseURL: databaseURL, 
//uncomment above line if you are using realtime database

projectId: projectId,
storageBucket: storageBucket,
messagingSenderId: messagingSenderId,
appId: appId,
  ),
);

Now from your main()

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  setPathUrlStrategy();  // using package -> url_strategy: ^0.2.0
  //this is for removing the "#" sign from the url

  await firebaseInitialization;
  runApp(const MyApp());
 }

CodePudding user response:

Have you ran this in terminal in your project directory:

flutter build web

Then hosted the web folder in the build folder?

  • Related