English 中文(简体)
• 如何在河道布道堤重建国家提供者
原标题:How to rebuild StateProvider in RiverPod Flutter

最近,我阅读了“罗伯特河国家管理”的情况,我开始在我的申请书中使用这一管理。 我在我Ui新闻复播台时,想提出一个随机的图像路径清单,我是一位国家提供者,从“不下”中获取随机路径清单。

final imgsPathsProvider = StateProvider<List<String>>((ref) {
  return List.generate(
      10,
      (index) =>
           https://source.unsplash.com/random/?night&${Random().nextInt(1000)} );
});

现在,在我要求复国时,我把这一供应商用在我的国家调查组中,这里是我的法典,它很好地发挥了作用:

 TextButton(
      onPressed: () {
        ref.read(imgsPathsProvider.notifier).update((state) {
          return List.generate(
              10,
              (index) =>
                  https://source.unsplash.com/random/?night&${Random().nextInt(1000)} );
        });
      },
      child: const Text( refresh ))

当我报章复述时,我想要重建供应商,以获得随机的图像清单,而不是重复该守则,我感到,像我破碎的德国南盟原则一样,这是一个非常简单的使用案例,因此,我使用的是国家提供人,而不是提名者,而我是否使用过诺蒂埃供应商,在要求复读时,如何界定一种方法,把它放在国际调查中? 或是否有任何方法重建我国的建国?

问题回答

更新职能将重建国家,但需要看到提供者这样做。

利用这一变量观察供应商,并利用这一变量来显示图像。

final images = ref.watch(imgsPathsProvider);

或者说,你可以以此来更新国家。

ref.read(imgsPathProvider.notifier).state = List.generate(
              10,
              (index) =>
                  https://source.unsplash.com/random/?night&${Random().nextInt(1000)} );
        });




相关问题
Is Form validation and Business validation too much?

I ve got this question about form validation and business validation. I see a lot of frameworks that use some sort of form validation library. You submit some values and the library validates the ...

Looping javascript get requests

I ve got a javascript 101 question. I m using a nice graphing library (flot), and plotting multiple graphs on a single page. Each graph is a div, with a attribute set that tells the graph where to ...

Django DRY URLs for Model access

Reader s Digest version: How do I get data (either single row if specified or full table) from a model by taking a URL argument of the model s name without hardcoding the URLconfs to match each model? ...

Drying up my rails models

I have a couple of models which share a has_many associations, named scopes and validations. What s the best way of drying these models up so they can share the same code? Create a parent class and ...

wpf DataGridTextColumn refactoring

I am using a DataGrid in a WPF app that has several (literally one for each day of the week) columns which differ only in their data index. A sample of the xaml is below. How can I refactor this into ...

Why isn t DRY considered a good thing for type declarations?

It seems like people who would never dare cut and paste code have no problem specifying the type of something over and over and over. Why isn t it emphasized as a good practice that type information ...

热门标签