Skip to content
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

Improve material/cupertino builder design - Rename function #230

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dickermoshe
Copy link
Collaborator

@dickermoshe dickermoshe commented Jan 7, 2025

Part 1

Right now customizing the material theme based off of the shadcn theme is burden some.

  1. Some of the material theme is customized using the shadcn theme and there is no way to know what unless you read the source code.
  2. You don't have access to the final shad theme in the builder, ShadTheme.of(context) throws a null error

Instead of guessing, why not include the variable make the api more explicit.

Before

materialThemeBuilder: (context, theme) {
  return theme.copyWith(
      // Guess what you can't replace
    );
  },

After

materialThemeBuilder: ( 
  context,
  themeData,
  fontFamily,
   extensions,
  brightness,
  primaryColor,
  onPrimaryColor,
  secondaryColor,
  onSecondaryColor,
  errorColor,
  onErrorColor,
  backgroundColor,
  onBackgroundColor,
  surfaceColor,
  onSurfaceColor,
  scaffoldBackgroundColor,
  dividerTheme,
  textSelectionTheme,
) {
    return ThemeData(
      /// You now know what you're doing
    );
  },

What great about this, is that if you ever wanted to make the material theme more customized, you just add another parameter (e.g. tooltipTheme) and it will be a breaking release, instead of people wondering why their app compiles but things have changed.


Part 2

materialTextTheme was a lie, renamed it to applyGoogleFontToTextTheme

@nank1ro What are your thoughts?

@nank1ro
Copy link
Owner

nank1ro commented Jan 7, 2025

Part 1: in reality you can customise everything, but if you encounter a bug it could be how something has been customised by the user. The ThemeData returned by ShadApp does just some little things. Isn't too much to explicit every property when in reality you can change whatever you want? In addition, nothing stops you returning a different ThemeData object without accessing the other properties.
Finally, how long that function will be for the user? 🤯
Part 2: Fair, the name is more correct

@dickermoshe
Copy link
Collaborator Author

If you want to integrate shadcn with material you can't expect me to read through source code to see exactly how it does that.

A single, overridable function which clearly shows what parameters are overridden allows the developer to apply what he wants and add additional customizing without worrying about whether he's breaking something.

You could also fix this by documenting clearly what has been done to this themedata you are being handed

@nank1ro
Copy link
Owner

nank1ro commented Jan 7, 2025

I'll go with the documentation, that function will scary every developer, including me 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants