dart
dart copied to clipboard
How to ignore some extra transmit when using Henson.with()?
I have an destination Activity called DetailActivity, it has 3 filed which need to be injected:
@InjectExtra
String name = "default name";
@InjectExtra
int age = 0;
@Nullable
@InjectExtra
User user;
Another activity called MainActivity want to send data to DetailActiivty, but when use Henson, it force me to write following full code:
Henson.with(this)
.gotoDetailActivity()
.age(27)
.name("jason")
.user(user)
.build()
But I don't want to send age, when I write "Henson.with(this)", it then prompt me must be set to age().
So how can I ignore part extra? That means, Can I use Henson as following ? (I seems make error)
Henson.with(this) .gotoDetailActivity() .name("jason") .build()
Hi @soaringEveryday ,
According to the DetailActivity code:
nameandageare required- only
useris optional (@Nullable annotation)
Taking into account your requirements, age is optional and should be annotated with @Nullable.
By default, all annotated fields are required and an exception is thrown if the extra is not provided. To remove that check and make it optional, the @Nullable annotation needs to be added.
@dlemures Thank you for your post. But my confused point is that, how can I exchange the sequence of name and age on the DSL. The following code is pass: Henson.with(this) .gotoDetailActivity() .age(27) .name("jason") .user(user) .build()
but, following code is report error on IDE(firstly name then age, seems it force me to call age firstly): Henson.with(this) .gotoDetailActivity() .name("jason") .age(27) .user(user) .build()
extras are sorted by alphabetical order when the DSL is created. There is no easy to provide a custom order. The order of the extras declaration is not something stable enough and providing a custom ordering seems tricky. We decided to order them alphabetically and we believe it's not such a big deal compared to the power of Henson.
If you want to suggest an alternative way, we are open to study proposals and PRs.
2016-06-12 0:33 GMT-07:00 Jason Chan [email protected]:
@dlemures https://github.com/dlemures Thank you for your post. But my confused point is that, how can I exchange the sequence of name and age on the DSL. The following code is pass: Henson.with(this) .gotoDetailActivity() .age(27) .name("jason") .user(user) .build()
but, following code is report error on IDE(firstly name then age, seems it force me to call age firstly): Henson.with(this) .gotoDetailActivity() .name("jason") .age(27) .user(user) .build()
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/f2prateek/dart/issues/118#issuecomment-225414925, or mute the thread https://github.com/notifications/unsubscribe/ABv33S_h-pTWBC9HMukVqNDoz-85Gfgoks5qK7Y1gaJpZM4IxuDA .