我正在将 Riverpod 与 Freezed Union 一起使用。
我正在尝试合并/观察两个FutureProviders都返回相同类型的两个StateNotifierProvider并使用它们来设置状态。
我注意到,因为我正在观察两个 futureProviders,所以它创建了两个实例StateNotifierProvider......
从日志记录中我可以看到 init 方法被调用两次,clocking state被调用两次,DPS state被调用一次。
我在第一个障碍上失败了,但我的希望是:
我意识到下面的示例没有实现计时器,但我需要找出 StateNotfierProvider 的问题,然后我将继续添加暂停等。
老实说,我什至不确定这是正确的做事方式吗?
我考虑过也许为小部件中的每个未来提供者设置两个消费者,但这似乎有点麻烦。如果我可以在州立提供商中管理多个未来的提供商,那就太好了。
final clockingState = StateNotifierProvider<ClockingNotifier, ClockingState>(
(ref) => ClockingNotifier(
ref.watch(loadingItineraryProvider), ref.watch(clockingDps)));
class ClockingNotifier extends StateNotifier<ClockingState> {
final AsyncValue<ClockingState> itineraryState;
final AsyncValue<ClockingState> clockingDps;
ClockingNotifier(this.itineraryState, this.clockingDps)
: super(ClockingState.init()) {
init();
}
void init() {
logger.d("the init method");
itineraryState.whenData((ClockingState clockingState) {
logger.d("clocking state");
state = clockingState;
});
clockingDps.whenData((ClockingState dps) { …Run Code Online (Sandbox Code Playgroud) 我有一个类似下面的项目列表,我想使用 room.log 输入到数据库中。
data class MyRotasDayItem(
@PrimaryKey
@SerializedName("id")
val id: Long,
@SerializedName("date")
val date: String,
@Embedded
@SerializedName("dayEvents")
val dayEvents: List<SealedObj>
)
Run Code Online (Sandbox Code Playgroud)
但是我似乎无法添加 dayEvents。即使我创建了类型 List 我得到...实体和 POJO 必须有一个可用的公共构造函数我是否必须使用类型转换器?
如果列表中的 Type 是一个包含其他数据对象的 Sealed 类,例如...
sealed class MySealedExample(
open val foo: Long,
open val bar: Long
) {
@PrimaryKey(autoGenerate = true)
var id: Int = 0
@Entity
data class AnExample1(
@Ignore override val foo: Long,
@Ignore override val bar: Long,
val something:String
) : MySealedExample(foo, bar)
@Entity
data class AnExample2(
@Ignore override val …Run Code Online (Sandbox Code Playgroud) 我编写了一些提供 aApiService到 a 的代码StateNotifier。依赖ApiService于authenticatorclient- 身份验证客户端必须异步创建,因为它使用共享首选项来获取令牌。
我只是想弄清楚他们是否是我写这篇文章的更优雅的方式。基本上,当服务 apiService 被注入到 StateNotifier 中时,它可能可以为空......对我来说,这有点代码味道。
简而言之,这就是我正在做的事情...使用 aFutureProvider来实例化RestClientaDio
authenticatorClient = FutureProvider<RestClient>((ref) async {
final prefs = await SharedPreferences.getInstance();
final dio = Dio();
...
return RestClient(dio);
}
Run Code Online (Sandbox Code Playgroud)
然后我观看并使用 MaybeWhen 返回服务
final clientCreatorWatchProvider = Provider<ApiService?>((ref) => ref
.watch(authenticatorClient)
.whenData((value) => ApiService(value))
.maybeWhen(
data: (service) => service,
orElse: () => null,
));
Run Code Online (Sandbox Code Playgroud)
所以我不喜欢的是 orElse 返回 null
然后我的StateNotifier就在看...
final AppState = StateNotifierProvider<AppNotifier, String>(
(ref) => …Run Code Online (Sandbox Code Playgroud) 我创建了一个应用程序,将航路点绘制到 Google 地图上,然后使用 API 显示每个航路点的根目录和导航。
但我想设计每个路径点的样式......特别给每个路径点一个独特的标题。您可以在添加标记时执行此操作,但我看不到对航路点执行此操作。
有什么解决方法或者我错过了什么吗?
只是想知道是否有人在使用firebase auth ui 4.2.0
当我使用 startActivityForResult
我得到错误了...
E / AuthUI:发生登录错误。
com.firebase.ui.auth.FirebaseUiException:保存凭据时出错。在com.firebase.ui.auth.viewmodel.smartlock.SmartLockHandler $ 1.onComplete(SmartLockHandler.java:98)
看起来与smartlock有关,
我看过一些关于git的评论,这似乎是在以前的版本中发生的,但据说已在4.2中修复
还有其他人看到吗?
我正在使用相对较新的Facebook图形API.我正在获取使用该应用的朋友列表和他们的个人资料照片.
我不知道如何修改我发送的参数,以便返回的图片很大.当前返回的默认值是小的.
我正在使用newMyFriendsRequest.
我发送它的parms看起来像这样......
Bundle parameters = new Bundle();
parameters.putString("fields", "picture,name");
request.setParameters(parameters);
request.executeAsync();
Run Code Online (Sandbox Code Playgroud)
不知道如何将parm添加到该请求,以便返回给我的图片很大.
有人可以帮忙吗?
android ×3
flutter ×2
riverpod ×2
android-room ×1
facebook ×1
firebase ×1
firebaseui ×1
google-maps ×1