feat: date picker on inout page

This commit is contained in:
louis 2024-03-26 16:36:27 +08:00
parent 6aab12f536
commit fbd129c90b
11 changed files with 82 additions and 87 deletions

View File

@ -59,33 +59,16 @@ class CustomAppBar extends StatelessWidget {
showCupertinoModalPopup(
context: Get.overlayContext!,
builder: (BuildContext context) {
return ZtBaseDatePicker();
return ZtBaseDatePicker(
initialDate: controller.endTime.value,
endDate: controller.endTime.value,
onDateTimeChanged: (date) {
controller.endTime.value = DateTime.parse(date);
controller.getData();
},
);
},
);
// showCupertinoModalPopup(
// context: Get.overlayContext!,
// builder: (BuildContext context) {
// return Container(
// height: 200,
// color: Colors.white,
// child: CupertinoDatePicker(
// mode: CupertinoDatePickerMode.date,
// initialDateTime: DateTime.now(),
// onDateTimeChanged: (DateTime newDateTime) {
// //
// },
// ),
// );
// },
// );
// final picker = await CupertinoDatePicker(
// context: Get.overlayContext!,
// initialDate: DateTime.now(),
// helpText: '选择的日期',
// confirmText: '确定',
// cancelText: '取消',
// firstDate: DateTime(2000, 1, 1),
// lastDate: DateTime.now().add(const Duration(days: 7)));
},
child: Container(
height: ScreenAdaper.height(70),
@ -93,7 +76,7 @@ class CustomAppBar extends StatelessWidget {
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: AppTheme.primaryColorLight,
gradient: LinearGradient(colors: [
gradient: const LinearGradient(colors: [
AppTheme.primaryColorLight,
AppTheme.primaryColor,
]),

View File

@ -14,7 +14,8 @@ class Dates extends StatelessWidget {
children: [
Obx(
() => Text(
DateUtil.getMonth(DateTime.now().add(Duration(days: -index))),
DateUtil.getMonth(
controller.endTime.value.add(Duration(days: -index))),
style: TextStyle(
color: controller.currentIndex.value == index
? Colors.white
@ -26,7 +27,8 @@ class Dates extends StatelessWidget {
),
Obx(
() => Text(
DateUtil.getDate(DateTime.now().add(Duration(days: -index))),
DateUtil.getDate(
controller.endTime.value.add(Duration(days: -index))),
style: TextStyle(
color: controller.currentIndex.value == index
? Colors.white
@ -38,7 +40,8 @@ class Dates extends StatelessWidget {
),
Obx(
() => Text(
DateUtil.getDay(DateTime.now().add(Duration(days: -index))),
DateUtil.getDay(
controller.endTime.value.add(Duration(days: -index))),
style: TextStyle(
color: controller.currentIndex.value == index
? Colors.white

View File

@ -181,7 +181,6 @@ class InventoryInouInfoController extends GetxController {
}
Future<void> getData() async {
printInfo(info: '$inventoryInoutId');
await Future.delayed(const Duration(milliseconds: 500));
final res = await Api.getInventoryInOutInfo(inventoryInoutId);
if (res.data != null) {

View File

@ -12,7 +12,7 @@ class InventoryInoutView extends StatelessWidget {
physics: const BouncingScrollPhysics(),
reverse: true,
onPageChanged: (index) {
controller.changePage(index);
controller.setIndex(index);
},
controller: controller.pageController,
children: List.generate(

View File

@ -6,6 +6,7 @@ import 'package:sk_base_mobile/screens/inventory_inout/components/responsive.dar
import 'package:sk_base_mobile/screens/inventory_inout/components/inventory_inout_card.dart';
import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart';
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});
@ -43,28 +44,30 @@ class Grid extends StatelessWidget {
required this.ind});
@override
Widget build(BuildContext context) {
return Obx(() => controller.list[ind].isEmpty
? Center(
child: Text(
TextEnum.noInventoryInout,
style: TextStyle(
color: AppTheme.black,
fontWeight: FontWeight.w600,
letterSpacing: ScreenAdaper.width(2),
fontSize: ScreenAdaper.sp(30)),
),
)
: GridView.builder(
padding: const EdgeInsets.only(top: 40),
itemCount: controller.list[ind].length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAsis, childAspectRatio: ratio),
itemBuilder: (context, index) {
return InventoryInoutCard(
index: index,
ind: ind,
);
},
));
return Obx(() => controller.loading.value
? const LoadingIndicator(common: true)
: controller.list[ind].isEmpty
? Center(
child: Text(
TextEnum.noInventoryInout,
style: TextStyle(
color: AppTheme.black,
fontWeight: FontWeight.w600,
letterSpacing: ScreenAdaper.width(2),
fontSize: ScreenAdaper.sp(30)),
),
)
: GridView.builder(
padding: const EdgeInsets.only(top: 40),
itemCount: controller.list[ind].length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAsis, childAspectRatio: ratio),
itemBuilder: (context, index) {
return InventoryInoutCard(
index: index,
ind: ind,
);
},
));
}
}

View File

@ -20,6 +20,7 @@ class UperBody extends StatelessWidget {
SizedBox(
height: ScreenAdaper.height(150),
child: ListView.builder(
key: PageStorageKey<String>('${controller.endTime.value}'),
controller: controller.scrollController,
shrinkWrap: true,
reverse: true,

View File

@ -17,7 +17,7 @@ class InventoryInoutController extends GetxController {
RxMap userData = {}.obs;
RxInt currentIndex = 0.obs;
final PageController pageController = PageController();
final DateTime dateTime = DateTime.now();
Rx<DateTime> endTime = Rx<DateTime>(DateTime.now());
final DbHelper db = DbHelper();
List<RxList<InventoryInOutModel>> list = [
<InventoryInOutModel>[].obs,
@ -32,17 +32,13 @@ class InventoryInoutController extends GetxController {
RxList model = [].obs;
final ScrollController scrollController = ScrollController();
final daysNum = 20;
RxBool loading = RxBool(false);
@override
onReady() {
super.onReady();
getData();
}
Future<void> changePage(int index) async {
LoggerUtil()
.info(DateUtil.format(DateTime.now().add(Duration(days: -index))));
}
///
Future<void> showInOrOutPickerDialog() async {
showDialog(
@ -253,17 +249,25 @@ class InventoryInoutController extends GetxController {
}
Future<List<InventoryInOutModel>> getInoutHistory() async {
final res = await Api.getInventoryInout({});
printInfo(info: res.toString());
if (res.data != null) {
return res.data!.items
.map((e) => InventoryInOutModel.fromJson(e))
.toList();
loading.value = true;
await Future.delayed(const Duration(milliseconds: 500));
final selectedDate =
DateUtil.format(endTime.value.add(Duration(days: -currentIndex.value)));
try {
final res = await Api.getInventoryInout({
'time': [selectedDate, selectedDate]
});
if (res.data != null) {
return res.data!.items
.map((e) => InventoryInOutModel.fromJson(e))
.toList();
}
return [];
} catch (e) {
return [];
} finally {
loading.value = false;
}
return [];
// final List<Map<String, Object?>> queryResult =
// await dbClient!.query('Tasks');
// return queryResult.map((e) => TaskModel.fromMap(e)).toList();
}
getData() async {
@ -277,10 +281,12 @@ class InventoryInoutController extends GetxController {
pageController.animateToPage(value,
duration: const Duration(milliseconds: 300), curve: Curves.easeIn);
currentIndex.value = value;
getData();
}
getDateAccordingTabs(int value) {
return DateUtil.format(dateTime.add(Duration(days: -(daysNum - value))));
return DateUtil.format(
endTime.value.add(Duration(days: -(daysNum - value))));
}
getSepretLists() {

View File

@ -13,7 +13,6 @@ class LandingPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
printInfo(info: 'landing');
return Material(
child: Stack(children: [
const BackColors(),

View File

@ -327,11 +327,6 @@ class NewInventoryInout extends StatelessWidget {
floatingLabelBehavior: FloatingLabelBehavior.always),
readOnly: true,
onTap: () {
printInfo(
info: firstLevelData
.map((e) => Center(child: (Text(e.label))))
.toList()
.toString());
ModalUtil.showBottomSheetPicker(
title: '库存位置',
firstLevel: firstLevelData

View File

@ -5,17 +5,23 @@ import 'package:sk_base_mobile/util/logger_util.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
class ZtBaseDatePicker extends StatelessWidget {
final Function? onDateTimeChanged;
final yearController =
FixedExtentScrollController(initialItem: DateTime.now().year - 2000);
final monthController =
FixedExtentScrollController(initialItem: DateTime.now().month - 1);
final dayController =
FixedExtentScrollController(initialItem: DateTime.now().day - 1);
ZtBaseDatePicker({super.key, this.onDateTimeChanged});
final Function(String)? onDateTimeChanged;
late final FixedExtentScrollController yearController;
late final FixedExtentScrollController monthController;
late final FixedExtentScrollController dayController;
DateTime? initialDate = DateTime.now();
DateTime? endDate = DateTime.now();
ZtBaseDatePicker(
{super.key, this.onDateTimeChanged, this.initialDate, this.endDate});
@override
Widget build(BuildContext context) {
yearController = FixedExtentScrollController(
initialItem: (initialDate ?? DateTime.now()).year - 2000);
monthController = FixedExtentScrollController(
initialItem: (initialDate ?? DateTime.now()).month - 1);
dayController = FixedExtentScrollController(
initialItem: (initialDate ?? DateTime.now()).day - 1);
return Container(
height: ScreenAdaper.height(250),
color: Colors.white,

View File

@ -13,11 +13,11 @@ class LoadingIndicator extends StatelessWidget {
Widget build(BuildContext context) {
return common
? LoadingAnimationWidget.fourRotatingDots(
color: AppTheme.primaryColorLight, size: ScreenAdaper.sp(40))
color: AppTheme.primaryColorLight, size: ScreenAdaper.sp(50))
: CupertinoActivityIndicator(
animating: animating,
color: AppTheme.primaryColor,
radius: ScreenAdaper.sp(20),
radius: ScreenAdaper.sp(25),
);
}
}