init
This commit is contained in:
10
lib/pages/login/binding.dart
Normal file
10
lib/pages/login/binding.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
class LoginBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => LoginLogic());
|
||||
}
|
||||
}
|
||||
6
lib/pages/login/index.dart
Normal file
6
lib/pages/login/index.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
library login;
|
||||
|
||||
export './logic.dart';
|
||||
export './state.dart';
|
||||
export './view.dart';
|
||||
export './binding.dart';
|
||||
20
lib/pages/login/logic.dart
Normal file
20
lib/pages/login/logic.dart
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
7
lib/pages/login/state.dart
Normal file
7
lib/pages/login/state.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
class LoginState {
|
||||
DateTime? lastPressedAt; //上次点击时间
|
||||
|
||||
LoginState() {
|
||||
///Initialize variables
|
||||
}
|
||||
}
|
||||
27
lib/pages/login/view.dart
Normal file
27
lib/pages/login/view.dart
Normal file
@@ -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<LoginLogic>();
|
||||
final state = Get.find<LoginLogic>().state;
|
||||
|
||||
DateTime? _lastPressedAt;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvoked: (_) {
|
||||
logic.isExit(context);
|
||||
},
|
||||
child: const Scaffold(
|
||||
body: Center(
|
||||
child: Text("login"),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -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<Offset> 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<Offset>(
|
||||
begin: const Offset(0.0, 1.0),
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(
|
||||
parent: animationController,
|
||||
curve: Curves.easeInOut,
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> 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');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<SplashPage> {
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user