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
class CatalogState { | |
CatalogState({ | |
@required this.repository, | |
}); | |
// | |
final CatalogRepository repository; | |
List<Item> items = []; | |
Future<CatalogState> getItems() async { | |
items = await repository.fetchItems(); |
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
class _MyListItem extends StatelessWidget { | |
final Item item; | |
_MyListItem(this.item, {Key key}) : super(key: key); | |
//with states_rebuilder you can get the current them without BuildContext | |
final textTheme = RM.theme.textTheme.headline6; | |
void _displaySnackBar() { | |
//with states_rebuilder you can get the active ScaffoldState without |
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
class MyCatalog extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: WhenRebuilder<CatalogState>( | |
// Create a new ReactiveModel and subscribe to this WhenRebuilder | |
// and invoke getItems method. | |
// | |
observe: () => RM.get<CatalogState>().future( | |
(CatalogState s, Future<CatalogState> _) => s.getItems(), |
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
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Injector( | |
inject: [ | |
// Inject the CatalogState. |
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
@immutable | |
class CartState { | |
CartState({this.items}); | |
// List of items in the cart. | |
final List<Item> items; | |
/// The current total price of all items. | |
int get totalPrice => | |
items.fold(0, (total, current) => total + current.price); |
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
@immutable | |
class CatalogState { | |
CatalogState({ | |
@required this.repository, | |
@required this.items, | |
}); | |
// | |
final CatalogRepository repository; | |
final List<Item> items; |
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
class Comments extends StatelessWidget { | |
final int postId; | |
Comments(this.postId); | |
@override | |
Widget build(BuildContext context) { | |
return Injector( | |
//NOTE1: Inject CommentsService | |
inject: [Inject(() => CommentsService(api: Injector.get()))], | |
builder: (context) { |
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
class PostPage extends StatelessWidget { | |
PostPage({this.post}); | |
final Post post; | |
//NOTE1: Get the logged user | |
final user = Injector.get<AuthenticationService>().user; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: backgroundColor, |
NewerOlder