-1

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 1

5

The source code for all of the widgets is freely accessible. In my opinion, the best approach depends on:

  1. how much of the core functionality do you want to change?
  2. 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 :)

Sign up to request clarification or add additional context in comments.

3 Comments

When i subclass a widget its build method never gets called? Why is this so? This makes overriding the build method impossible :/
When you overrode build, did you remember to call super(...)? See stackoverflow.com/questions/13272035/… for examples.
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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.