पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv0.2.0

flutter_env_native

एक प्लगइन/उपयोगिता जो मूल वेब प्लेटफॉर्म के लिए संकलन-समय चर प्रदान करती है।

AndroidiOS
30-दिन डाउनलोड
6.9 हज़ार
लाइक
37
Pub अंक
150

पैकेज इंस्टॉल करें

flutter pub add flutter_env_native

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

flutter_env_native एक Flutter प्लगइन है जो मूल Android और iOS प्लेटफॉर्म के लिए संकलन-समय चर का उपयोग करने की अनुमति देता है। यह विकासकर्ताओं को सुरक्षित रूप से ऐप के मूल कोड में वातावरण-विशिष्ट मानों—जैसे API कीज़ या कॉन्फ़िगरेशन फ्लैग—संकलन के दौरान एम्बेड करने की अनुमति देता है। इस दृष्टिकोण से संवेदनशील डेटा के रनटाइम उजागर को रोककर सुरक्षा में सुधार होता है। यह पैकेज मौजूदा Flutter प्रोजेक्ट्स के साथ बिना किसी दिक्कत के एकीकृत होता है और विशिष्ट बिल्ड-समय तंत्र के माध्यम से प्लेटफॉर्म-विशिष्ट कॉन्फ़िगरेशन का समर्थन करता है।

उपयोग

  • नेटिव बिल्ड में API कीज़ का सुरक्षित प्रबंधन
  • संकलन समय पर वातावरण-विशिष्ट सेटिंग्स को कॉन्फ़िगर करना
  • नेटिव प्लेटफॉर्म-विशिष्ट तर्क के साथ एकीकरण
  • रनटाइम सीक्रेट्स को कम करके ऐप सुरक्षा में सुधार करना
  • कई पर्यावरणों में डिप्लॉयमेंट को सरल बनाना

मुख्य विशेषताएँ

  • संकलन-समय चर प्रतिस्थापन
  • Android और iOS प्लेटफॉर्म के लिए समर्थन
  • कम रनटाइम सीक्रेट्स के माध्यम से सुधारित सुरक्षा
  • Flutter बिल्ड प्रक्रिया के साथ निरंतर एकीकरण
  • प्लेटफॉर्म-विशिष्ट कॉन्फ़िगरेशन हैंडलिंग

इनके लिए उपयुक्त

  • एप्लिकेशन सुरक्षा को प्राथमिकता देने वाले विकासकर्ता
  • कई डेप्लॉयमेंट परिवेशों का प्रबंधन करने वाली टीमें
  • मूल स्तर के विन्यास की आवश्यकता वाले प्रोजेक्ट
  • संवेदनशील प्रमाणिक उपयोग करने वाले ऐप्स
  • निर्धारक विन्यास की आवश्यकता वाले पाइपलाइन बनाएं

विचार योग्य बातें

  • मूल निर्माण कॉन्फ़िगरेशन की आवश्यकता है
  • केवल संकलन-समय के मूल्यों तक सीमित
  • गतिशील रनटाइम परिवर्तन के लिए उपयुक्त नहीं
  • बिल्ड कॉम्प्लेक्सिटी बढ़ सकती है
  • मूल प्रोजेक्ट फ़ाइल में सही सेटअप पर निर्भर करता है

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

flutter_env_native

pub package

A plugin/utility that provides compile-time variables for native platform.

This plugin/utility makes env variables set in --dart-define and --dart-define-from-file available to the native platforms.

🎖 Installing

dev_dependencies:
  flutter_env_native: ^0.2.0

🎮 Setup Guide

Define .env file

APP_NAME=batcave
APP_SUFFIX=.dev
MAPS_API_KEY=someKeyString

Pass .env file to flutter run/build via --dart-define-from-file=.env

[!WARNING] In iOS *.xcconfig has some limitations when it comes to variable values it treats the sequence // as a comment delimiter, then for example, https://example.com, will be https:// in the code, everything after // will be ignored. For solve omit the https:// while specifying the env variable and prepend the https:// in code, read more about the solution here.

Android Installation

:open_file_folder: android/app/build.gradle

:exclamation: DO NOT OMIT ANY OF THE FOLLOWING CHANGES :exclamation:

// flutter_env_native
+Project flutter_env_native = project(':flutter_env_native')
+apply from: "${flutter_env_native.projectDir}/envConfig.gradle"
Usage in android manifest file
:open_file_folder: android/app/src/main/AndroidManifest.xml:

:exclamation: DO NOT OMIT ANY OF THE FOLLOWING CHANGES :exclamation:

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "tech.mastersam.flutter_env_example"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName

+       resValue "string", "app_name", APP_NAME ?: 'default_name'
    }

The above create a string resource with variable app_name set to the value of APP_NAME

<application
        android:label="flutter_env_example"
+       android:name="@string/app_name"
        android:icon="@mipmap/ic_launcher">

The above sets the android:name to the value of app_name in the string resource. The same applies for other .xml files.

Usage in kotlin file
:open_file_folder: android/app/src/main/AndroidManifest.xml:

:exclamation: DO NOT OMIT ANY OF THE FOLLOWING CHANGES :exclamation:

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "tech.mastersam.flutter_env_example"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName

+       buildConfigField "String", "APP_NAME", "\"${APP_NAME ?: 'default_name'}\""
    }

The above creates the BuildConfig field APP_NAME and sets its value to the env variable APP_NAME where available and defaults it to 'default_name'

:open_file_folder: android/.../MainActivity.kt:

:exclamation: DO NOT OMIT ANY OF THE FOLLOWING CHANGES :exclamation:

package tech.mastersam.flutter_env_example

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

         // Access BuildConfig values
+        val appName = BuildConfig.APP_NAME

         // Sample usage to display a toast message
         Toast.makeText(this, "APP_NAME: $appName", Toast.LENGTH_LONG).show()
    }
}

iOS Installation

:open_file_folder: ios/Podfile

:exclamation: DO NOT OMIT ANY OF THE FOLLOWING CHANGES :exclamation:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end

+ flutter_env_plugin_path = File.join(Dir.pwd, '.symlinks', 'plugins', 'flutter_env_native', 'ios', 'setup_env.sh')
+ root_dir = File.expand_path('..', Dir.pwd)

+ # Run the setup_env.sh script from the plugin
+ system("sh \"#{flutter_env_plugin_path}\" \"#{root_dir}\"")
end
Usage in plist file
:open_file_folder: info.plist:

Reference the env variable directly as defined in the .env file

<key>CFBundleDisplayName</key>
<string>$(APP_NAME)</string>
Usage in swift file
:open_file_folder: AppDelegate.swift: (any swift file of choice)
+ var app_name: String = Bundle.main.infoDictionary?["APP_NAME"] as? String ?? ""
  NSLog("\nHere's your app name -> \(app_name)")

[!NOTE] Don't forget the env variable added in info.plist so you can access it in the swift file.

श्रेणियाँ

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट

अभी कोई डेटा उपलब्ध नहीं है।