-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#36 create generic image widget #69
Conversation
…r-app into #36_create_generic_image_widget # Conflicts: # packages/mottai_flutter_app/pubspec.yaml
final double? radius; | ||
@override | ||
Widget build(BuildContext context) { | ||
return imageUrl.isEmpty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[任意(好みの問題)]
3 項演算子でなくていいなら、単に
if (condition) {
return something;
}
return somethingElse;
が私は好きです!(インデントが減って見やすい、if 文の条件が増えても 3 項演算子がネストするようなことにならない)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 各図形の高さ。circle/squareの場合、widthにもこの値が入る。rectangleの場合、widthはこれの2倍の値が入る | ||
// 指定がない場合は、defaultとして64.0が入る |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このような説明は、height
自体の定義に doc comment(3 本スラッシュ ///
のコメント)として書くと、利用する側がエディタでカーソルを合わせることでその内容を確認できるのでやってみてください!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます!
今回は該当箇所が削除になりましたが、次回こういったシチュエーションがあった際は、doc commentにします!
placeholder: (context, url) => const Center( | ||
child: CircularProgressIndicator(), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[追加の提案]
画像の読み込み中は CircularProgressIndicator
のぐるぐるではなく、使用者が任意のウィジェットを渡したくなることもほぼ間違いなくあるので、任意で渡せるようにしましょうか!(また、そのときのデフォルトのウィジェットも CircularProgressIndicator()
よりも、単にその形のグレー色のウィジェットのほうが良さそうな気がしています)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final DecorationImage? decorationImage; | ||
@override | ||
Widget build(BuildContext context) { | ||
const defaultSize = 64.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このクラス自体の変数として
static const double _defaultSize = 64;
みたいにしましょうか
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.height, | ||
this.radius, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この画像を使用する人が、画像 URL と形に加えて、
- 高さ
- 半径
を渡すというのがちょっとアンバランスな感じがしてどうなんだろうと思っています。
また(これ以下の実装の話ですが)、長方形の場合は常に横幅は高さの 2 倍にする仕様になっていますか?(おそらく 1:2 は一般的画像のアスペクト比というわけでもないでしょうし、「汎用的な画像ウィジェット」としては、長方形の場合は、高さと幅を両方指定するようにするべきかな〜!と思っています!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
勝手に2倍の仕様にしてしまっていました・・・
形ごとの名前付きコンストラクタを作成し、長方形の場合は高さと幅の両方を指定するよう修正しました!
} | ||
|
||
class GenericImageWidget extends StatelessWidget { | ||
const GenericImageWidget({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下でも指摘した、「形ごとに渡すべきサイズに関する値の種類が異なる」という仕様の話にも関連して、これを名前付きコンストラクタにする(イニシャライザリストも活用する)のはどうでしょうか?
- https://dart.dev/language/constructors#named-constructors
- https://dart.dev/language/constructors#initializer-list
そうすると、それぞの名前付きコンストラクタごとに渡すパラメータを変えられるように思います(たとえば円と正方形では単にsize
、長方形では width
と height
のような感じ)。
GenericImageWidget.circle(/* 省略 */): imageShape = ImageShape.circle;
GenericImageWidget.square(/* 省略 */): imageShape = ImageShape.square;
GenericImageWidget.rectangle(/* 省略 */): imageShape = ImageShape.rectangle;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? (height != null ? height! * 2 : defaultSize * 2) | ||
: height ?? defaultSize; | ||
|
||
return Center( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここもそのほうが見やすければ ImageShape
で switch-case
書いてしまっていいとも思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final adjustWidth = imageShape == ImageShape.rectangle | ||
? (height != null ? height! * 2 : defaultSize * 2) | ||
: height ?? defaultSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上で指摘した通り、この仕様はやめることになると思います。
? _ImageDisplayContainer( | ||
imageShape: imageShape, | ||
color: Colors.grey, | ||
height: height, | ||
radius: radius, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは Colors.grey
を直接渡すことで _ImageDisplayContainer
側でその見た目に合うようなウィジェットを表示するというよりは、ウィジェットを分けてしまう(PlaceholderImage
みたいな)か名前付き引数(_ImageDisplayContainer.placeholder(/* 省略 */)
みたいな)かで書くほうが読んですぐに理解できると思います!(現状だと、ここだけ読んでどんな見た目になりそうか想像できない。PlaceholderImage
のように書いてあると「ああ、画像が空っぽのときのプレースホルダ画像なんだろうな」とすぐわかる)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appBar: AppBar( | ||
title: const Text('開発中のComponents'), | ||
), | ||
body: Column( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[任意]
エラーのケース(もし可能なら、loading のケース)の見た目のサンプルもあると嬉しいです!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こちらについてはまだ対応できていませんので、追って対応します!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cee51c7
にてエラーのケースのサンプルを追加しました!
7167511
で、エラーケースの場合は指定された形やサイズの中にアイコンを表示するようにしてみましたが、いかがでしょう?
(元々はアイコンのみ表示される仕様にしていた)
loading のケースは、GPT先生に相談して
http://deelay.me/
というサービスを教えてもらったんですが、今は動作してないようでした・・・
他に実現できる方法がわからなかったので、loadingのケースは対応できていません。
Widget build(BuildContext context) { | ||
const defaultSize = 64.0; | ||
|
||
// 長方形が指定された場合のみ、指定されたheightの2倍の値またはdefaulSizeの2倍の値をwidthに設定する |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[タイポ]
defaulSize → defaultSize
…r-app into #36_create_generic_image_widget
final double? height; | ||
final double? width; | ||
final double? borderRadius; | ||
final Widget? loading; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[軽微]
loadingWidget
か loadingPlaceholder
に変えましょうか!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます!
d32565b
にて修正しました。
Widget build(BuildContext context) { | ||
switch (imageShape) { | ||
case ImageShape.circle: | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この波括弧 {}
は不要ではないですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます!
不要ですね・・・
ec98a2b
にて修正しました
…r-app into #36_create_generic_image_widget # Conflicts: # packages/mottai_flutter_app/lib/development/development_items/ui/development_items.dart
…r-app into #36_create_generic_image_widget
Issue
close #36
説明
UI
開発ページ内に「Components」追加
開発中のComponentsページ
その他
レビューのほどよろしくお願いします!
チェックリスト