सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
एक फ्लटर टेक्स्टफील्ड विजेट जो स्वतः ही अपने बाउंड्स के भीतर सामग्री के अनुरूप आकार में समायोजित होता है। यह उपयोगकर्ता द्वारा टाइप करते समय गतिशील रूप से टेक्स्ट फील्ड का आकार बदलता है, ओवरफ्लो या अत्यधिक सफेद स्थान के बिना आदर्श स्थान उपयोग सुनिश्चित करता है। निरंतर लेआउट और प्रतिक्रियाशील डिजाइन के लिए आवश्यक रूप से फॉर्म और इनपुट फील्ड के लिए आदर्श है। पैकेज एंड्रॉइड, आईओएस, वेब, मैकओएस, विंडोज और लिनक्स जैसे बहुत सारे प्लेटफॉर्म को समर्थन देता है, जिससे यह क्रॉस-प्लेटफॉर्म एप्लिकेशन के लिए लचीला बनता है। यह हल्का है और मौजूदा फ्लटर प्रोजेक्ट्स में आसानी से एकीकृत होता है।
उपयोग
डायनामिक फॉर्म इनपुट
प्रतिक्रियाशील टेक्स्ट एंट्री फ़ील्ड
क्रॉस-प्लेटफॉर्म UI सामंजस्य
स्वचालित रूप से समायोजित होने वाले इनपुट बॉक्स
हाथ से लेआउट समायोजनों को कम करना
मुख्य विशेषताएँ
सामग्री के आधार पर स्वचालित आकार बदलें
क्रॉस-प्लेटफॉर्म संगतता
Flutter के साथ निरंतर एकीकरण
सभी प्रमुख प्लेटफॉर्म का समर्थन करता है
आवश्यक विन्यास न्यूनतम
इनके लिए उपयुक्त
प्रतिक्रियाशील फॉर्म बना रहे विकासक
अनुकूलित इनपुट फ़ील्ड की आवश्यकता वाले एप्प्स
क्रॉस-प्लेटफॉर्म Flutter प्रोजेक्ट्स
UI डिज़ाइनर लेआउट की कुशलता पर ध्यान केंद्रित करते हैं
न्यूनतम बॉयलरप्लेट के लिए आवश्यक टेक्स्ट फ़ील्ड वाले प्रोजेक्ट्स
विचार योग्य बातें
जटिल लेआउट के लिए अतिरिक्त स्टाइलिंग की आवश्यकता हो सकती है
बहुत लंबे पाठ के साथ प्रदर्शन प्रभाव
मूल आकार के अलावा सीमित कस्टमाइज़ेशन
स्थिर आकार की आवश्यकताओं के लिए उपयुक्त नहीं
पिता कंटेनर की सीमाओं पर निर्भर करता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
Auto Size TextField
✍️ Flutter TextField widget that automatically resizes text field to fit perfectly within its bounds.
📢 Announcement:
🚒 ️️IMPORTANTv2.0.0 and above is for Flutter v3. For Flutter v2 and below, please continue to use v1.0.1
🚒 BREAKINGv2.2.0 Flutter v3.3 support: deprecated ToolbarOptionstoolbarOptions and added support of its replacement ContextMenuBuilder.
Use 2.1.1 instead if your AutoSizeTextField is still dependent on toolbarOptions.
Note: Kudos to @leisim! This work is inspired by his awesome lib Auto Size Text. Please check it out if you want to auto size the Flutter Text widget content.
Show some ❤️ and star the repo to support the project
TODO
[x] Update README.md to show examples of more use cases
Note:AutoSizeTextField needs bounded constraints to resize the text. More info here.
fullwidth (default value: true)
The fullwidth parameter extends the width of TextField to its parent's BoxContraints to occupy full width.
Set to false to let the width TextField determined by the width of the text.
maxLines
The maxLines parameter works like you are used to with the Text widget. If there is no maxLines parameter specified, the AutoSizeTextField only fits the text according to the available width and height.
The AutoSizeTextField starts with TextStyle.fontSize. It measures the resulting text and rescales it to fit within its bonds. You can however set the allowed range of the resulting font size.
With minFontSize you can specify the smallest possible font size. If the text still doesn't fit, it will be handled according to overflow. The default minFontSize is 12.
maxFontSize sets the largest possible font size. This is useful if the TextStyle inherits the font size and you want to constrain it.
The AutoSizeTextField will try each font size, starting with TextStyle.fontSize until the text fits within its bounds. stepGranularity specifies how much the font size is decreased each step. Usually, this value should not be below 1 for best performance.
If you want to allow only specific font sizes, you can set them with presetFontSizes.
If presetFontSizes is set, minFontSize, maxFontSize and stepGranularity will be ignored.
Controls how one widget replaces another widget in the tree.
textKey
Sets the key for the resulting Text widget
style*
If non-null, the style to use for this text
fullwidth
Default: true, It extends the width of TextField to its parent's BoxContraints to occupy full width. Set to false to let the width TextField determined by the width of the text.
minFontSize
The minimum text size constraint to be used when auto-sizing text. Is being ignored if presetFontSizes is set.
maxFontSize
The maximum text size constraint to be used when auto-sizing text. Is being ignored if presetFontSizes is set.
stepGranularity
The step size in which the font size is being adapted to constraints.
presetFontSizes
Predefines all the possible font sizes. Important:presetFontSizes have to be in descending order.
locale*
Used to select a font when the same Unicode character can be rendered differently, depending on the locale.
wrapWords
Whether words which don't fit in one line should be wrapped. Defaults to true to behave like Text.
overflowReplacement
If the text is overflowing and does not fit its bounds, this widget is displayed instead.
maxLines
An optional maximum number of lines for the text to span.
minWidth
An optional min width for input field. Only set it when fullwidth = false
Parameters marked with * behave exactly the same as in TextField.
The unlisted parameters behave exactly the same as TextField.
Performance
AutoSizeTextField is really fast. In fact, you can replace all your TextField widgets with AutoSizeTextField.
Nevertheless you should not use an unreasonable high fontSize in your TextStyle. E.g. don't set the fontSize to 1000 if you know, that the text will never be larger than 30.
If your font size has a very large range, consider increasing stepGranularity.
Troubleshooting
Missing bounds
If AutoSizeTextField overflows or does not resize the text, you should check if it has constrained width and height.
Because Row and other widgets like Container, Column or ListView do not constrain their children, the text will overflow.
You can fix this by constraining the AutoSizeTextField. Wrap it with Expanded in case of Row and Column or use a SizedBox or another widget with fixed width (and height).
Correct code:
Row(
children: <Widget>[
Expanded( // Constrains AutoSizeTextField to the width of the Row
child: AutoSizeTextField(
controller: _textEditingController,
maxLines: 1,
)
),
],
)
}
MinFontSize too large
AutoSizeTextField does not resize text below the minFontSize which defaults to 12.:
MIT License
Copyright (c) 2020Zhuoran LI
Permissionis hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Softwareis
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.