Skip to content

Instantly share code, notes, and snippets.

View marcossevilla's full-sized avatar
🦄

Marcos Sevilla marcossevilla

🦄
View GitHub Profile
import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:translator/l10n/l10n.dart';
// To parse this JSON data, do
//
// final translation = translationFromJson(jsonString);
/// * si usamos Riverpod
void main() => runApp(ProviderScope(child: MyApp()));
...
final userStateNotifierProvider = Provider<UserStateNotifier>(
(_) => UserStateNotifier();
);
/// * si usamos Provider
void main() => runApp(
StateNotifierProvider<UserStateNotifier, UserState>(
create: (_) => UserStateNotifier(),
child: MyApp(),
),
);
...
class UserStateNotifier extends StateNotifier<UserState> {
// usamos super para crear nuestro estado inicial,
// igual que en Bloc
UserStateNotifier() : super(UserNotLogged());
// cambiamos el estado asignando uno nuevo
void logIn(User user) => state = UserLogged(user: user);
}
abstract class UserState { }
class UserNotLogged extends UserState { }
class UserLogged extends UserState {
UserLogged({@required this.user});
final User user;
}
# * si usas Provider
provider: ^4.3.3
state_notifier: ^0.6.0
flutter_state_notifier: ^0.6.1
# * si usas Riverpod, ya integra state_notifier
flutter_riverpod: ^0.12.2
# usa las dependencias más recientes o
# las que sean compatibles con tu proyecto
Container(height: 100, width: 100, color: ColorName.justBlack);
Assets.images.background.image();
class API {
static const url = 'url_to_my_api.dev/api';
}
Future callToAPI() async {
await http.get(API.url);
}
Future anotherCallToAPI() async {
await http.get('${API.url}/other');
Text(
'Esto es usando las fuentes con FlutterGen',
style: TextStyle(fontFamily: FontFamily.googleSans),
);