Flutter plugin instance with parameters

104 views
Skip to first unread message

Leoš Husar

unread,
Dec 28, 2021, 1:59:00 PM12/28/21
to Flutter Development (flutter-dev)
Hi! I am trying to make a plugin for authentication. It will act like a "wrapper" (but with additional functionality for each plugin) for different already existing packages for different platforms.

By the additional functionality I mean

  • Web implementation already has state management
  • Android implementation is AppAuth, so here I need to add my own state management

I am trying to use the PlatformInterface way, but I cannot find any guide how to make it instantiable with constructor params.

Let's say I have this code: link

This would work, but in my app I would like to do this:
final _keycloakAuth = KeycloakAuth(keycloakUrl: 'xxx', clientId: 'yyy');

If I simply tried to add params like this: link

I wouldn't be able to pass them inside the _setPlatform() method since this is static method.

Also KeycloakAuthAppAuth extends KeycloakAuth, so I would need to pass those parameters back and forth, like instantiate KeycloakAuth, this instantiates KeycloakAuthAppAuth which needs to pass those parameters back via super()...

Any tips for this?

I know I can make a method initialize({String keycloakUrl, String clientId}) with my parameters, but I would still like to know if it's possible to make it using the constructor.

Narendra N1

unread,
Dec 29, 2021, 1:20:55 AM12/29/21
to Flutter Development (flutter-dev)
please set a firstly   KeycloakAuthAppAuth instance of the main file then run. Project is run
Reply all
Reply to author
Forward
0 new messages