GitHub license pub codecov CodeScene Code Health

buijs software logo

Flutter Widgets to be used in conjunction with the klutter plugin. Full support for:

MethodChannel

Example function which invokes method foo on the given channel and returns a String value.

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:klutter_ui/klutter_ui.dart';

const MethodChannel _channel =
    MethodChannel('foo.bar.plugin/channel/my_simple_controller');

void foo({
  State? state,
  void Function(String)? onSuccess,
  void Function(Exception)? onFailure,
}) =>
    doEvent<String>(
      state: state,
      event: "foo",
      channel: _channel,
      onSuccess: onSuccess,
      onFailure: onFailure,
    );

Using the function as a tearoff requires just a single line of code:

TextButton(onPressed: foo, child: Text("Click"))

EventChannel

Example implementation of a Subscriber (statefull widget) which subscribes to a channel and updates it state everytime a new counter value is received.

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:klutter_ui/klutter_ui.dart';

const _stream = EventChannel('foo.bar.plugin/channel/counter');

class Counter extends Subscriber<int> {
    const Counter({
      required Widget Function(int?) builder,
      Key? key,
    }) : super(
      builder: builder,
      channel: _stream,
      topic: "counter",
      key: key,
    );
    
    @override
    int decode(dynamic json) => json as int;
}

All that is required to use the returned data is to wrap any widget with the Counter widget and then use it's value.

Counter(builder: (res) => Text("$res")),

Libraries

klutter_ui
Flutter widgets to be used in conjunction with the klutter plugin.