Coder Social home page Coder Social logo

Comments (3)

FusoraTech avatar FusoraTech commented on June 9, 2024

Sadly, as you noticed, it can't be manually adjusted, the script at dev/tools/gen_defaults/bin/gen_defaults.dart should be modified to be smart enough to omit such kind of redundancy.

A better result for this segment of code could be:

  @override ButtonStyle? get style {
    return ButtonStyle(
      textStyle: MaterialStatePropertyAll<TextStyle?>(Theme.of(context).textTheme.labelLarge),
      backgroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
        // if (states.contains(MaterialState.disabled)) {
        //   return null;
        // }
        if (states.contains(MaterialState.selected)) {
          return _colors.secondaryContainer;
        }
        return null;
      }),
      foregroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
        if (states.contains(MaterialState.disabled)) {
          return _colors.onSurface.withOpacity(0.38);
        }
        if (states.contains(MaterialState.selected)) {
          // if (states.contains(MaterialState.pressed)) {
          //   return _colors.onSecondaryContainer;
          // }
          // if (states.contains(MaterialState.hovered)) {
          //   return _colors.onSecondaryContainer;
          // }
          // if (states.contains(MaterialState.focused)) {
          //   return _colors.onSecondaryContainer;
          // }
          return _colors.onSecondaryContainer;
        } else {
          // if (states.contains(MaterialState.pressed)) {
          //   return _colors.onSurface;
          // }
          // if (states.contains(MaterialState.hovered)) {
          //   return _colors.onSurface;
          // }
          // if (states.contains(MaterialState.focused)) {
          //   return _colors.onSurface;
          // }
          return _colors.onSurface;
        }
      }),

from flutter.

TahaTesser avatar TahaTesser commented on June 9, 2024

Hi @YukiAttano
As @FusoraTech mentioned, this is generated from gen_defaults.

While the values might look similar, the tokens used to generate these values are quite different. This ensures regardless of the token value, we're generating colors specified in the specs. This is important if the token value database is updated the generated code will produce correct colors based on overlay states.

overlayColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
if (states.contains(MaterialState.pressed)) {
return ${_stateColor(tokenGroup, 'selected', 'pressed')};
}
if (states.contains(MaterialState.hovered)) {
return ${_stateColor(tokenGroup, 'selected', 'hover')};
}
if (states.contains(MaterialState.focused)) {
return ${_stateColor(tokenGroup, 'selected', 'focus')};
}
} else {
if (states.contains(MaterialState.pressed)) {
return ${_stateColor(tokenGroup, 'unselected', 'pressed')};
}
if (states.contains(MaterialState.hovered)) {
return ${_stateColor(tokenGroup, 'unselected', 'hover')};
}
if (states.contains(MaterialState.focused)) {
return ${_stateColor(tokenGroup, 'unselected', 'focus')};
}
}
return null;
}),

I believe this is working as design. please refer to the gen_defaults for more details on the tokens and their values.

from flutter.

github-actions avatar github-actions commented on June 9, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

from flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.