gpt4 book ai didi

Riverpod what to name enum types used in Providers?(Riverpod如何命名提供者中使用的枚举类型?)

转载 作者:bug小助手 更新时间:2023-10-28 11:30:01 25 4
gpt4 key购买 nike



Let's say I have an enum that defines the sorting mode in the UI

假设我有一个枚举,它定义了UI中的排序模式


enum SortType {
name,
date,
location,
}

I would like to have a riverpod Notifier that stores the current sorting mode

我想要一个存储当前排序模式的RiverPod通告程序


@riverpod
class SortType extends _$SortType {
@override
SortType build() {
return SortType.date;
}

void switchType(SortType type) {
state = type;
}
}

This causes a rather silly naming conflict. Of course, I could not name the enum and the riverpod Class the same way but I would like the enum to keep the intuitive name and the notifierProvider to also have a nice autogenerated name that is sortTypeProvider

这导致了一个相当愚蠢的命名冲突。当然,我不能用相同的方式命名enum和riverpod Class,但我希望enum保留直观的名称,并且notifierProvider也有一个很好的自动生成的名称sortTypeProvider


What is the best way to achieve this?

实现这一目标的最佳方式是什么?


更多回答

I'd call the enum SortingMode, and the provider CurrentSortingMode

我会调用枚举SortingMode和提供程序CurrentSortingMode

优秀答案推荐
更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com