PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 5, 2022

[FIXED] How to use .env in Flutter web?

 November 05, 2022     dart, environment-variables, flutter     No comments   

Issue

Short story:

I am trying to use .env file in my Flutter Web project.

I used flutter_dotenv before in Flutter mobile app but it is not working in Flutter web.

How can we use .env file in Flutter web?

Long Story:

For now, I am using dart file to save current constant values such as backend url.

Backend is in same domain like this => https://domain_for_webapp.com/api/

class Environment {

  // API URL
  static const String API_URL ='https://domain_for_webapp.com/api/';
...

But problem here is I have one more server to deploy same site https://another_domain_for_webapp.com/api/ So I tried to solve that by using relative url

class Environment {

  // API URL
  static const String API_URL ='/api/';
...

But Flutter web can't find correct full API url for each server.

To solve this I have been trying to use .env like in normal web app.

But I can't use .env in Flutter web.

Is there any proper solution for this problem?


Solution

Like mentioned here, you can rename your .env file to something that doesn't start with a dot. I've changed my .env file to "dotenv".



Answered By - Jonas Goebel
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing