What is the best way to customize flutter (cupertino styled) widgets? I want to customize the cupertino tab bar with some animations, ... Should I extend the widget and override the build method and implement my stuff there, should I copy the whole widget, ... Any best practices?
Asked
Active
Viewed 1,596 times
1 Answers
5
The source code for all of the widgets is freely accessible. In my opinion, the best approach depends on:
- how much of the core functionality do you want to change?
- how important is the aspect to your app?
If you are changing a lot then I would suggest you start from scratch or use the existing code as a base. Whether you subclass or start from "scratch" you'll still probably end up doing maintenance yourself so whatever route makes sense over time is probably the best one (only you know which one).
In general, it's OK to copy + paste the class/code into your app directly and modify it if you want to do something custom. That's why it is open source.
If it is something that could be useful to other people you could then consider doing a PR or writing a custom control for other people to use :)

Luke
- 6,388
- 3
- 26
- 35
-
When i subclass a widget its build method never gets called? Why is this so? This makes overriding the build method impossible :/ – C. Mürtz May 10 '18 at 16:33
-
When you overrode `build`, did you remember to call `super(...)`? See https://stackoverflow.com/questions/13272035/how-do-i-call-a-super-constructor-in-dart for examples. – Randal Schwartz May 10 '18 at 20:02
-
Yes :D The super constructor gets called but the overriden build method never gets called... Seems like all widgets need to be a subclass of stful or stless widget? – C. Mürtz May 11 '18 at 03:25