top of page

Big Font Widget (Android): Adjust Your Phone Settings with One Tap



I have a Text widget and not sure why it seems to just have padding at the top and bottom even though I didn't set any in the code. This is from the default Flutter app, I just modified the font size.


Sometimes you get this in CSS where there is padding even though none was set but you can remove it simply with padding: 0 but I don't see how to do it here since I can't find a padding option for the Text widget.




Big Font Widget (Android)




For most fonts, setting height to 1.0 is not the same as omitting or setting height to null because the fontSize sets the height of the EM-square, which is different than the font provided metrics for line height.


Fonts have ascenders and descenders on some characters, and there's also en ascent line for special characters like the accent marker. That's why numbers are centered in the middle. That's not padding on Flutter side, but typography design(?). Maybe you could find a way to sort your issue, by looking for a font without ascenders and descenders.


The fontFamily - try commenting it out and see if you still have the same problem. If this is the reason and you absolutely must/want to use this specific font, I'm not sure what the fix is, apart from some horrible logic to stack widgets accordingly so that it looks like there's no padding.


Layout constraints from the parent Widgets - you only included the code of the Text widget, but if for example it's wrapped in an Expanded widget within a Column, that would also explain the extra height (possibly wrong assumption here because the text wouldn't center itself vertically by default anyway, but then there might be a DefaultTextStyle widget up in the hierarchy somewhere so still possible....)


I found that you can reduce the top padding by setting a TextStyle with a height lower than 1. The value required seems to depend on the font size and the text itself, as different characters have different heights.


You can also reduce the bottom padding by clipping the Text using a fixed size Container. This will also vary based on the font size and the text itself. Below is an example of using both of these to reduce the top and bottom padding to 0 for the text '0:00.00' of font size 72:


Try playing with line height of the text by setting height in style property. Height of the text is determined based on font size. It will multiply the font size and give you the space that will look like it has some padding. The line height of the text is also linked to the font itself, since every font has it own line height.


Each line here is progressively more opaque. The base color ismaterial.Colors.black, and Color.withOpacity is used to create aderivative color with the desired opacity. The root TextSpan for thisRichText widget is explicitly given the ambient DefaultTextStyle, sinceRichText does not do that automatically. The inner TextStyle objects areimplicitly mixed with the parent TextSpan's TextSpan.style.


By default, text will layout with line height as defined by the font.Font-metrics defined line height may be taller or shorter than the font size.The height property allows manual adjustment of the height of the line asa multiple of fontSize. For most fonts, setting height to 1.0 is notthe same as omitting or setting height to null. The following diagramillustrates the difference between the font-metrics-defined line height andthe line height produced with height: 1.0 (also known as the EM-square):


Leading is the vertical spacebetween glyphs from adjacent lines. Quantitatively, it is the line height(see the previous section) subtracted by the font's ascent and descent.It's possible to have a negative Leading if height is sufficientlysmall.


When the height multiplier is null, leading and how it is distributedis up to the font'smetrics.When the height multiplier is specified, the exact behavior can beconfigured via leadingDistribution and TextPainter.textHeightBehavior.


The leadingDistribution property controls how leading is distributed overand under the text. With TextLeadingDistribution.proportional(Configuration 1), Top Leading : Bottom Leading = Font Ascent : Font Descent, which also means the alphabetic baseline divides the line heightinto 2 parts proportional to the font's ascent and descent. WithTextLeadingDistribution.even (Configuration 3), Top Leading equalsBottom Leading, and the glyphs are roughly centered within the allottedline height.


The TextPainter.textHeightBehavior is a property that controls leading atthe paragraph level. The applyHeightToFirstAscent property is appliedafter height and leadingDistribution. Setting it to false trims the"Top Leading" of the text box to match the font's ascent if it's on thefirst line (see Configuration 2). Similarly settingapplyHeightToLastDescent to false reduces "Bottom Leading" to 0 for thelast line of text (Configuration 4).


link assignment Stack( children: [ // Stroked text as border. Text( 'Greetings, planet!', style: TextStyle( fontSize: 40, foreground: Paint() ..style = PaintingStyle.stroke ..strokeWidth = 6 ..color = Colors.blue[700]!, ), ), // Solid text as fill. Text( 'Greetings, planet!', style: TextStyle( fontSize: 40, color: Colors.grey[300], ), ), ],)


link assignment Text( 'Greetings, planet!', style: TextStyle( fontSize: 40, foreground: Paint() ..shader = ui.Gradient.linear( const Offset(0, 20), const Offset(150, 20), [ Colors.red, Colors.yellow, ], ) ),)


The family property determines the name of the font, which you can use inthe fontFamily argument. The asset property is a path to the font file,relative to the pubspec.yaml file. The weight property specifies theweight of the glyph outlines in the file as an integer multiple of 100between 100 and 900. This corresponds to the FontWeight class and can beused in the fontWeight argument. The style property specifies whether theoutlines in the file are italic or normal. These values correspond tothe FontStyle class and can be used in the fontStyle argument.


To use a font family defined in a package, the package argument must beprovided. For instance, suppose the font declaration above is in thepubspec.yaml of a package named my_package which the app depends on.Then creating the TextStyle is done as follows:


A package can also provide font files without declaring a font in itspubspec.yaml. These files should then be in the lib/ folder of thepackage. The font files will not automatically be bundled in the app, insteadthe app can use these selectively when declaring a font. Suppose a packagenamed my_package has:


In the following example, any glyphs not present in the font Raleway will be attemptedto be resolved with Noto Sans CJK SC, and then with Noto Color Emoji: link assignment const TextStyle( fontFamily: 'Raleway', fontFamilyFallback: [ 'Noto Sans CJK SC', 'Noto Color Emoji', ],)


A known example of this is that Samsung devices ship with a CJK font that hassmaller line spacing than the Android default. This results in Samsung devicesdisplaying more tightly spaced text than on other Android devices when nocustom font is specified.


Font sizes are calculated automatically by Flutter based on the OS setting.However, as a developer you should make sure your layout has enough room torender all its contents when the font sizes are increased.For example, you can test all parts of your app on a small-screendevice configured to use the largest font setting.


With the flag activated, the semantic nodes appear on top of the widgets;you can verify that the semantic elements are placed where they should be.If the semantic nodes are incorrectly placed, please file a bug report.


The Android app allows the user to create widgets on the home screen so the user can perform a variety of actions like execute a service call, display the state of an entity or even render a template. You can add the widget like you normally would for any app depending on your devices launcher. The widget will not work when Data Saver is enabled, you will also need to ensure that background data for the app is enabled. If you notice that a widget is no longer working try to recreate it. Widgets can also be edited by navigating to Settings > Companion App > Manage Widgets, if you are on Android 12 you can also edit the widget by long pressing it and clicking on the edit icon.


This widget will be updated when the entity state changes or when it is tapped. This widget will allow the user to select any entity they wish to get the state and an attribute from as well as setting the text size and adding a custom separator between the state and attributes.


This widget will let the user control any media player on their home screen and will be updated when the media player state changes or when the album art is tapped. There are a couple of options available to hide or show the seek and skip buttons.


This widget will make the service call when it is tapped. The user will see a green check mark if the call was successful and red if not. Red would indicate either the widget was not setup properly, the Home Assistant server is unavailable or some other error that would be indicated in the Home Assistant log.


This widget will display any text that you wish to show in a widget using Home Assistants templating feature. This is an advanced feature but allows the user to display a wide variety of data. The template will be updated instantly on relevant states changes. When editing the widget, the template will be shown below the text field so you can preview what it would look like.


If the template in the widget isn't updating instantly, you're most likely hitting rate limits. Try optimizing your template to get faster updates, or tap on the widget to update it manually. You can also use the preview in Developer Tools > Template to test your template updates.


BattStatt Pro is a free, open-source battery-level widget. Unlike the Text Battery Widget, BattStatt Pro is very customizable. It used to be the paid version of BattStatt Free, has since become free. You can change text style, color, size, capitalization, bold news. And set the widget tap action to show your battery info or usage screen. BattStatt Pro comes in three sizes and 8 languages. 2ff7e9595c


1 view0 comments

Recent Posts

See All

Comentários


bottom of page