Skip to content
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

Merged
merged 27 commits into from
Jul 27, 2023
Merged

Conversation

haterain0203
Copy link
Collaborator

@haterain0203 haterain0203 commented Jul 24, 2023

Issue

close #36

説明

  • 汎用的な画像Widgetの作成
    • cached_network_image を使用
    • 円 or 正方形 or 長方形を指定できる(それ用のenumを作成)
    • サイズ(縦)を指定できる
    • サイズ(横)は、円・正方形の場合は、サイズ(縦)を適用し、長方形の場合はサイズ(縦)の2倍とした
    • 指定がない場合はデフォルト値として縦横 64とした
    • 角丸サイズを指定できる
    • 画像をタップした場合のVoidCallbackを指定できる
    • imageUrlが空文字の場合は代わりのグレー色プレイスホルダーっぽい見た目に
  • 上記Widgetのサンプルを表示するdevelopment/development_components/develop/components.dartの追加
  • development/development_items/development_items.dart内に上記サンプルページへの動線追加

UI

開発ページ内に「Components」追加

開発中のComponentsページ

その他

レビューのほどよろしくお願いします!

チェックリスト

  • PR の冒頭に関連する Issue 番号を記載しましたか?
  • 本 PR の変更に関して、エディタや IDE で意図しない警告は増えていませんか?(lint 警告やタイポなど)
  • Issue の完了の定義は満たせていますか?

final double? radius;
@override
Widget build(BuildContext context) {
return imageUrl.isEmpty
Copy link
Owner

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 項演算子がネストするようなことにならない)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!

e3f09e5

にて対応しました!

Comment on lines 15 to 16
// 各図形の高さ。circle/squareの場合、widthにもこの値が入る。rectangleの場合、widthはこれの2倍の値が入る
// 指定がない場合は、defaultとして64.0が入る
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このような説明は、height 自体の定義に doc comment(3 本スラッシュ /// のコメント)として書くと、利用する側がエディタでカーソルを合わせることでその内容を確認できるのでやってみてください!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!
今回は該当箇所が削除になりましたが、次回こういったシチュエーションがあった際は、doc commentにします!

Comment on lines 51 to 53
placeholder: (context, url) => const Center(
child: CircularProgressIndicator(),
),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[追加の提案]

画像の読み込み中は CircularProgressIndicator のぐるぐるではなく、使用者が任意のウィジェットを渡したくなることもほぼ間違いなくあるので、任意で渡せるようにしましょうか!(また、そのときのデフォルトのウィジェットも CircularProgressIndicator() よりも、単にその形のグレー色のウィジェットのほうが良さそうな気がしています)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!

c03f552

にて対応しました。

final DecorationImage? decorationImage;
@override
Widget build(BuildContext context) {
const defaultSize = 64.0;
Copy link
Owner

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; みたいにしましょうか

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!

f12a6b0

にて対応しました

Comment on lines 17 to 18
this.height,
this.radius,
Copy link
Owner

@kosukesaigusa kosukesaigusa Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この画像を使用する人が、画像 URL と形に加えて、

  • 高さ
  • 半径

を渡すというのがちょっとアンバランスな感じがしてどうなんだろうと思っています。

また(これ以下の実装の話ですが)、長方形の場合は常に横幅は高さの 2 倍にする仕様になっていますか?(おそらく 1:2 は一般的画像のアスペクト比というわけでもないでしょうし、「汎用的な画像ウィジェット」としては、長方形の場合は、高さと幅を両方指定するようにするべきかな〜!と思っています!)

Copy link
Collaborator Author

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({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下でも指摘した、「形ごとに渡すべきサイズに関する値の種類が異なる」という仕様の話にも関連して、これを名前付きコンストラクタにする(イニシャライザリストも活用する)のはどうでしょうか?

そうすると、それぞの名前付きコンストラクタごとに渡すパラメータを変えられるように思います(たとえば円と正方形では単にsize、長方形では widthheight のような感じ)。

GenericImageWidget.circle(/* 省略 */): imageShape = ImageShape.circle;

GenericImageWidget.square(/* 省略 */): imageShape = ImageShape.square;

GenericImageWidget.rectangle(/* 省略 */): imageShape = ImageShape.rectangle;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!
恥ずかしながら名前付きコンストラクタを理解できていなかったので勉強になりました・・・!

1e562cc

上記のような対応でいかがでしょうか!?

? (height != null ? height! * 2 : defaultSize * 2)
: height ?? defaultSize;

return Center(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここもそのほうが見やすければ ImageShapeswitch-case 書いてしまっていいとも思います。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます!

30e2a0c

上記のように修正してみたのですが、どうでしょうか?

Comment on lines 82 to 84
final adjustWidth = imageShape == ImageShape.rectangle
? (height != null ? height! * 2 : defaultSize * 2)
: height ?? defaultSize;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上で指摘した通り、この仕様はやめることになると思います。

Comment on lines 30 to 35
? _ImageDisplayContainer(
imageShape: imageShape,
color: Colors.grey,
height: height,
radius: radius,
)
Copy link
Owner

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 のように書いてあると「ああ、画像が空っぽのときのプレースホルダ画像なんだろうな」とすぐわかる)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、確かに変更前だと「ここだけ読んでどんな見た目になるか想像できない」ですね・・・

fda64db

にて、.placeholderを作ってみました!

appBar: AppBar(
title: const Text('開発中のComponents'),
),
body: Column(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[任意]

エラーのケース(もし可能なら、loading のケース)の見た目のサンプルもあると嬉しいです!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらについてはまだ対応できていませんので、追って対応します!

Copy link
Collaborator Author

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に設定する
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[タイポ]

defaulSize → defaultSize

final double? height;
final double? width;
final double? borderRadius;
final Widget? loading;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[軽微]

loadingWidgetloadingPlaceholder に変えましょうか!

Copy link
Collaborator Author

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:
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この波括弧 {} は不要ではないですか?

Copy link
Collaborator Author

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
@haterain0203 haterain0203 merged commit f9875f0 into main Jul 27, 2023
1 check passed
@haterain0203 haterain0203 deleted the #36_create_generic_image_widget branch July 27, 2023 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

汎用的な画像ウィジェットを定義する
2 participants