feat: grid view auto height for each item

This commit is contained in:
louis 2024-03-29 15:06:05 +08:00
parent 8a06486f93
commit c475f8b553
5 changed files with 56 additions and 153 deletions

View File

@ -23,8 +23,8 @@ class InventoryInoutCard extends StatelessWidget {
},
child: Container(
margin: EdgeInsets.symmetric(
vertical: ScreenAdaper.height(15),
horizontal: ScreenAdaper.width(15)),
vertical: ScreenAdaper.height(10),
horizontal: ScreenAdaper.width(10)),
padding: EdgeInsets.symmetric(
horizontal: ScreenAdaper.width(defaultPadding),
vertical: ScreenAdaper.height(defaultPadding)),
@ -42,116 +42,6 @@ class InventoryInoutCard extends StatelessWidget {
children: [
buildImage(),
Expanded(child: buildContent()),
// const Spacer(
// flex: 2,
// ),
// controller.list[ind][index].inOrOut ==
// InventoryInOrOutEnumValues[InventoryInOrOutEnum.In]
// ? Container(
// height: ScreenAdaper.height(40),
// width: ScreenAdaper.width(40),
// decoration: BoxDecoration(
// shape: BoxShape.circle,
// gradient: const LinearGradient(
// begin: Alignment.topCenter,
// end: Alignment.bottomCenter,
// colors: [
// lightOrange,
// darkOrange,
// ]),
// boxShadow: [
// BoxShadow(
// color: lightOrange,
// offset: Offset(0, ScreenAdaper.height(10)),
// blurRadius: ScreenAdaper.sp(10))
// ]),
// child: const Icon(
// Icons.done,
// color: Colors.white,
// ),
// )
// : Align(
// alignment: Alignment.topRight,
// child: Padding(
// padding: EdgeInsets.only(top: ScreenAdaper.height(20)),
// child: PopupMenuButton(
// onSelected: (value) => {
// // controller.onTaskComplete(value, index, ind,
// // controller.list[ind][index].key, context)
// },
// surfaceTintColor: Colors.white,
// padding: EdgeInsets.zero,
// icon: Icon(
// Icons.more_vert_rounded,
// color: Colors.grey,
// size: ScreenAdaper.height(24),
// ),
// shape: OutlineInputBorder(
// borderRadius:
// BorderRadius.circular(ScreenAdaper.sp(20)),
// borderSide: BorderSide.none,
// ),
// itemBuilder: (context) {
// return [
// PopupMenuItem(
// height: ScreenAdaper.height(20),
// value: 1,
// child: Row(
// children: [
// Icon(
// Icons.edit_note,
// color: Colors.orange,
// size: ScreenAdaper.height(14),
// ),
// SizedBox(
// width:
// ScreenAdaper.width(defaultPadding) /
// 2,
// ),
// const Text('Edit')
// ],
// )),
// PopupMenuItem(
// height: ScreenAdaper.height(25),
// value: 2,
// child: Row(
// children: [
// Icon(
// Icons.delete_outline,
// color: Colors.orange,
// size: ScreenAdaper.height(14),
// ),
// SizedBox(
// width:
// ScreenAdaper.width(defaultPadding) /
// 2,
// ),
// Text('Delete')
// ],
// )),
// PopupMenuItem(
// height: ScreenAdaper.height(25),
// value: 3,
// child: Row(
// children: [
// Icon(
// Icons.done_all_outlined,
// color: Colors.orange,
// size: ScreenAdaper.height(14),
// ),
// SizedBox(
// width:
// ScreenAdaper.width(defaultPadding) /
// 2,
// ),
// Text('Complete')
// ],
// )),
// ];
// },
// )),
// ),
],
),
),
@ -178,7 +68,7 @@ class InventoryInoutCard extends StatelessWidget {
buildInOrOut()
],
),
Spacer(),
// Spacer(),
Text(
controller.list[ind][index].product?.company?.name ?? '-',
style: TextStyle(

View File

@ -17,7 +17,7 @@ class InventoryInoutView extends StatelessWidget {
controller: controller.pageController,
children: List.generate(
controller.daysNum,
(index) => TaskList(
(index) => InventoryInoutViewItem(
index: index,
)));
}

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/constants/constants.dart';
@ -8,43 +9,36 @@ import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controlle
import 'package:sk_base_mobile/util/util.dart';
import 'package:sk_base_mobile/widgets/loading_indicator.dart';
class TaskList extends StatelessWidget {
const TaskList({super.key, required this.index});
class InventoryInoutViewItem extends StatelessWidget {
const InventoryInoutViewItem({super.key, required this.index});
final int index;
@override
Widget build(BuildContext context) {
return Responsive(
tablet: Grid(
crossAsis: 2,
ratio: 2.2,
columnNum: 2,
ind: index,
),
largeTablet: Grid(
crossAsis: 3,
ratio: 2.3,
columnNum: 3,
ind: index,
),
mobile: Grid(
ratio: 3,
crossAsis: 1,
columnNum: 1,
ind: index,
));
}
}
class Grid extends StatelessWidget {
final int crossAsis;
final double ratio;
final int columnNum;
final int ind;
final controller = Get.find<InventoryInoutController>();
Grid(
{super.key,
required this.crossAsis,
required this.ratio,
required this.ind});
Grid({super.key, required this.columnNum, required this.ind});
@override
Widget build(BuildContext context) {
return Obx(() => controller.loading.value
return Obx(
() => controller.loading.value
? const LoadingIndicator(common: true)
: controller.list[ind].isEmpty
? Center(
@ -57,17 +51,27 @@ class Grid extends StatelessWidget {
fontSize: ScreenAdaper.height(30)),
),
)
: GridView.builder(
padding: const EdgeInsets.only(top: 40),
: MasonryGridView.count(
padding: EdgeInsets.only(top: ScreenAdaper.height(60)),
crossAxisCount: columnNum,
itemCount: controller.list[ind].length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAsis, childAspectRatio: ratio),
itemBuilder: (context, index) {
return InventoryInoutCard(
index: index,
ind: ind,
);
},
));
),
);
// : GridView.count(
// padding: const EdgeInsets.only(top: 40),
// crossAxisCount: columnNum,
// children: List.generate(controller.list[ind].length, (index) {
// return InventoryInoutCard(
// index: index,
// ind: ind,
// );
// }),
// ));
}
}

View File

@ -358,6 +358,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.9.0"
flutter_staggered_grid_view:
dependency: "direct main"
description:
name: flutter_staggered_grid_view
sha256: "19e7abb550c96fbfeb546b23f3ff356ee7c59a019a651f8f102a4ba9b7349395"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
flutter_test:
dependency: "direct dev"
description: flutter

View File

@ -60,6 +60,7 @@ dependencies:
decimal: ^2.3.3
photo_view: ^0.14.0
image_gallery_saver: ^2.0.3
flutter_staggered_grid_view: ^0.7.0