-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from n4sust1m/2
2
- Loading branch information
Showing
4 changed files
with
109 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
enum AlignDirection { | ||
start, | ||
center, | ||
end, | ||
} | ||
|
||
MainAxisAlignment toMainAxisAlignment(AlignDirection ad) { | ||
switch (ad) { | ||
case AlignDirection.start: | ||
return MainAxisAlignment.start; | ||
case AlignDirection.center: | ||
return MainAxisAlignment.center; | ||
case AlignDirection.end: | ||
return MainAxisAlignment.end; | ||
default: | ||
throw Error(); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class MyColoredBox extends StatelessWidget { | ||
final Color color; | ||
final int width; | ||
final int height; | ||
const MyColoredBox( | ||
{Key? key, | ||
required this.color, | ||
required this.width, | ||
required this.height}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
width: width.toDouble(), | ||
height: height.toDouble(), | ||
child: ColoredBox( | ||
color: color, | ||
), | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_training_2023/domain/align/model.dart'; | ||
import 'package:flutter_training_2023/widgets/my_colored_box.dart'; | ||
|
||
class MyColoredBoxList extends StatelessWidget { | ||
final int width; | ||
final int height; | ||
final AlignDirection align; | ||
final int amount; | ||
final Color color; | ||
const MyColoredBoxList({ | ||
Key? key, | ||
required this.width, | ||
required this.height, | ||
required this.align, | ||
required this.amount, | ||
required this.color, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
MainAxisAlignment mainAxisAlignment = toMainAxisAlignment(align); | ||
|
||
List<Widget> children = List.filled( | ||
amount, | ||
[ | ||
MyColoredBox( | ||
color: color, | ||
width: width, | ||
height: height, | ||
), | ||
const SizedBox(width: 10), | ||
], | ||
).expand((e) => e).toList(); | ||
children = children.sublist(0, children.length - 1); // 末尾のSizedBoxを取り除く | ||
|
||
return Row( | ||
mainAxisAlignment: mainAxisAlignment, | ||
children: children, | ||
); | ||
} | ||
} |