You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After testing it looks like constants are not supported.
I would suggest this is a pretty important implementation detail otherwise we will be left to maintain matching constants list on both sides of the wire.
Support for static constants would seem fairly straight forward and solve a large class of problems (including obviating the short term need for enum support).
/// The collection of methods we use to call into the platform code.@HostApi()
abstractclassSoundsToPlatformApi {
/// The list of specific errors that can be passed from the platform to dart.staticconst errnoGeneral =1;
staticconst errnoUnsupportedCodec =2;
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.
Activity
bsutton commentedon Sep 24, 2020
After testing it looks like constants are not supported.
I would suggest this is a pretty important implementation detail otherwise we will be left to maintain matching constants list on both sides of the wire.
Support for static constants would seem fairly straight forward and solve a large class of problems (including obviating the short term need for enum support).
bsutton commentedon Oct 5, 2020
I have found a way to pass static constants through the api which avoid having to maintain mappings in the host code.
This is still fairly ugly but provides a work around until static consts are supported.
When creating an argument class:
class StartCar
{
int carId;
int mode;
int const_suv_mode;
int const_sports_mode;
}
You then need another 'helper' class.
class StartCardConsts
{
static const suv_mode = 1;
static const sports_mode = 2;
}
When constructing the argument class:
var args = StartCar();
args.carId = xx;
args.mode = StartCardConsts.suv_mode;
args.const_suv_mode = StartCardConsts.suv_mode;
args.const_sports_mode = StartCardConsts.sports_mode;
HostApi().startCar(args);
The resulting java/ios code will now have getters for each of the modes so you can write
serverplumber commentedon Aug 26, 2022
[-][pigeon] are constants supported.[/-][+][pigeon] Support static constant ints[/+][-][pigeon] Support static constant ints[/-][+][pigeon] Support static constant values[/+]kfieldi5 commentedon Apr 6, 2024
tarrinneal commentedon Jul 21, 2026
closed as fixed by flutter/packages#12032
github-actions commentedon Aug 4, 2026
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 -vand a minimal reproduction of the issue.