Created
June 19, 2019 21:05
-
-
Save gladson/31a51b13acba25c8e055dec9ea269b14 to your computer and use it in GitHub Desktop.
This file contains 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
@override | |
Widget build(BuildContext context) { | |
final SubTotalBloc subTotalBloc = BlocProvider.getBloc<SubTotalBloc>(); | |
return BlocProvider( | |
blocs: [ | |
Bloc((i) => SubTotalBloc()), | |
], | |
child: Container( | |
child: ListView.builder( | |
itemCount: widget.products.length, | |
itemBuilder: (context, index) { | |
return | |
Padding( | |
padding: EdgeInsets.only(top:10, bottom: 10, left: 0, right: 0), | |
child: Card( | |
elevation: 5, | |
child: Container( | |
height: 225, | |
child: Row( | |
children: <Widget>[ | |
Expanded( | |
child: Container( | |
height: double.infinity, | |
child: Padding( | |
padding: EdgeInsets.only(top:2, bottom: 0, left: 10, right: 0), | |
child: Column( | |
children: <Widget>[ | |
Padding( | |
padding: EdgeInsets.only(top: 0, bottom: 10, left: 0, right: 10), | |
child: | |
SizedBox( | |
width: double.infinity, | |
height: 60, | |
child: FlatButton( | |
child: Text( | |
"ADICIONAR", | |
style: TextStyle( | |
fontSize: 30, | |
fontWeight: FontWeight.bold | |
), | |
), | |
color: Colors.deepOrangeAccent[400], | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(10.0), | |
), | |
onPressed: () { | |
subTotalBloc.increment(double.parse(widget.products[index].pvenda.replaceAll(",", "."))); | |
}, | |
) | |
) | |
) | |
], | |
), | |
), | |
), | |
) | |
], | |
), | |
), | |
), | |
); | |
}, | |
) | |
), | |
); | |
} |
This file contains 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'; | |
import 'package:rxdart/rxdart.dart'; | |
class SubTotalBloc extends BlocBase { | |
SubTotalBloc(); | |
var _subtotalController = BehaviorSubject<double>.seeded(0.0); | |
//saida | |
Stream<double> get outSubTotal => _subtotalController.stream; | |
//entrada | |
Sink<double> get inSubTotal => _subtotalController.sink; | |
increment(double value) { | |
inSubTotal.add(_subtotalController.value + value); | |
} | |
decrement(double value) { | |
inSubTotal.add(_subtotalController.value - value); | |
} | |
@override | |
void dispose() { | |
_subtotalController.close(); | |
super.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment