सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
Flutter के लिए एक कोड जनरेशन टूल जो pubspec.yaml में सूचीबद्ध संपत्तियों को स्कैन करके स्वचालित रूप से एक संसाधन वर्ग बनाता है, जैसे कि Android का R.java। यह प्रकार-सुरक्षित, संकलन-समय जाँच की रेफरेंस के साथ संपत्ति प्राप्त करने को सरल बनाता है, त्रुटियों को कम करता है और रखरखाव को बेहतर बनाता है। उत्पादित फ़ाइल चित्रों, फ़ॉन्ट और अन्य संपत्तियों के लिए संक्षिप्त, पढ़ने में आसान नाम प्रदान करती है, जिससे विभिन्न प्लेटफॉर्मों पर विकास कार्य प्रवाह को सुगम बनाया जाता है।
उपयोग
बड़े Flutter प्रोजेक्ट में संपत्ति प्रबंधन को सरल बनाना
गलत असेट पथ के कारण रनटाइम त्रुटियों को कम करना
एप्लिकेशन संसाधनों तक प्रकार-सुरक्षित पहुँच सक्षम करना
बिल्ड के दौरान संसाधन वर्ग उत्पादन को स्वचालित करना
संक्षिप्त संपत्ति रेफरेंस के साथ कोड पठनीयता में सुधार
मुख्य विशेषताएँ
pubspec.yaml से स्वचालित रूप से संसाधन क्लास उत्पन्न करता है
छोटे, स्पष्ट परिसंपत्ति नाम प्रदान करता है
प्रकार सुरक्षित संसाधन पहुँच
चित्रों, फॉन्ट और अन्य संसाधनों का समर्थन करता है
क्रॉस-प्लेटफॉर्म संगतता
इनके लिए उपयुक्त
Flutter ऐप में कई संपत्तियों के प्रबंधन करने वाले विकासकर्ता
संपत्ति से संबंधित बग को कम करना चाहने वाली टीमें
समान संपत्ति नामकरण प्रणाली की आवश्यकता वाले प्रोजेक्ट
स्वचालित संसाधन उत्पादन की आवश्यकता वाले बिल्ड पाइपलाइन्स बनाएं
बहुप्लेटफॉर्म लक्षित ऐप्स
विचार योग्य बातें
build_runner और निर्भरताओं की सेटअप की आवश्यकता होती है
जनरेट किए गए फ़ाइलों को हाथ से संपादित नहीं करना चाहिए
बिल्ड समय को थोड़ा बढ़ा सकता है
pubspec.yaml को सही तरीके से कॉन्फ़िगर करने की आवश्यकता है
कोड विश्लेषण उपकरण के साथ सबसे अच्छा उपयोग किया जाता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Automatically generate the dart file for pubspec.yaml
The purpose of this library is to help flutter developers
automatically generate asset corresponding dart files
to help developers release their hands from this meaningless job,
and the open source community has a lot of the same functionality.
This library is based on dartlang's build library.
dart pub global activate flutter_asset_generator
# or
dart pub global activate -s git https://github.com/fluttercandies/flutter_asset_generator.git
Run below commands:
fgen
or
fgen -s $flutter_project
Support options
Use $ fgen -h or $ fgen --help see usage document.
fgen -h
-w, --[no-]watch Continue to monitor changes after execution of orders.
(defaults to on)
-p, --[no-]preview Generate file with preview comments.
(defaults to on)
-o, --output Your resource file path.
If it's a relative path, the relative flutter root directory
(defaults to "lib/const/resource.dart")
-s, --src Flutter project root path
(defaults to ".")
-n, --name The class name for the constant.
(defaults to "R")
-h, --[no-]help Help usage
-d, --[no-]debug debug info
File name
Space, '.' and '-' in the path will be converted to _. @ will be converted to _AT_.
Because the two field names will be exactly the same.
Config file
The location of the configuration file is conventional.
Configuration via commands is not supported.
The specified path is fgen.yaml in the flutter project root directory.
The file is yaml format, every element is glob style.
The name of the excluded file is under the exclude node, and the type is a string array. If no rule is included, it means no file is excluded.
The include node is the name of the file that needs to be imported, and the type is a string array. If it does not contain any rules, all file are allowed.
In terms of priority, exclude is higher than include, in other words:
First import the file according to the include nodes, and then exclude the files.
Replacement Rules
File names can be replaced according to the configuration file as shown below: