admin管理员组

文章数量:1125594

Do have an option to use a variable only once in condition and value in Dart? or do you Have any shortened solution.

Conditon:

final phoneHeight = PhoneSize.deviceHeight(context);

final sectionHeight=phoneHeight >=1000?phoneHeight*0.85:phoneHeight;

Do have an option to use a variable only once in condition and value in Dart? or do you Have any shortened solution.

Conditon:

final phoneHeight = PhoneSize.deviceHeight(context);

final sectionHeight=phoneHeight >=1000?phoneHeight*0.85:phoneHeight;
Share Improve this question edited 2 days ago Frank van Puffelen 598k84 gold badges887 silver badges858 bronze badges asked Jan 9 at 6:17 Palash DeyPalash Dey 841 silver badge8 bronze badges 1
  • I will just use if conditional statement which is much more readable – Md. Yeasin Sheikh Commented Jan 9 at 7:00
Add a comment  | 

1 Answer 1

Reset to default 1
final sectionHeight = switch(PhoneSize.deviceHeight(context)) {
  >= 1000 && final v => v * 0.85,
  final v => v,
};

本文标签: Is there any shorten solution for repeat var in ternary operator on dartStack Overflow