login_view.dart 3.8 KB
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,
            ),
          ],
        )
      ],
    );
  }
}