home_view.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import 'dart:io';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:naiyouwl/app/component/sys_app_bar.dart';
  6. import 'package:window_manager/window_manager.dart';
  7. import '../controllers/home_controller.dart';
  8. class HomeView extends GetView<HomeController> {
  9. const HomeView({Key? key}) : super(key: key);
  10. @override
  11. Widget build(BuildContext context) {
  12. return Container(
  13. decoration: const BoxDecoration(
  14. image: DecorationImage(
  15. image: AssetImage("images/login/login.png"),
  16. fit: BoxFit.fill,
  17. ),
  18. ),
  19. child: Scaffold(
  20. backgroundColor: Colors.transparent,
  21. appBar: const SysAppBar(title: Text("登录"),),
  22. body: Obx(() {
  23. return LoginScreen(isLoading: controller.isLoading.value,
  24. onLogin: (username, password) {
  25. controller.fetchSysConfig();
  26. // 在这里处理登录逻辑,例如调用API
  27. print('Username: $username');
  28. print('Password: $password');
  29. });
  30. })
  31. ),
  32. );
  33. }
  34. }
  35. class LoginScreen extends StatefulWidget {
  36. final Function(String username, String password) onLogin;
  37. final bool isLoading;
  38. LoginScreen({required this.isLoading, required this.onLogin});
  39. @override
  40. _LoginScreenState createState() => _LoginScreenState();
  41. }
  42. class _LoginScreenState extends State<LoginScreen> {
  43. final _usernameController = TextEditingController();
  44. final _passwordController = TextEditingController();
  45. @override
  46. Widget build(BuildContext context) {
  47. return Padding(
  48. padding: const EdgeInsets.only(bottom: 30),
  49. child: Center(
  50. child: Padding(
  51. padding: const EdgeInsets.fromLTRB(55, 0, 55, 0),
  52. child: Column(
  53. mainAxisAlignment: MainAxisAlignment.center,
  54. children: [
  55. TextField(
  56. controller: _usernameController,
  57. decoration: const InputDecoration(
  58. labelText: '用户名',
  59. hintText: '请输入用户名',
  60. border: InputBorder.none,
  61. ),
  62. ),
  63. const SizedBox(height: 16),
  64. TextField(
  65. controller: _passwordController,
  66. decoration: const InputDecoration(
  67. labelText: '密码',
  68. hintText: '输入密码',
  69. border: InputBorder.none,
  70. ),
  71. obscureText: true,
  72. ),
  73. const SizedBox(height: 20),
  74. SizedBox(
  75. width: 200,
  76. height: 40,
  77. child: ElevatedButton(
  78. onPressed: () {
  79. if (!widget.isLoading) {
  80. final username = _usernameController.text;
  81. final password = _passwordController.text;
  82. widget.onLogin(username, password);
  83. }
  84. },
  85. child: widget.isLoading ? const CircularProgressIndicator(
  86. color: Colors.white,
  87. ) : const Text('登录'),
  88. ),
  89. ),
  90. ],
  91. ),
  92. ),
  93. ),
  94. );
  95. }
  96. @override
  97. void dispose() {
  98. _usernameController.dispose();
  99. _passwordController.dispose();
  100. super.dispose();
  101. }
  102. }