From 504dc26ed4114bb1eee06f2726c1215bfe3ee855 Mon Sep 17 00:00:00 2001 From: louis <869322496@qq.com> Date: Wed, 20 Mar 2024 10:37:52 +0800 Subject: [PATCH] feat: create inventory in or out picker --- .../inventory_inout_controller.dart | 159 +++++++++++++++++- lib/screens/landing/landing.dart | 34 ++-- lib/widgets/floating_action.dart | 119 +++++-------- lib/widgets/gradient_button.dart | 8 +- lib/widgets/tap_to_dismiss_keyboard.dart | 5 +- 5 files changed, 220 insertions(+), 105 deletions(-) diff --git a/lib/screens/inventory_inout/inventory_inout_controller.dart b/lib/screens/inventory_inout/inventory_inout_controller.dart index ddf4847..9a4d675 100644 --- a/lib/screens/inventory_inout/inventory_inout_controller.dart +++ b/lib/screens/inventory_inout/inventory_inout_controller.dart @@ -1,9 +1,15 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:sk_base_mobile/app_theme.dart'; import 'package:sk_base_mobile/db_helper/dbHelper.dart'; +import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout.dart'; import 'package:sk_base_mobile/util/date.util.dart'; +import 'package:sk_base_mobile/util/logger_util.dart'; import 'package:sk_base_mobile/util/modal.util.dart'; +import 'package:sk_base_mobile/util/screen_adaper_util.dart'; + +import 'components/responsive.dart'; class InventoryInoutController extends GetxController { RxMap userData = {}.obs; @@ -24,7 +30,158 @@ class InventoryInoutController extends GetxController { RxList model = [].obs; final ScrollController scrollController = ScrollController(); - InventoryInoutController() {} + Future showInOrOutPickerDialog() async { + showDialog( + context: Get.overlayContext!, + builder: (_) => Align( + alignment: Alignment.center, + widthFactor: 1, + heightFactor: 1, + child: SizedBox( + width: ScreenAdaper.width(1000), + height: ScreenAdaper.height(500), + child: TweenAnimationBuilder( + curve: Curves.easeInOut, + tween: Tween(begin: 0, end: 1), + duration: const Duration(milliseconds: 200), + builder: (context, value, child) { + return Stack( + alignment: Alignment.center, + children: [ + AnimatedPositioned( + duration: const Duration(milliseconds: 100), + left: value * 80, + child: GestureDetector( + onTap: () { + Get.back(); + showInventoryInoutCreateDialog(); + }, + child: Container( + height: ScreenAdaper.height(350), + width: ScreenAdaper.height(350), + decoration: const BoxDecoration( + borderRadius: + BorderRadius.all(Radius.circular(30)), + gradient: LinearGradient(colors: [ + AppTheme.primaryColorLight, + AppTheme.primaryColor + ]), + ), + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.add_circle_outline, + color: AppTheme.nearlyWhite, + size: ScreenAdaper.sp(80), + ), + SizedBox( + height: ScreenAdaper.height(10), + ), + Text( + '入库', + style: TextStyle( + decoration: TextDecoration.none, + color: AppTheme.nearlyWhite, + fontSize: ScreenAdaper.sp(60), + letterSpacing: ScreenAdaper.width(5), + fontWeight: FontWeight.w700), + ) + ]), + )), + ), + AnimatedPositioned( + duration: const Duration(milliseconds: 100), + right: 80 * value, + child: GestureDetector( + onTap: () { + Get.back(); + showInventoryInoutCreateDialog(); + }, + child: Container( + height: ScreenAdaper.height(350), + width: ScreenAdaper.height(350), + decoration: const BoxDecoration( + // shape: BoxShape.circle, + borderRadius: + BorderRadius.all(Radius.circular(30)), + gradient: LinearGradient(colors: [ + AppTheme.primaryColorLight, + AppTheme.primaryColor + ]), + ), + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + // 减号、 + Icons.remove_circle_outline, + color: AppTheme.nearlyWhite, + size: ScreenAdaper.sp(80), + ), + SizedBox( + height: ScreenAdaper.height(10), + ), + Text( + '出库', + style: TextStyle( + decoration: TextDecoration.none, + color: AppTheme.nearlyWhite, + fontSize: ScreenAdaper.sp(60), + letterSpacing: + ScreenAdaper.width(5), + fontWeight: FontWeight.w700), + ) + ])), + )), + ], + ); + }, + ))), + ); + } + + /// 打开新建库存出入库对话框 + Future showInventoryInoutCreateDialog() async { + final isTablet = Responsive.isTablet(Get.context!); + isTablet + ? showGeneralDialog( + context: Get.overlayContext!, + barrierLabel: "Barrier", + barrierDismissible: true, + barrierColor: Colors.black.withOpacity(0.5), + transitionDuration: const Duration(milliseconds: 400), + pageBuilder: (_, __, ___) { + return Center( + child: ClipRRect( + borderRadius: BorderRadius.circular(30), + child: Material(child: NewInventoryInout()), + ), + ); + }, + transitionBuilder: (_, anim, __, child) { + Tween tween; + tween = Tween(begin: const Offset(0, -1), end: Offset.zero); + return SlideTransition( + position: tween.animate( + CurvedAnimation(parent: anim, curve: Curves.easeInOut), + ), + child: child, + ); + }, + ) + : showModalBottomSheet( + elevation: 0, + isScrollControlled: true, + backgroundColor: Colors.white, + context: Get.overlayContext!, + builder: (context) { + return NewInventoryInout(); + }, + ); + } getTasks() async { db.getData().then((value) { diff --git a/lib/screens/landing/landing.dart b/lib/screens/landing/landing.dart index 39af9f5..1fee953 100644 --- a/lib/screens/landing/landing.dart +++ b/lib/screens/landing/landing.dart @@ -14,25 +14,21 @@ class LandingPage extends StatelessWidget { @override Widget build(BuildContext context) { return Material( - child: GestureDetector( - onTap: () { - controller.showCreateBtn.value = true; - }, - child: Stack(children: [ - const BackColors(), - SafeArea( - child: Obx(() => Scaffold( - floatingActionButtonLocation: - FloatingActionButtonLocation.centerDocked, - floatingActionButton: controller.currentIndex.value == 0 - ? FloatingCreateButton() - : null, - bottomNavigationBar: BottomNavBar(), - backgroundColor: Colors.transparent, - body: Obx(() => - controller.pages[controller.currentIndex.value]), - ))) - ])), + child: Stack(children: [ + const BackColors(), + SafeArea( + child: Obx(() => Scaffold( + floatingActionButtonLocation: + FloatingActionButtonLocation.centerDocked, + floatingActionButton: controller.currentIndex.value == 0 + ? FloatingCreateButton() + : null, + bottomNavigationBar: BottomNavBar(), + backgroundColor: Colors.transparent, + body: Obx( + () => controller.pages[controller.currentIndex.value]), + ))) + ]), ); } } diff --git a/lib/widgets/floating_action.dart b/lib/widgets/floating_action.dart index 2ea04f7..9513959 100644 --- a/lib/widgets/floating_action.dart +++ b/lib/widgets/floating_action.dart @@ -1,63 +1,21 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:sk_base_mobile/app_theme.dart'; -import 'package:sk_base_mobile/screens/inventory_inout/components/responsive.dart'; import 'package:sk_base_mobile/screens/inventory_inout/inventory_inout_controller.dart'; import 'package:sk_base_mobile/screens/landing/landing_controller.dart'; -import 'package:sk_base_mobile/screens/new_inventory_inout/new_inventory_inout.dart'; +import 'package:sk_base_mobile/util/logger_util.dart'; import 'package:sk_base_mobile/util/screen_adaper_util.dart'; class FloatingCreateButton extends StatelessWidget { FloatingCreateButton({super.key}); final controller = Get.find(); - + final inventoryInoutController = Get.find(); @override Widget build(BuildContext context) { - final isTablet = Responsive.isTablet(context); return Obx(() => controller.showCreateBtn.value ? InkWell( borderRadius: BorderRadius.circular(ScreenAdaper.sp(50)), - onTap: () { - controller.showCreateBtn.value = false; - return; - !isTablet - ? showGeneralDialog( - context: context, - barrierLabel: "Barrier", - barrierDismissible: true, - barrierColor: Colors.black.withOpacity(0.5), - transitionDuration: const Duration(milliseconds: 400), - pageBuilder: (_, __, ___) { - return Center( - child: ClipRRect( - borderRadius: BorderRadius.circular(30), - child: Material(child: NewInventoryInout()), - ), - ); - }, - transitionBuilder: (_, anim, __, child) { - Tween tween; - tween = - Tween(begin: const Offset(0, -1), end: Offset.zero); - return SlideTransition( - position: tween.animate( - CurvedAnimation( - parent: anim, curve: Curves.easeInOut), - ), - child: child, - ); - }, - ) - : showModalBottomSheet( - elevation: 0, - isScrollControlled: true, - backgroundColor: Colors.white, - context: context, - builder: (context) { - return NewInventoryInout(); - }, - ); - }, + onTap: inventoryInoutController.showInOrOutPickerDialog, child: Container( height: ScreenAdaper.height(140), width: ScreenAdaper.height(140), @@ -82,40 +40,45 @@ class FloatingCreateButton extends StatelessWidget { return Stack( alignment: Alignment.center, children: [ - Transform.translate( - offset: Offset(-ScreenAdaper.width(120) * value, - -ScreenAdaper.height(120)), - child: AnimatedContainer( - duration: const Duration(milliseconds: 200), - height: ScreenAdaper.height(200), - width: ScreenAdaper.height(200), - decoration: const BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(30)), - gradient: LinearGradient(colors: [ - AppTheme.primaryColorLight, - AppTheme.primaryColor - ]), - ), - alignment: Alignment.center, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon( - Icons.add_circle_outline, - color: AppTheme.nearlyWhite, - size: ScreenAdaper.sp(70), + GestureDetector( + onTap: () { + print('元素被点击'); + // 在这里添加你的代码 + }, + child: Transform.translate( + offset: Offset(-ScreenAdaper.width(120) * value, + -ScreenAdaper.height(120)), + child: AnimatedContainer( + duration: const Duration(milliseconds: 200), + height: ScreenAdaper.height(200), + width: ScreenAdaper.height(200), + decoration: const BoxDecoration( + borderRadius: + BorderRadius.all(Radius.circular(30)), + gradient: LinearGradient(colors: [ + AppTheme.primaryColorLight, + AppTheme.primaryColor + ]), ), - Text( - '入库', - style: TextStyle( - color: AppTheme.nearlyWhite, - fontSize: ScreenAdaper.sp(50), - letterSpacing: ScreenAdaper.width(5), - fontWeight: FontWeight.w700), - ) - ]), - ), - ), + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.add_circle_outline, + color: AppTheme.nearlyWhite, + size: ScreenAdaper.sp(70), + ), + Text( + '入库', + style: TextStyle( + color: AppTheme.nearlyWhite, + fontSize: ScreenAdaper.sp(50), + letterSpacing: ScreenAdaper.width(5), + fontWeight: FontWeight.w700), + ) + ]), + ))), Transform.translate( offset: Offset(ScreenAdaper.width(120) * value, -ScreenAdaper.height(120)), diff --git a/lib/widgets/gradient_button.dart b/lib/widgets/gradient_button.dart index c9987b5..a1c9e25 100644 --- a/lib/widgets/gradient_button.dart +++ b/lib/widgets/gradient_button.dart @@ -5,10 +5,10 @@ import 'package:sk_base_mobile/constants/constants.dart'; import 'package:sk_base_mobile/util/screen_adaper_util.dart'; class GradientButton extends StatelessWidget { - VoidCallback? onPressed; - bool isLoading; - String buttonText; - GradientButton( + final VoidCallback? onPressed; + final bool isLoading; + final String buttonText; + const GradientButton( {super.key, this.buttonText = TextEnum.createInventoryInOutBtnText, this.onPressed, diff --git a/lib/widgets/tap_to_dismiss_keyboard.dart b/lib/widgets/tap_to_dismiss_keyboard.dart index 5e993ea..fd61fd0 100644 --- a/lib/widgets/tap_to_dismiss_keyboard.dart +++ b/lib/widgets/tap_to_dismiss_keyboard.dart @@ -2,9 +2,8 @@ import 'package:flutter/cupertino.dart'; class TapToDismissKeyboard extends StatelessWidget { final Widget? child; - late BuildContext context; - - TapToDismissKeyboard({this.child, required context}); + final BuildContext context; + const TapToDismissKeyboard({super.key, this.child, required this.context}); @override Widget build(BuildContext context) {