Last active
June 25, 2022 17:36
-
-
Save daiki1003/a4c74d795594681a0b57a3c7ec6cfdfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyGreatestWidget extends StatelessWidget { | |
const MyGreatestWidget({ | |
Key? key, | |
required this.onPressed, | |
}) : super(key: key); | |
final ValueCallback<String> onPressed; | |
@override | |
Widget build(BuildContext context) { | |
final fruits = ['apple', 'banana', 'orange']; | |
return ListView( | |
children: fruits.map((fruit) { | |
return _buildFruitItem( | |
fruit: fruit | |
onPressed: onPressed, | |
); | |
}).toList(), | |
); | |
} | |
Widget _buildFruitItem({ | |
required String fruit, | |
required ValueCallback<String> onPressed, | |
}) { | |
// 渡す引数が長かったり多かったりして、どうしても | |
// 呼び出し元のコードが肥大化してしまう場合のみヘルパー使う | |
// (とはいえ、こうなってしまうのは設計見直しのサインだったりもする) | |
return FruitItem( | |
fruit: fruit, | |
maxLines: 2, | |
hoge: true, | |
fuga: false, | |
isFavorite: true, | |
onPressed: onPressed, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment