aryehof / dart-eventsubscriber

A Flutter widget for subscribing to a Dart Event.
https://pub.dev/packages/eventsubscriber
Apache License 2.0
3 stars 0 forks source link

Version update of EventSubscriber #2

Closed Sjonnie2nd closed 1 month ago

Sjonnie2nd commented 1 month ago

First of all, I'm a big fan of your packages Event/Eventsubscriber No need for Provider/Riverpod or other relatively complex state handling mechanisms. I have no idea why your packages have not been promoted more..

Now I see Event has been updated to a new version (3.01), but Eventsubscriber's dependency has not been updated.

Is it easy for you to solve this?

aryehof commented 1 month ago

Hi, thanks for the kind comment. I hope to release v3 of EventSubscriber in the next day or two. Sorry for the delay.

aryehof commented 1 month ago

Version 3 has been released.

Sjonnie2nd commented 1 month ago

Thanx for your great work but..

I ran into an issue with extended EventArgs.

A simple project:

import 'package:event/event.dart';
import 'package:eventsubscriber/eventsubscriber.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class TextEventArgs extends EventArgs {
  String text;
  TextEventArgs(this.text);
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {

  Event<TextEventArgs> event = Event<TextEventArgs>();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              EventSubscriber(
                events: [ event ],
                builder: (context, status, args) {
                  return Text(args.text);
                }
              ),
              TextButton(
                onPressed: () => event.broadcast(TextEventArgs('Changed text')),
                child: const Text('Change text')
              )
            ],
          ),
        ),
      ),
    );
  }
}

Everything compiles fine but the initial loading breaks on eventsubscriber.dart:68 dart T _eventArgs = EventArgs() as T;

_TypeError (type "EventArgs" is not a subtype of type "TextEventArgs" in type cast)

In this example it's clear that there's no initial text property declared.

But in the earlier version the EventArgs in the builder function of EventSubscriber was optional so you could check for being null.

Am I doing something wrong here or?