0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Flutter 2023.8.8 コードFB

Posted at

・同じようなコードが複数ある場合は変数にまとめると見やすくて簡単に記述できる。
→動作させるのに必死で意識が薄れることがよくあるので気を付けていきたい。

一部コード抜粋(Riverpod)
上Bfore
下after

          child: TextButton(
            onPressed: (){
              if(ref.watch(_counterProvider) == 100) return;
                ref.read(_counterProvider.notifier).update((state) =>
                ref.watch(_counterProvider) + (int.parse(_editController.text)));
              if(ref.watch(_counterProvider) >= 100){
                ref.read(_counterProvider.notifier).update((state) =>
                 100);
              }
            },

          child: TextButton(
            onPressed: (){
              if(countNum == 100) return;
              int newCountNum = countNum + (int.parse(_editController.text));
              if(newCountNum >= 100) newCountNum = 100;
              ref.read(_counterProvider.notifier).update((state) => newCountNum);
            },

ref.watch(_counterProvider);
長いので
int countNum = ref.watch(_counterProvider);
とした。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?