This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc_pattern/bloc_pattern.dart'; | |
class ValueBloc extends BlocBase { | |
double value = 0.0; | |
onChangeValue(double v) { | |
value = v; | |
notifyListeners(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return BlocProvider( | |
blocs: [ | |
Bloc((i) => ValueBloc()), | |
], | |
child: MaterialApp( | |
title: 'Flutter Demo', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
Consumer<ValueBloc>( | |
builder: (BuildContext context, ValueBloc valueBloc) { | |
return _textValue(valueBloc.value); | |
}, | |
), | |
Container( | |
height: 25, | |
), | |
Consumer<ValueBloc>( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc_pattern/bloc_pattern.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:provider_test/src/value_bloc.dart'; | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
Consumer<ValueBloc>( | |
builder: (BuildContext context, ValueBloc valueBloc) { | |
return Text("Value: ${valueBloc.value.toStringAsPrecision(1)}", | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: 24, | |
fontWeight: FontWeight.bold, | |
), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ValueBloc extends BlocBase { | |
StreamController<double> _valueController = StreamController<double>(); | |
double value = 0.0; | |
onChangeValue(double v) { | |
value = v; | |
_valueController.add(value); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:bloc_pattern/bloc_pattern.dart'; | |
class ValueBloc extends BlocBase { | |
StreamController<double> _valueController = StreamController<double>(); | |
double value = 0.0; | |
//outputs | |
Stream<double> get valueOut => _valueController.stream; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ValueBloc valueBloc = BlocProvider.getBloc<ValueBloc>(); | |
... | |
StreamBuilder<String>( | |
stream: valueBloc.valueStringOut, | |
initialData: "", | |
builder: (context, snapshot) { | |
return Text(snapshot.data, | |
style: TextStyle( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc_pattern/bloc_pattern.dart'; | |
import 'package:flutter/material.dart'; | |
import 'value_bloc.dart'; | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HomeModule extends ModuleWidget { | |
//Inject the blocs | |
@override | |
List<Bloc<BlocBase>> get blocs => [ | |
Bloc((i) => HomeBloc())), | |
]; | |
//Inject the dependencies | |
@override |