edispatcher 1.0.1 copy "edispatcher: ^1.0.1" to clipboard
edispatcher: ^1.0.1 copied to clipboard

outdated

A tool class that is convenient for developers to implement event distribution

example/lib/main.dart

import 'package:edispatcher/edispatcher.dart';
import 'package:flutter/material.dart';

import 'random_model.dart';

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: HomePage(title: 'edispatcher Demo'),
    );
  }
}

class HomePage extends StatefulWidget {
  HomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with ESubscriber {
  RandomModel _random = RandomModel();
  String _randomText = "";

  @override
  void initState() {
    _random.onType<RandomNotifyEvent>(this, (event) {
      setState(() {
        _randomText = event.random;
      });
    });
    super.initState();
  }

  @override
  void dispose() {
    _random.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              onPressed: () {
                _random.random();
              },
              child: Text("random invoke"),
            ),
            SizedBox(
              height: 30,
            ),
            Text("random:$_randomText")
          ],
        ),
      ),
    );
  }
}
2
likes
40
pub points
0%
popularity

Publisher

verified publisheradeveloper.tech

A tool class that is convenient for developers to implement event distribution

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on edispatcher