7
0

【小ネタ】riverpod_lintのassist紹介

Posted at

YUMEMI Flutter Advent Calendar 2023 11日目の記事です。

はじめに

特にriverpod_generatorと併用すると便利なriverpod_lintですが、lintの他にいくつかのassistが含まれているので紹介します。

assist紹介

Widgetの変換

StatelessWidgetやStatefulWidgetなどを相互に変換できます。
この機能はriverpod_generatorを使っていなくても恩恵を受けられます。

image.png

HookWidgetなどはflutter_hooksの依存があるときしか候補に表示されないようになってます。

ProviderScope、Consumerでのラップ

ScopedProviderのoverrideなどに使うProviderScope、リビルド範囲を制御するときなどに使うConsumerをすぐに使えます。
この機能もriverpod_generatorを使っていなくても恩恵を受けられます。

image.png

関数ProviderとクラスベースProviderの変換

関数ProviderとクラスベースのProviderを変換できます。
これまでと違い、riverpod_generator向けの機能です。

導入方法

ここまで見てriverpod_lintを使いたくなった人向けの導入方法の紹介です。
(といっても公式ままですが)

riverpod_lintとcustom_lintをdev_dependenciesに追加する

pubspec.yaml
dev_dependencies:
  custom_lint:
  riverpod_lint:

analysis_options.yamlでcustom_lintを有効化する
結構忘れがちです。custom_lintを入れてるつもりなのにassistが出てない場合は漏れてるかも?

analysis_options.yaml
analyzer:
  plugins:
    - custom_lint

Riverpodを初めて導入するとき

同僚の記事をおすすめしておきます😎

まとめ

riverpod_lintのassistを紹介しました。

余談

Widgetの変換に自分の実装も入ってるんですが、あまり使われてないのでは?と気になって記事書きました😂

7
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
0