addState method

ButtonStyle addState({
  1. Color? backgroundColor,
  2. Color? foregroundColor,
  3. Set<MaterialState> state = const {MaterialState.focused, MaterialState.hovered, MaterialState.pressed, MaterialState.selected},
})

Implementation

ButtonStyle addState({
  Color? backgroundColor,
  Color? foregroundColor,
  Set<MaterialState> state = const {
    MaterialState.focused,
    MaterialState.hovered,
    MaterialState.pressed,
    MaterialState.selected,
  },
}) {
  return copyWith(
    backgroundColor: MaterialStateProperty.resolveWith((st) {
      if (st.containsAny(state)) {
        return backgroundColor ?? this.backgroundColor?.resolve(st);
      }
      return this.backgroundColor?.resolve(st);
    }),
    foregroundColor: MaterialStateProperty.resolveWith((st) {
      if (st.containsAny(state)) {
        return foregroundColor ?? this.foregroundColor?.resolve(st);
      }
      return this.foregroundColor?.resolve(st);
    }),
  );
}