-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify tab size in Text widget #50087
Comments
I checked this (trying to figure out if this is actually an easy fix) and my conclusion is that this is probably not done in the framework (cc @VladyslavBondarenko) - the framework label might still make sense because we would certainly need a new parameter in the framework (probably inside of In that case, I would also argue this is not an easy fix @TahaTesser because it touches the fundamentals of how text is not only painted but also laid out, i.e. currently the string is just passed as-is to the native This makes me conclude that tabs are handled by Skia internally and we would either need to hack it (by replacing with spaces), expose the configuration options if they exist, or implement this in the engine (or even in Skia) altogether. Please point out if I am missing something obvious; this seems like a very useful feature. |
Is there any progress on this feature? |
CC @loic-sharma |
Hello, thanks for creating this issue!
This is correct. Today, platform-specific code tries to convert the tab into a glyph during text shaping. As a result, how tabs are rendered depends on your font and your platform. As part of #79153, we plan to introduce some tab processing logic into Skia to make this behavior consistent across platforms. However, we haven't started proper support for things like tab stop or tab size customization. This is definitely not an easy fix. As a hacky workaround before we fix this, you can consider pre-processing text and replacing tabs with the desired amount of spaces. Something like: import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Text(_processText('#\tTab in Text')),
),
),
);
}
String _processText(String text) {
return text.replaceAll('\t', ' ');
}
} |
Hi, is there any parameter to specify tab size in text widget such as
Text
andRichText
?Seems it is 8 by default. In some cases developers may want to specify it as 4 or 2, for example code synatx highlighting lib, like the
tab-size
prop in CSSScreenshot
Reproduce steps
Paste the code below to https://dartpad.dev/flutter
The text was updated successfully, but these errors were encountered: