Last updated:
0 purchases
klutter ui
Flutter Widgets to be used in conjunction with the klutter plugin.
Full support for:
MethodChannel
EventChannel
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,
);
copied to clipboard
Using the function as a tearoff requires just a single line of code:
TextButton(onPressed: foo, child: Text("Click"))
copied to clipboard
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;
}
copied to clipboard
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")),
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.