home_view.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: LoginScreen(onLogin: (username,password) {
  23. controller.fetchSysConfig();
  24. // 在这里处理登录逻辑,例如调用API
  25. print('Username: $username');
  26. print('Password: $password');
  27. })
  28. ),
  29. );
  30. }
  31. }
  32. class LoginScreen extends StatefulWidget {
  33. final Function(String username, String password) onLogin;
  34. LoginScreen({required this.onLogin});
  35. @override
  36. _LoginScreenState createState() => _LoginScreenState();
  37. }
  38. class _LoginScreenState extends State<LoginScreen> {
  39. final _usernameController = TextEditingController();
  40. final _passwordController = TextEditingController();
  41. @override
  42. Widget build(BuildContext context) {
  43. return Padding(
  44. padding: const EdgeInsets.only(bottom: 30),
  45. child: Center(
  46. child: Padding(
  47. padding: const EdgeInsets.fromLTRB(55, 0, 55, 0),
  48. child: Column(
  49. mainAxisAlignment: MainAxisAlignment.center,
  50. children: [
  51. TextField(
  52. controller: _usernameController,
  53. decoration: const InputDecoration(
  54. labelText: '用户名',
  55. hintText: '请输入用户名',
  56. border: InputBorder.none,
  57. ),
  58. ),
  59. const SizedBox(height: 16),
  60. TextField(
  61. controller: _passwordController,
  62. decoration: const InputDecoration(
  63. labelText: '密码',
  64. hintText: '输入密码',
  65. border: InputBorder.none,
  66. ),
  67. obscureText: true,
  68. ),
  69. const SizedBox(height: 20),
  70. SizedBox(
  71. width: 200,
  72. height: 40,
  73. child: ElevatedButton(
  74. onPressed: () {
  75. final username = _usernameController.text;
  76. final password = _passwordController.text;
  77. widget.onLogin(username, password);
  78. },
  79. child: const Text('登录'),
  80. ),
  81. ),
  82. ],
  83. ),
  84. ),
  85. ),
  86. );
  87. }
  88. @override
  89. void dispose() {
  90. _usernameController.dispose();
  91. _passwordController.dispose();
  92. super.dispose();
  93. }
  94. }