0

How to give predetermine string value.

Something like this.

class Button extends StatelessWidget {
  final String type;
  const Button({
    this.type = 'raised' | 'text',
  });

}

That give me the error.

In constant expressions, operands of this operator must be of type 'bool' or 'int'.

How to give the parameter options to only be those predetermine string values.

Millenial2020
  • 2,465
  • 9
  • 38
  • 83

2 Answers2

0

Why do you want to create a button with a stateless widget? If you need to know the state of that button, you should create a stateful widget. I think you can refer to this navigation bar stateful example. (please ignore the title of the post) How to create a button navigation bar with a stateless widget in flutter?

0

Define an enum:

enum MyButtonType {
  raised,
  text
}


class Button extends StatelessWidget {
  final MyButtonType type;
  Button(this.type) {
     if (this.type==MyButtonType.raised) print("Raised Button");
  }
}
Andrija
  • 1,534
  • 3
  • 10