https://github.com/buijs-dev/klutter-dart-ui
Flutter widgets for Klutter.
https://github.com/buijs-dev/klutter-dart-ui
eventchannel flutter klutter methodchannel widgets
Last synced: 3 months ago
JSON representation
Flutter widgets for Klutter.
- Host: GitHub
- URL: https://github.com/buijs-dev/klutter-dart-ui
- Owner: buijs-dev
- License: mit
- Created: 2023-03-23T18:45:52.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-17T13:15:36.000Z (about 1 year ago)
- Last Synced: 2025-01-21T21:46:49.994Z (4 months ago)
- Topics: eventchannel, flutter, klutter, methodchannel, widgets
- Language: Dart
- Homepage:
- Size: 579 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://pub.dev/publishers/buijs.dev/packages)
[](https://github.com/buijs-dev/klutter-dart-ui/blob/main/LICENSE)
[](https://pub.dev/packages/klutter_ui)
[](https://codecov.io/gh/buijs-dev/klutter-dart-ui)
[](https://codescene.io/projects/38075)
Flutter Widgets to be used in conjunction with the [klutter plugin](https://github.com/buijs-dev/klutter-dart).
Full support for:- [MethodChannel](#MethodChannel)
- [EventChannel](#EventChannel)## MethodChannel
Example function which invokes method foo on the given channel and returns a String value.```dart
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(
state: state,
event: "foo",
channel: _channel,
onSuccess: onSuccess,
onFailure: onFailure,
);
```Using the function as a tearoff requires just a single line of code:
```dart
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.```dart
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 {
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.
```dart
Counter(builder: (res) => Text("$res")),
```