Skip to content

Instantly share code, notes, and snippets.

View jacobaraujo7's full-sized avatar

Jacob Moura jacobaraujo7

View GitHub Profile
//avaliable in Dart 2.13
typedef ProductList = List<Product>;
class ProductStore extends StreamStore<Exception, ProductList> {
final ProductRepository repository;
Counter({required this.repository}): super([]);
fetchProduct() async {
class Counter extends StreamStore<Exception, int> {
Counter(): super(0)
increment(){
update(state + 1);
}
}
# backup
docker run -v [volume]:/volume --rm loomchild/volume-backup backup - > [backupfile.tar.bz2]
# restore
cat [backupfile.tar.bz2] | docker run -i -v [volume2]:/volume --rm loomchild/volume-backup restore -
class HomePage extends StatelessWidget {
final counter = RxNotifier<int>(0);
_increment() => counter.value++;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Counter')),
class HomePage extends StatelessWidget {
final counter = ValueNotifier<int>(0);
_increment() => counter.value++;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Counter')),
class Computed<T> extends ChangeNotifier implements ValueNotifier<T> {
final List<Listenable> values;
final T Function() resolver;
Listenable listenable;
T _value;
Computed(this.values, {this.resolver}) {
listenable = Listenable.merge(values)..addListener(_listener);
}
class MyGuard extends RouteGuard {
@override
Future<bool> canActivate(String path, ModularRoute router) async {
if (path == '/admin') {
return await UserService().isAdmin();
} else {
return true;
}
}
}
// StartPage
@override
Widget build(BuildContext context) {
return Scaffold(
// Nested Pages
body: RouterOutlet(),
// bottomBar
bottomNavigationBar: BottomNavigationBar(
@override
final List<ModularRoute> routes = [
...
ChildRoute('/start', child: (_, args) => StartPage(), children: [
ModuleRoute('/home', module: HomeModule()),
ChildRoute('/config', child: (_, args) => ConfigPage()),
ChildRoute('/perfil', child: (_, args) => PerfilPage()),
]),
];
@override
final List<ModularRoute> routes = [
ChildRoute('/', child: (_, args) => HomePage()),
ChildRoute('/details/:id',
child: (_, args) => DetailsPage(id: args?.params?['id'])),
];