diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 7ed9a37..2c4c8d8 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ LoginLogic()); + } +} diff --git a/lib/pages/login/index.dart b/lib/pages/login/index.dart new file mode 100644 index 0000000..96001b9 --- /dev/null +++ b/lib/pages/login/index.dart @@ -0,0 +1,6 @@ +library login; + +export './logic.dart'; +export './state.dart'; +export './view.dart'; +export './binding.dart'; \ No newline at end of file diff --git a/lib/pages/login/logic.dart b/lib/pages/login/logic.dart new file mode 100644 index 0000000..cfd5793 --- /dev/null +++ b/lib/pages/login/logic.dart @@ -0,0 +1,20 @@ +import 'dart:io'; +import 'package:bot_toast/bot_toast.dart'; +import 'package:get/get.dart'; +import 'state.dart'; + +class LoginLogic extends GetxController { + final LoginState state = LoginState(); + + void isExit(context) { + if (state.lastPressedAt == null || + DateTime.now().difference(state.lastPressedAt!) > + const Duration(seconds: 1)) { + //两次点击间隔超过1秒则重新计时 + state.lastPressedAt = DateTime.now(); + BotToast.showText(text:"再按一次退出程序"); + return; + } + exit(0); + } +} diff --git a/lib/pages/login/state.dart b/lib/pages/login/state.dart new file mode 100644 index 0000000..8c67d4e --- /dev/null +++ b/lib/pages/login/state.dart @@ -0,0 +1,7 @@ +class LoginState { + DateTime? lastPressedAt; //上次点击时间 + + LoginState() { + ///Initialize variables + } +} diff --git a/lib/pages/login/view.dart b/lib/pages/login/view.dart new file mode 100644 index 0000000..2efd7da --- /dev/null +++ b/lib/pages/login/view.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +import 'logic.dart'; + +class LoginPage extends StatelessWidget { + LoginPage({Key? key}) : super(key: key); + + final logic = Get.find(); + final state = Get.find().state; + + DateTime? _lastPressedAt; + + @override + Widget build(BuildContext context) { + return PopScope( + canPop: false, + onPopInvoked: (_) { + logic.isExit(context); + }, + child: const Scaffold( + body: Center( + child: Text("login"), + ), + )); + } +} diff --git a/lib/pages/splash/splash_logic.dart b/lib/pages/splash/splash_logic.dart index d54b4a8..b6c247b 100644 --- a/lib/pages/splash/splash_logic.dart +++ b/lib/pages/splash/splash_logic.dart @@ -1,24 +1,64 @@ +import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:tdesign_flutter/tdesign_flutter.dart'; import 'splash_state.dart'; -class SplashLogic extends GetxController { +import '../../utils/utils.dart'; + +class SplashLogic extends GetxController with GetTickerProviderStateMixin { final SplashState state = SplashState(); + late AnimationController animationController; + late Animation animation; + + @override + void onInit() { + super.onInit(); + + initAnimation(); + + animationController.forward(); + + isLoginFn(); + } + @override void onReady() { - // TODO: implement onReady + debugPrint('onReady'); super.onReady(); } @override void onClose() { - // TODO: implement onClose + animationController.dispose(); super.onClose(); } - void showText(context) { - TDToast.showText('轻提示文字内容', context: context); + void initAnimation() { + animationController = AnimationController( + vsync: this, + duration: const Duration(seconds: 1), + ); + + animation = Tween( + begin: const Offset(0.0, 1.0), + end: Offset.zero, + ).animate(CurvedAnimation( + parent: animationController, + curve: Curves.easeInOut, + )); + } + + Future isLoginFn() async { + // 倒计时3秒 + await Future.delayed(const Duration(seconds: 3), () { + final token = StorageUtil().getString("token"); + if (!ToolFn.isBlank(token)) { + Get.offAllNamed('/home'); + } else { + Get.offAllNamed('/login'); + // Get.toNamed('/login'); + } + }); } } diff --git a/lib/pages/splash/splash_view.dart b/lib/pages/splash/splash_view.dart index c684845..fae7c65 100644 --- a/lib/pages/splash/splash_view.dart +++ b/lib/pages/splash/splash_view.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:tdesign_flutter/tdesign_flutter.dart'; import 'splash_logic.dart'; class SplashPage extends StatefulWidget { @@ -18,19 +17,30 @@ class _SplashPageState extends State { Widget build(BuildContext context) { return Scaffold( body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text("Splash"), - TDButton( - theme: TDButtonTheme.primary, - text: "立即登录", - onTap: () { - logic.showText(context); - }, - ), - ], - ), + child: SlideTransition( + position: logic.animation, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(10), + child: Image.asset( + "assets/images/logo.png", + width: 120, + ), + ), + const Padding( + padding: EdgeInsets.only(top: 10), + ), + const Text( + "捷兑通-商家版", + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + ), + ), + ], + )), ), ); } diff --git a/lib/router/app_pages.dart b/lib/router/app_pages.dart index 9661540..1cff134 100644 --- a/lib/router/app_pages.dart +++ b/lib/router/app_pages.dart @@ -1,5 +1,6 @@ import 'package:get/get.dart'; import '../pages/splash/index.dart'; +import '../pages/login/index.dart'; class AppPages { static const String initial = '/'; @@ -11,7 +12,8 @@ class AppPages { name: AppPages.initial, page: () => const SplashPage(), binding: SplashBinding()), - // GetPage(name: AppPages.login, page: () => LoginPage()), + GetPage( + name: AppPages.login, page: () => LoginPage(), binding: LoginBinding()), // GetPage(name: AppPages.home, page: () => HomePage()), ]; } diff --git a/lib/utils/tool.dart b/lib/utils/tool.dart new file mode 100644 index 0000000..a07b8b3 --- /dev/null +++ b/lib/utils/tool.dart @@ -0,0 +1,9 @@ +class ToolFn { + // 字符串是否为空 + static bool isBlank(String? str) { + if (str == null || str.isEmpty) { + return true; + } + return false; + } +} diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index e8eb31a..59d82e5 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -2,4 +2,5 @@ library utils; export 'logger.dart'; export 'status_bar.dart'; -export 'storage.dart'; \ No newline at end of file +export 'storage.dart'; +export 'tool.dart'; \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index bf4fc5e..176c045 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -25,6 +25,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" + bot_toast: + dependency: "direct main" + description: + name: bot_toast + sha256: "6b93030a99a98335b8827ecd83021e92e885ffc61d261d3825ffdecdd17f3bdf" + url: "https://pub.flutter-io.cn" + source: hosted + version: "4.1.3" characters: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 96943b8..21c57b6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,6 +7,7 @@ environment: sdk: '>=3.2.3 <4.0.0' dependencies: + bot_toast: ^4.1.3 device_info_plus: ^9.1.1 dio: ^5.4.0 easy_refresh: ^3.3.3+1 @@ -27,3 +28,5 @@ dev_dependencies: flutter: uses-material-design: true + assets: + - assets/images/logo.png \ No newline at end of file