listeners 1.0.0 copy "listeners: ^1.0.0" to clipboard
listeners: ^1.0.0 copied to clipboard

Ease state-management

example/listeners_example.dart

import 'package:listeners/listeners.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


class Application extends StatefulWidget {
  const Application({Key? key}): super(key: key);
  
@override
  _ApplicationState createState() => _ApplicationState();
}

class _ApplicationState extends State<Application> {
  int counter = 0;

  void onPressed(){
    counter++;
    listeners.update('counter');
  }
  
  @override
  void initState() {
    listeners.add('counter', this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) =>
    Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: <Widget>[
      Text('Counter $counter'),

      CupertinoButton(
        onPressed: onPressed,
        child:
        Text('+')
      )
    ]);
}


void main() async {
  runApp(CupertinoApp(
    debugShowCheckedModeBanner: false,
    home: 
    Container(
      color: Colors.white, 
      child: const Application()
    )
  ));
}
1
likes
130
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

Ease state-management

Repository (GitHub)
View/report issues

Topics

#state

Documentation

API reference

License

MIT (license)

More

Packages that depend on listeners