login_view.dart
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import 'package:cp_offline_manage/common/colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'login_logic.dart';
class LoginPage extends GetView<LoginLogic> {
const LoginPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final logic = Get.put(LoginLogic());
return Scaffold(
appBar: AppBar(
title: Text('${(logic.args["type"] as int == 1) ? "总店主登录" : "打票员登录"}'),
centerTitle: true,
backgroundColor: ColorConfig.themeColor),
body: _buildBody());
}
Widget _buildBody() {
final TextEditingController _usernameController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
_usernameController.addListener(() {
controller.updateUsername(_usernameController.text);
});
_passwordController.addListener(() {
controller.updatePassword(_passwordController.text);
});
return Column(
children: [
SizedBox(
height: 80,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: TextField(
controller: _usernameController,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
LengthLimitingTextInputFormatter(11),
],
decoration: InputDecoration(
prefixIcon: Icon(Icons.person),
hintText: "请输入登录手机号码",
border: OutlineInputBorder(),
),
),
),
SizedBox(height: 30),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: TextField(
controller: _passwordController,
obscureText: true,
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock),
hintText: "请输入登录密码",
border: OutlineInputBorder(),
),
),
),
SizedBox(height: 60),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 40,
),
Container(
width: 120,
height: 40,
child: Obx(() => ElevatedButton(
onPressed: controller.canLogin ? () {
controller.enter();
} : null,
child: Text(
"登录",
style: TextStyle(fontSize: 18),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.disabled)) {
return Colors.grey; // 设置按钮不可操作状态的背景颜色
}
return Color(0xFFFF562F); // 设置按钮可操作状态的背景颜色
}),
))),
),
Expanded(child: Container()),
Container(
width: 120,
height: 40,
child: ElevatedButton(
onPressed: () {
controller.enter();
},
child: Text(
"快捷登录",
style: TextStyle(fontSize: 18),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Color(0xFFFF562F))),
),
),
SizedBox(
width: 40,
),
],
)
],
);
}
}