registerExtensions method
void
registerExtensions()
Registers the extensions. Call once, before runApp.
Implementation
void registerExtensions() {
GuestExtensions.register('ext.flutterware.knobs', (_, _) async {
return developer.ServiceExtensionResponse.result(
jsonEncode(describe().toJson()),
);
});
GuestExtensions.register('ext.flutterware.setKnobs', (_, args) async {
// A service extension's arguments are strings, so the payload is JSON in
// one of them rather than a map of typed values.
var payload = jsonDecode(args['payload'] ?? '{}') as Map<String, dynamic>;
var applied = applyAll(payload.cast<String, Object?>());
// Answered only once the demo has rebuilt on it. Turning a knob can
// reveal or retire another, so a reply that came back before the frame
// would leave the panel asking what to show and being told about the
// build it had just replaced — intermittently, depending on whether the
// frame beat the next request, which is worse than being wrong.
//
// Bounded because this is an RPC a panel waits on: a guest that has
// stopped drawing should make the panel late, not stuck.
if (applied) {
await WidgetsBinding.instance.endOfFrame.timeout(
const Duration(seconds: 2),
onTimeout: () {},
);
}
return developer.ServiceExtensionResponse.result(
jsonEncode({'applied': applied}),
);
});
}