Giter Site home page Giter Site logo

glourencosilva / simple_bloc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from everton-e26/simple_bloc

0.0 0.0 0.0 3.1 MB

A simple alternative to the BLoC implementation created in Dimension C-137

License: MIT License

Dart 87.01% Kotlin 1.68% Swift 4.64% Objective-C 0.44% Shell 6.24%

simple_bloc's Introduction



A simple alternative to the BLoC implementation created in Dimension C-137

Getting started

You should ensure that you add the simple_bloc as a dependency in your flutter project.

read more at how to install

Usage

Simple BLoC for counter app

class CounterBloc extends Bloc {
  //define the controller
  final _counterController = BlocController<int>(initalData: 0);

  //output
  Stream<int> get counterOut => _counterController.stream;

  //action
  Action get increment => _counterController.action((value) {
        //implement your business logic here
        return ++value;
      });

  @override
  void dispose() {
    //dispose your controller
    _counterController.dispose();
  }
}

Screen Widget

import 'package:flutter/material.dart';
import 'package:simple_bloc/simple_bloc.dart';
import 'counter_bloc.dart';

class CounterScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //get bloc form provider
    final bloc = BlocProvider.of<CounterBloc>(context);
    return Scaffold(
      appBar: AppBar(
        title: Text("Simple BLoC"),
      ),
      body: Center(
        //consume output
        child: StreamBuilder(
          stream: bloc.counterOut,
          builder: (_, snapshot) {
            return Text(snapshot.data.toString());
          },
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        //call bloc action
        onPressed: bloc.increment,
      ),
    );
  }
}

checkout app source at github

simple_bloc's People

Contributors

everton-e26 avatar termnal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.