styled_widget
styled_widget copied to clipboard
name conflicts with the origin properties
.textWidthBasic() .textDirection() conflict with the origin same name properties

Flutter 2.13.0-0.2.pre • channel beta • https://github.com/flutter/flutter.git Framework • revision 8662e22bac (4 days ago) • 2022-04-20 08:21:52 -0700 Engine • revision 24a02fa5ee Tools • Dart 2.17.0 (build 2.17.0-266.5.beta) • DevTools 2.12.2
I would actually not recommend using methods for properties of Text since each method creates a new Text widget. If you have any suggestions for a solution, I would like to hear!
I would actually not recommend using methods for properties of Text since each method creates a new Text widget. If you have any suggestions for a solution, I would like to hear!
according dart document about const and here
If you can eventually generate a const Text(), there should be no runtime performance loss. But I don't think it can be reached unless dart modifies itself.
Cuz const in dart is not const as we understand it in other languages, I think it's better to think of it as a static block in memory, so it's understandable that it has so many restrictions, and any variables returned by method can't be a const, and for class constructor, it should be a pure data constructor ( with no body ), so you can't build a const copyWith(), because the compiling process doesn't execute any dart code.
So, how about fixing the known naming conflicts first? Otherwise, the alternative is to implement the code generator. But I personally hate code generator. I think it's a bit like introducing a big monster to fix a small flaw.
I agree. Don't want to deal with code generation if there are other alternatives. I have previously thought about creating a separate Text data class with non-mutable members. Then add a method for generating a text widget from the class.
StyledText("some text")
.bold()
.size(20)
.toText()
or something like that.
Btw i do not really prioritize development of this library at the moment. I am open for discussion but I won't make large changes in the near future. If you would like to contribute I would be more than happy to accept contributions.
Update: I learned this in an unrelated official video. If define a widget as a static final, can prevent it from rebuild, I guess this is the least expensive workaround so far
class Basic extends StatelessWidget {
const Basic({Key? key}) : super(key: key);
static final text = const Text(
'some text',
)
.textScale(1.5)
.italic()
.bold()
.fontWeight(FontWeight.w200)
.fontSize(20)
.fontFamily('sans-serif')
.letterSpacing(5.0)
.wordSpacing(20.0)
.textShadow(
color: Colors.black,
blurRadius: 10.0,
offset: const Offset(5.0, 5.0),
)
.textElevation(11)
.textColor(Colors.green);
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text,
],
);
}
}
that's an interesting approach!
But it is still somewhat unsatisfactory. It works well as long as the widget is final. If you later decide to include an animation on the text, its no longer as easy to include without impacting performance.
that's an interesting approach!
But it is still somewhat unsatisfactory. It works well as long as the widget is final. If you later decide to include an animation on the text, its no longer as easy to include without impacting performance.
This reminds me that there is a hookBuilder in flutter_hooks, which is the equivalent of a widget scope, that is used to solve the problem you mentioned, as ref