feat: date picker on inout page
This commit is contained in:
parent
6aab12f536
commit
fbd129c90b
|
@ -59,33 +59,16 @@ class CustomAppBar extends StatelessWidget {
|
||||||
showCupertinoModalPopup(
|
showCupertinoModalPopup(
|
||||||
context: Get.overlayContext!,
|
context: Get.overlayContext!,
|
||||||
builder: (BuildContext context) {
|
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(
|
child: Container(
|
||||||
height: ScreenAdaper.height(70),
|
height: ScreenAdaper.height(70),
|
||||||
|
@ -93,7 +76,7 @@ class CustomAppBar extends StatelessWidget {
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
color: AppTheme.primaryColorLight,
|
color: AppTheme.primaryColorLight,
|
||||||
gradient: LinearGradient(colors: [
|
gradient: const LinearGradient(colors: [
|
||||||
AppTheme.primaryColorLight,
|
AppTheme.primaryColorLight,
|
||||||
AppTheme.primaryColor,
|
AppTheme.primaryColor,
|
||||||
]),
|
]),
|
||||||
|
|
|
@ -14,7 +14,8 @@ class Dates extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
Obx(
|
Obx(
|
||||||
() => Text(
|
() => Text(
|
||||||
DateUtil.getMonth(DateTime.now().add(Duration(days: -index))),
|
DateUtil.getMonth(
|
||||||
|
controller.endTime.value.add(Duration(days: -index))),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: controller.currentIndex.value == index
|
color: controller.currentIndex.value == index
|
||||||
? Colors.white
|
? Colors.white
|
||||||
|
@ -26,7 +27,8 @@ class Dates extends StatelessWidget {
|
||||||
),
|
),
|
||||||
Obx(
|
Obx(
|
||||||
() => Text(
|
() => Text(
|
||||||
DateUtil.getDate(DateTime.now().add(Duration(days: -index))),
|
DateUtil.getDate(
|
||||||
|
controller.endTime.value.add(Duration(days: -index))),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: controller.currentIndex.value == index
|
color: controller.currentIndex.value == index
|
||||||
? Colors.white
|
? Colors.white
|
||||||
|
@ -38,7 +40,8 @@ class Dates extends StatelessWidget {
|
||||||
),
|
),
|
||||||
Obx(
|
Obx(
|
||||||
() => Text(
|
() => Text(
|
||||||
DateUtil.getDay(DateTime.now().add(Duration(days: -index))),
|
DateUtil.getDay(
|
||||||
|
controller.endTime.value.add(Duration(days: -index))),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: controller.currentIndex.value == index
|
color: controller.currentIndex.value == index
|
||||||
? Colors.white
|
? Colors.white
|
||||||
|
|
|
@ -181,7 +181,6 @@ class InventoryInouInfoController extends GetxController {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getData() async {
|
Future<void> getData() async {
|
||||||
printInfo(info: '$inventoryInoutId');
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
final res = await Api.getInventoryInOutInfo(inventoryInoutId);
|
final res = await Api.getInventoryInOutInfo(inventoryInoutId);
|
||||||
if (res.data != null) {
|
if (res.data != null) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ class InventoryInoutView extends StatelessWidget {
|
||||||
physics: const BouncingScrollPhysics(),
|
physics: const BouncingScrollPhysics(),
|
||||||
reverse: true,
|
reverse: true,
|
||||||
onPageChanged: (index) {
|
onPageChanged: (index) {
|
||||||
controller.changePage(index);
|
controller.setIndex(index);
|
||||||
},
|
},
|
||||||
controller: controller.pageController,
|
controller: controller.pageController,
|
||||||
children: List.generate(
|
children: List.generate(
|
||||||
|
|
|
@ -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/components/inventory_inout_card.dart';
|
||||||
import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.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/util/util.dart';
|
||||||
|
import 'package:sk_base_mobile/widgets/loading_indicator.dart';
|
||||||
|
|
||||||
class TaskList extends StatelessWidget {
|
class TaskList extends StatelessWidget {
|
||||||
const TaskList({super.key, required this.index});
|
const TaskList({super.key, required this.index});
|
||||||
|
@ -43,28 +44,30 @@ class Grid extends StatelessWidget {
|
||||||
required this.ind});
|
required this.ind});
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() => controller.list[ind].isEmpty
|
return Obx(() => controller.loading.value
|
||||||
? Center(
|
? const LoadingIndicator(common: true)
|
||||||
child: Text(
|
: controller.list[ind].isEmpty
|
||||||
TextEnum.noInventoryInout,
|
? Center(
|
||||||
style: TextStyle(
|
child: Text(
|
||||||
color: AppTheme.black,
|
TextEnum.noInventoryInout,
|
||||||
fontWeight: FontWeight.w600,
|
style: TextStyle(
|
||||||
letterSpacing: ScreenAdaper.width(2),
|
color: AppTheme.black,
|
||||||
fontSize: ScreenAdaper.sp(30)),
|
fontWeight: FontWeight.w600,
|
||||||
),
|
letterSpacing: ScreenAdaper.width(2),
|
||||||
)
|
fontSize: ScreenAdaper.sp(30)),
|
||||||
: GridView.builder(
|
),
|
||||||
padding: const EdgeInsets.only(top: 40),
|
)
|
||||||
itemCount: controller.list[ind].length,
|
: GridView.builder(
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
padding: const EdgeInsets.only(top: 40),
|
||||||
crossAxisCount: crossAsis, childAspectRatio: ratio),
|
itemCount: controller.list[ind].length,
|
||||||
itemBuilder: (context, index) {
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
return InventoryInoutCard(
|
crossAxisCount: crossAsis, childAspectRatio: ratio),
|
||||||
index: index,
|
itemBuilder: (context, index) {
|
||||||
ind: ind,
|
return InventoryInoutCard(
|
||||||
);
|
index: index,
|
||||||
},
|
ind: ind,
|
||||||
));
|
);
|
||||||
|
},
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ class UperBody extends StatelessWidget {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: ScreenAdaper.height(150),
|
height: ScreenAdaper.height(150),
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
|
key: PageStorageKey<String>('${controller.endTime.value}'),
|
||||||
controller: controller.scrollController,
|
controller: controller.scrollController,
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
reverse: true,
|
reverse: true,
|
||||||
|
|
|
@ -17,7 +17,7 @@ class InventoryInoutController extends GetxController {
|
||||||
RxMap userData = {}.obs;
|
RxMap userData = {}.obs;
|
||||||
RxInt currentIndex = 0.obs;
|
RxInt currentIndex = 0.obs;
|
||||||
final PageController pageController = PageController();
|
final PageController pageController = PageController();
|
||||||
final DateTime dateTime = DateTime.now();
|
Rx<DateTime> endTime = Rx<DateTime>(DateTime.now());
|
||||||
final DbHelper db = DbHelper();
|
final DbHelper db = DbHelper();
|
||||||
List<RxList<InventoryInOutModel>> list = [
|
List<RxList<InventoryInOutModel>> list = [
|
||||||
<InventoryInOutModel>[].obs,
|
<InventoryInOutModel>[].obs,
|
||||||
|
@ -32,17 +32,13 @@ class InventoryInoutController extends GetxController {
|
||||||
RxList model = [].obs;
|
RxList model = [].obs;
|
||||||
final ScrollController scrollController = ScrollController();
|
final ScrollController scrollController = ScrollController();
|
||||||
final daysNum = 20;
|
final daysNum = 20;
|
||||||
|
RxBool loading = RxBool(false);
|
||||||
@override
|
@override
|
||||||
onReady() {
|
onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
getData();
|
getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> changePage(int index) async {
|
|
||||||
LoggerUtil()
|
|
||||||
.info(DateUtil.format(DateTime.now().add(Duration(days: -index))));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 打开出库还是入库选择框
|
/// 打开出库还是入库选择框
|
||||||
Future<void> showInOrOutPickerDialog() async {
|
Future<void> showInOrOutPickerDialog() async {
|
||||||
showDialog(
|
showDialog(
|
||||||
|
@ -253,17 +249,25 @@ class InventoryInoutController extends GetxController {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<InventoryInOutModel>> getInoutHistory() async {
|
Future<List<InventoryInOutModel>> getInoutHistory() async {
|
||||||
final res = await Api.getInventoryInout({});
|
loading.value = true;
|
||||||
printInfo(info: res.toString());
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
if (res.data != null) {
|
final selectedDate =
|
||||||
return res.data!.items
|
DateUtil.format(endTime.value.add(Duration(days: -currentIndex.value)));
|
||||||
.map((e) => InventoryInOutModel.fromJson(e))
|
try {
|
||||||
.toList();
|
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 {
|
getData() async {
|
||||||
|
@ -277,10 +281,12 @@ class InventoryInoutController extends GetxController {
|
||||||
pageController.animateToPage(value,
|
pageController.animateToPage(value,
|
||||||
duration: const Duration(milliseconds: 300), curve: Curves.easeIn);
|
duration: const Duration(milliseconds: 300), curve: Curves.easeIn);
|
||||||
currentIndex.value = value;
|
currentIndex.value = value;
|
||||||
|
getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
getDateAccordingTabs(int value) {
|
getDateAccordingTabs(int value) {
|
||||||
return DateUtil.format(dateTime.add(Duration(days: -(daysNum - value))));
|
return DateUtil.format(
|
||||||
|
endTime.value.add(Duration(days: -(daysNum - value))));
|
||||||
}
|
}
|
||||||
|
|
||||||
getSepretLists() {
|
getSepretLists() {
|
||||||
|
|
|
@ -13,7 +13,6 @@ class LandingPage extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
printInfo(info: 'landing');
|
|
||||||
return Material(
|
return Material(
|
||||||
child: Stack(children: [
|
child: Stack(children: [
|
||||||
const BackColors(),
|
const BackColors(),
|
||||||
|
|
|
@ -327,11 +327,6 @@ class NewInventoryInout extends StatelessWidget {
|
||||||
floatingLabelBehavior: FloatingLabelBehavior.always),
|
floatingLabelBehavior: FloatingLabelBehavior.always),
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
printInfo(
|
|
||||||
info: firstLevelData
|
|
||||||
.map((e) => Center(child: (Text(e.label))))
|
|
||||||
.toList()
|
|
||||||
.toString());
|
|
||||||
ModalUtil.showBottomSheetPicker(
|
ModalUtil.showBottomSheetPicker(
|
||||||
title: '库存位置',
|
title: '库存位置',
|
||||||
firstLevel: firstLevelData
|
firstLevel: firstLevelData
|
||||||
|
|
|
@ -5,17 +5,23 @@ import 'package:sk_base_mobile/util/logger_util.dart';
|
||||||
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
||||||
|
|
||||||
class ZtBaseDatePicker extends StatelessWidget {
|
class ZtBaseDatePicker extends StatelessWidget {
|
||||||
final Function? onDateTimeChanged;
|
final Function(String)? onDateTimeChanged;
|
||||||
final yearController =
|
late final FixedExtentScrollController yearController;
|
||||||
FixedExtentScrollController(initialItem: DateTime.now().year - 2000);
|
late final FixedExtentScrollController monthController;
|
||||||
final monthController =
|
late final FixedExtentScrollController dayController;
|
||||||
FixedExtentScrollController(initialItem: DateTime.now().month - 1);
|
DateTime? initialDate = DateTime.now();
|
||||||
final dayController =
|
DateTime? endDate = DateTime.now();
|
||||||
FixedExtentScrollController(initialItem: DateTime.now().day - 1);
|
ZtBaseDatePicker(
|
||||||
ZtBaseDatePicker({super.key, this.onDateTimeChanged});
|
{super.key, this.onDateTimeChanged, this.initialDate, this.endDate});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return Container(
|
||||||
height: ScreenAdaper.height(250),
|
height: ScreenAdaper.height(250),
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
|
|
|
@ -13,11 +13,11 @@ class LoadingIndicator extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return common
|
return common
|
||||||
? LoadingAnimationWidget.fourRotatingDots(
|
? LoadingAnimationWidget.fourRotatingDots(
|
||||||
color: AppTheme.primaryColorLight, size: ScreenAdaper.sp(40))
|
color: AppTheme.primaryColorLight, size: ScreenAdaper.sp(50))
|
||||||
: CupertinoActivityIndicator(
|
: CupertinoActivityIndicator(
|
||||||
animating: animating,
|
animating: animating,
|
||||||
color: AppTheme.primaryColor,
|
color: AppTheme.primaryColor,
|
||||||
radius: ScreenAdaper.sp(20),
|
radius: ScreenAdaper.sp(25),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue