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 MainModel extends Model { | |
final itemProvider = ItemProvider(); | |
List<Item> items; | |
Color detailedColor; // The color of the tapped card from the ListView | |
int detailedIndex; // The index of the tapped card from the ListView | |
getItems() async { | |
items = await itemProvider.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 MyScopedModelState extends State<MyScopedModel> { | |
MainModel mainModel; | |
void initState() { | |
super.initState(); | |
mainModel = MainModel(); | |
} | |
@override | |
Widget build(BuildContext 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 MainBloc { | |
final itemProvider = ItemProvider(); | |
final itemsConroller = StreamController<List<Item>>(); | |
final detailedColorConroller = StreamController<Color>(); | |
final detailedItemConroller = StreamController<Item>(); | |
Stream get itemsStream => itemsConroller.stream; | |
Stream get detailedColorStream => detailedColorConroller.stream; | |
Stream get detailedItemStream => detailedItemConroller.stream; |
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 MyHomePage extends StatefulWidget { | |
@override | |
MyHomePageState createState() { | |
return new MyHomePageState(); | |
} | |
} | |
class MyHomePageState extends State<MyHomePage> { | |
@override | |
void initState() { |
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:ui'; | |
import 'package:flutter/widgets.dart'; | |
import 'package:states_rebuilder/states_rebuilder.dart'; | |
import 'item.dart'; | |
import 'item_provider.dart'; | |
class MainBloc extends StatesRebuilder { | |
final itemProvider = ItemProvider(); |
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 MyHomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
children: <Widget>[ | |
Container( | |
padding: EdgeInsets.only(top: 10), | |
height: 150, | |
child: StateBuilder( |
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'; | |
class LoginFormModel { | |
final emailController = StreamController<String>(); | |
final passwordController = StreamController<String>(); | |
Function(String) get changeEmail => emailController.sink.add; | |
Function(String) get changePassword => passwordController.sink.add; | |
Stream<String> get email => emailController.stream.transform(validateEmail); |
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 LoginFormView extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Injector( | |
inject: [ | |
Inject(() => LoginFormModel()), | |
//get teh email stream and inject it as stream | |
Inject.stream(() => Injector.get<LoginFormModel>().email, | |
name: "emailStream"), |
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 FutureCounterWithError extends ChangeNotifier { | |
int _count = 0; | |
int get count => _count; | |
bool isLoaded = false; | |
bool hasError = false; | |
String errorMessage; | |
Future<void> increment() async { | |
isLoaded = false; |
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 Counter { | |
int _count = 0; | |
int get count => _count; | |
Future<void> increment() async { | |
await Future<void>.delayed(const Duration(seconds: 1)); | |
if (Random().nextBool()) { | |
throw CounterError('You have an error'); | |
} | |
_count++; |
OlderNewer