gallery_picker/lib/views/gridview_static.dart

97 lines
3.0 KiB
Dart
Raw Normal View History

2022-12-25 12:30:20 +03:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.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();
}
Widget horizontalView() {
return SizedBox(
height: size,
child: Column(
children: [
for (int i = 0; i < crossAxisCount; i+=crossAxisCount)
Padding(
padding: EdgeInsets.only(
bottom: i != children.length - 1 ? mainAxisSpacing : 0),
child: SizedBox(
height: size / crossAxisCount,
child: Row(
children: [
for (int j = i; j < i + (children.length~/crossAxisCount)+1; j++)
j < children.length
? Expanded(
child: Padding(
padding: EdgeInsets.only(
right: j != i + crossAxisCount
? crossAxisSpacing
: 0),
child: children[j],
))
: Spacer()
],
),
),
)
],
),
);
}
Widget verticalView() {
return SizedBox(
width: size,
child: Column(
children: [
for (int i = 0; i < children.length; i+=crossAxisCount)
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],
))
: Spacer()
],
),
),
)
],
),
);
}
}