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?
1 Answer
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 :)
3 Comments
build, did you remember to call super(...)? See stackoverflow.com/questions/13272035/… for examples.