2022-12-25 12:30:20 +03:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
|
|
|
class GridViewStatic extends StatelessWidget {
|
|
|
|
final Axis scrollDirection;
|
|
|
|
final EdgeInsetsGeometry? padding;
|
|
|
|
final int crossAxisCount;
|
|
|
|
final double mainAxisSpacing;
|
|
|
|
final double crossAxisSpacing;
|
|
|
|
final double childAspectRatio;
|
|
|
|
final List<Widget> children;
|
|
|
|
final double size;
|
|
|
|
const GridViewStatic({
|
|
|
|
super.key,
|
|
|
|
required this.size,
|
|
|
|
required this.children,
|
|
|
|
required this.crossAxisCount,
|
|
|
|
this.scrollDirection = Axis.vertical,
|
|
|
|
this.padding,
|
|
|
|
this.mainAxisSpacing = 0.0,
|
|
|
|
this.crossAxisSpacing = 0.0,
|
|
|
|
this.childAspectRatio = 1.0,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return verticalView();
|
|
|
|
}
|
2022-12-30 05:18:18 +03:00
|
|
|
|
2022-12-25 12:30:20 +03:00
|
|
|
Widget horizontalView() {
|
|
|
|
return SizedBox(
|
|
|
|
height: size,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-12-30 05:18:18 +03:00
|
|
|
for (int i = 0; i < crossAxisCount; i += crossAxisCount)
|
2022-12-25 12:30:20 +03:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: i != children.length - 1 ? mainAxisSpacing : 0),
|
|
|
|
child: SizedBox(
|
|
|
|
height: size / crossAxisCount,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2022-12-30 05:18:18 +03:00
|
|
|
for (int j = i;
|
|
|
|
j < i + (children.length ~/ crossAxisCount) + 1;
|
|
|
|
j++)
|
2022-12-25 12:30:20 +03:00
|
|
|
j < children.length
|
|
|
|
? Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
right: j != i + crossAxisCount
|
|
|
|
? crossAxisSpacing
|
|
|
|
: 0),
|
|
|
|
child: children[j],
|
|
|
|
))
|
2022-12-30 05:18:18 +03:00
|
|
|
: const Spacer()
|
2022-12-25 12:30:20 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget verticalView() {
|
|
|
|
return SizedBox(
|
|
|
|
width: size,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-12-30 05:18:18 +03:00
|
|
|
for (int i = 0; i < children.length; i += crossAxisCount)
|
2022-12-25 12:30:20 +03:00
|
|
|
SizedBox(
|
|
|
|
width: size,
|
|
|
|
height: (size / crossAxisCount) * childAspectRatio,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: i != children.length - 1 ? mainAxisSpacing : 0),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
for (int j = i; j < i + crossAxisCount; j++)
|
|
|
|
j < children.length
|
|
|
|
? Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
right: j != i + crossAxisCount
|
|
|
|
? crossAxisSpacing
|
|
|
|
: 0),
|
|
|
|
child: children[j],
|
|
|
|
))
|
2022-12-30 05:18:18 +03:00
|
|
|
: const Spacer()
|
2022-12-25 12:30:20 +03:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|